-
Notifications
You must be signed in to change notification settings - Fork 342
/
selectors.js
133 lines (110 loc) · 3.4 KB
/
selectors.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { createSelector } from 'reselect'
import { SPECIAL_LIST_NAMES } from '@worldbrain/memex-common/lib/storage/modules/lists/constants'
import * as selectors from '../search-filters/selectors'
export const customLists = (state) => state.customLists
export const inboxUnreadCount = createSelector(
customLists,
(state) => state.inboxUnreadCount,
)
export const allLists = createSelector(customLists, (state) => state.lists)
export const activeListIndex = createSelector(
customLists,
(state) => state.activeListIndex,
)
export const getSortedLists = createSelector(allLists, (lists) => {
const mobileListIndex = lists.findIndex(
({ name }) => name === SPECIAL_LIST_NAMES.MOBILE,
)
if (mobileListIndex === -1) {
return [{ name: SPECIAL_LIST_NAMES.MOBILE, id: -1 }, ...lists]
}
return lists
})
const isSpecialList = (list) =>
[SPECIAL_LIST_NAMES.INBOX, SPECIAL_LIST_NAMES.MOBILE].includes(list.name)
export const createdLists = createSelector(getSortedLists, (lists) =>
lists.filter((list) => !isSpecialList(list)),
)
export const specialLists = createSelector(getSortedLists, (lists) =>
lists.filter((list) => isSpecialList(list)),
)
export const getUrlsToEdit = createSelector(
customLists,
(state) => state.urlsToEdit,
)
export const createdDisplayLists = createSelector(
createdLists,
activeListIndex,
selectors.listIdFilter,
(lists, listIndex, listFilter) =>
lists.map((pageDoc, i) => ({
...pageDoc,
isEditing: i === listIndex,
isFilterIndex: Number(listFilter) === pageDoc.id,
isMobileList: false,
})),
)
export const specialDisplayLists = createSelector(
specialLists,
selectors.listIdFilter,
(lists, listFilter) =>
lists.map((pageDoc) => ({
...pageDoc,
isFilterIndex: Number(listFilter) === pageDoc.id,
isMobileList: pageDoc.name === SPECIAL_LIST_NAMES.MOBILE,
})),
)
export const deleteConfirmProps = createSelector(
customLists,
(state) => state.deleteConfirmProps,
)
export const isDeleteConfShown = createSelector(
deleteConfirmProps,
(state) => state.isShown,
)
export const shareModalProps = createSelector(
customLists,
(state) => state.shareModalProps,
)
export const deletingIndex = createSelector(
deleteConfirmProps,
(state) => state.deleting,
)
export const deletingID = createSelector(
deleteConfirmProps,
(state) => state.id,
)
export const listEditDropdown = createSelector(
customLists,
(state) => state.listEditDropdown,
)
export const showAddToList = createSelector(
customLists,
(state) => state.showAddToList,
)
export const urlDragged = createSelector(
customLists,
(state) => state.urlDragged,
)
export const showCreateListForm = createSelector(
customLists,
(state) => state.showCreateListForm,
)
export const showCommonNameWarning = createSelector(
customLists,
(state) => state.showCommonNameWarning,
)
export const showCrowdFundingModal = createSelector(
customLists,
(state) => state.showCrowdFundingModal,
)
export const activeCollectionName = createSelector(
selectors.listIdFilter,
allLists,
(listFilterId, lists) =>
listFilterId
? lists
.filter((list) => list.id === Number(listFilterId))
.map((list) => list.name)[0]
: undefined,
)