-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathusers.js
More file actions
49 lines (44 loc) · 1.48 KB
/
users.js
File metadata and controls
49 lines (44 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { createSelector } from '@reduxjs/toolkit';
import { getConfig } from '../../../utils/getConfig';
import { parseNumber } from '../../../utils/parseStringToType';
export const getAuthenticated = (state) => state.user.authenticated;
const getTotalSize = (state) => state.user.totalSize;
const getAssetsTotalSize = (state) => state.assets.totalSize;
export const getSketchOwner = (state) => state.project.owner;
const getUserId = (state) => state.user.id;
const limit = parseNumber(getConfig('UPLOAD_LIMIT')) || 250000000;
export const getCanUploadMedia = createSelector(
getAuthenticated,
getTotalSize,
(authenticated, totalSize) => {
const currentSize = totalSize || 0;
if (!authenticated) return false;
// eventually do the same thing for verified when
// email verification actually works
if (currentSize >= limit) return false;
return true;
}
);
export const getreachedTotalSizeLimit = createSelector(
getTotalSize,
getAssetsTotalSize,
(totalSize, assetsTotalSize) => {
const currentSize = totalSize || assetsTotalSize || 0;
if (currentSize >= limit) return true;
// if (totalSize > 1000) return true;
return false;
}
);
export const getIsUserOwner = createSelector(
getSketchOwner,
getUserId,
(sketchOwner, userId) => {
if (!sketchOwner) return false;
return sketchOwner.id === userId;
}
);
export const selectCanEditSketch = createSelector(
getSketchOwner,
getIsUserOwner,
(sketchOwner, isOwner) => !sketchOwner || isOwner
);