-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathusers.js
47 lines (42 loc) · 1.37 KB
/
users.js
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
import { createSelector } from '@reduxjs/toolkit';
import getConfig from '../../../utils/getConfig';
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 = getConfig('UPLOAD_LIMIT') || 250000000;
export const getCanUploadMedia = createSelector(
getAuthenticated,
getTotalSize,
(authenticated, totalSize) => {
if (!authenticated) return false;
// eventually do the same thing for verified when
// email verification actually works
if (totalSize > limit) return false;
return true;
}
);
export const getreachedTotalSizeLimit = createSelector(
getTotalSize,
getAssetsTotalSize,
(totalSize, assetsTotalSize) => {
const currentSize = totalSize || assetsTotalSize;
if (currentSize && 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
);