forked from WorldBrain/Memex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectors.js
105 lines (88 loc) · 2.64 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
import { createSelector } from 'reselect'
// import { selectors } from '../search-filters'
// TODO: check why not working the other way around.
import * as selectors from '../search-filters/selectors'
// import { selectors as filters } from '../overview/filters'
// TODO: Needs some work.
const sortAlphabetically = (a, b) => {
if (a.name.toLowerCase() < b.name.toLowerCase()) {
return -1
}
if (a.name.toLowerCase() > b.name.toLowerCase()) {
return 1
}
return 0
}
export const customLists = state => state.customLists
export const allLists = createSelector(customLists, state => state.lists)
export const activeListIndex = createSelector(
customLists,
state => state.activeListIndex,
)
export const listFilterIndex = createSelector(
customLists,
state => state.listFilterIndex,
)
export const getSortedLists = createSelector(allLists, lists => {
return lists.sort(sortAlphabetically)
})
export const getUrlsToEdit = createSelector(
customLists,
state => state.urlsToEdit,
)
export const results = createSelector(
getSortedLists,
activeListIndex,
selectors.listFilter,
(lists, listIndex, listFilter) => {
return lists.map((pageDoc, i) => ({
...pageDoc,
isEditing: i === listIndex,
isFilterIndex: Number(listFilter) === pageDoc.id,
}))
},
)
export const deleteConfirmProps = createSelector(
customLists,
state => state.deleteConfirmProps,
)
export const isDeleteConfShown = createSelector(
deleteConfirmProps,
state => state.isShown,
)
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.listFilter,
allLists,
(listFilterId, lists) =>
listFilterId
? lists
.filter(list => list.id === Number(listFilterId))
.map(list => list.name)[0]
: undefined,
)