forked from WorldBrain/Memex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectors.ts
74 lines (71 loc) · 2.21 KB
/
selectors.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { State } from './reducer'
import { createSelector } from 'reselect'
import { NOTIFICATIONS_PAGE_SIZE } from './constants'
const notifications = (state: any): State => state.notifications
export const notificationsList = createSelector(
notifications,
state => state.notificationsList,
)
export const readNotificationList = createSelector(notificationsList, notifs =>
notifs.filter(notif => notif.isRead === true),
)
export const unreadNotificationList = createSelector(
notificationsList,
notifs => notifs.filter(notif => !notif.isRead),
)
export const showMoreIndex = createSelector(
notifications,
state => state.showMoreIndex,
)
export const currentPage = createSelector(
notifications,
state => state.currentPage,
)
export const notificationsSkip = createSelector(
currentPage,
page => page * NOTIFICATIONS_PAGE_SIZE,
)
export const isLoading = createSelector(notifications, state => state.isLoading)
export const resultsExhausted = createSelector(
notifications,
state => state.resultExhausted,
)
export const needsWaypoint = createSelector(
resultsExhausted,
isLoading,
(isExhausted, loading) => !loading && !isExhausted,
)
export const isReadExpanded = createSelector(
notifications,
state => state.isReadExpanded,
)
export const isReadShow = createSelector(
readNotificationList,
isReadExpanded,
(notifs, readExpand) => readExpand && notifs.length !== 0,
)
export const showInbox = createSelector(notifications, state => state.showInbox)
export const initUnreadNotifCount = createSelector(
notifications,
state => state.unreadNotifCount,
)
export const unreadNotifCount = createSelector(
notificationsList,
unreadNotificationList,
initUnreadNotifCount,
(totalNotifs, notifs, countUnread) =>
totalNotifs.length || notifs.length ? notifs.length : countUnread,
)
export const localStorageNotif = createSelector(
notifications,
state => state.localStorageNotif,
)
export const showUnreadCount = createSelector(
unreadNotifCount,
count => count !== 0,
)
export const isLoadingBar = createSelector(
notificationsList,
unreadNotificationList,
(totalNotifs, notifs) => !(totalNotifs.length || notifs.length),
)