@synerise/ds-item-picker 1.17.0 → 1.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/ItemPicker.d.ts +5 -5
- package/dist/ItemPicker.js +13 -17
- package/dist/ItemPicker.styles.d.ts +1 -1
- package/dist/ItemPicker.styles.js +6 -3
- package/dist/components/ItemPickerDropdown/ItemPickerDropdown.d.ts +2 -2
- package/dist/components/ItemPickerDropdown/ItemPickerDropdown.js +58 -99
- package/dist/components/ItemPickerDropdown/ItemPickerDropdown.style.d.ts +7 -7
- package/dist/components/ItemPickerDropdown/ItemPickerDropdown.style.js +22 -19
- package/dist/components/ItemPickerDropdown/ItemPickerDropdown.types.d.ts +4 -4
- package/dist/components/ItemPickerDropdown/ItemPickerDropdown.types.js +1 -1
- package/dist/components/ItemPickerLegacy/ItemPickerLegacy.d.ts +2 -2
- package/dist/components/ItemPickerLegacy/ItemPickerLegacy.js +89 -152
- package/dist/components/ItemPickerLegacy/ItemPickerLegacy.types.d.ts +8 -8
- package/dist/components/ItemPickerLegacy/ItemPickerLegacy.types.js +1 -1
- package/dist/components/ItemPickerList/ItemPickerList.d.ts +4 -4
- package/dist/components/ItemPickerList/ItemPickerList.js +199 -267
- package/dist/components/ItemPickerList/ItemPickerList.styles.d.ts +18 -18
- package/dist/components/ItemPickerList/ItemPickerList.styles.js +55 -64
- package/dist/components/ItemPickerList/ItemPickerList.types.d.ts +3 -3
- package/dist/components/ItemPickerList/ItemPickerList.types.js +1 -1
- package/dist/components/ItemPickerList/components/EmptyListMessage.d.ts +3 -3
- package/dist/components/ItemPickerList/components/EmptyListMessage.js +27 -40
- package/dist/components/ItemPickerList/components/ErrorItem.d.ts +1 -1
- package/dist/components/ItemPickerList/components/ErrorItem.js +10 -9
- package/dist/components/ItemPickerList/components/ErrorMessage.d.ts +2 -2
- package/dist/components/ItemPickerList/components/ErrorMessage.js +12 -15
- package/dist/components/ItemPickerList/components/InfiniteLoaderItem.d.ts +2 -2
- package/dist/components/ItemPickerList/components/InfiniteLoaderItem.js +19 -17
- package/dist/components/ItemPickerList/components/ItemPickerListFooter.d.ts +3 -3
- package/dist/components/ItemPickerList/components/ItemPickerListFooter.js +21 -20
- package/dist/components/ItemPickerList/components/ItemPickerListRow.d.ts +4 -4
- package/dist/components/ItemPickerList/components/ItemPickerListRow.js +42 -43
- package/dist/components/ItemPickerList/components/ItemPickerListSkeleton.d.ts +1 -1
- package/dist/components/ItemPickerList/components/ItemPickerListSkeleton.js +16 -23
- package/dist/components/ItemPickerList/components/ListSearchInput.d.ts +4 -4
- package/dist/components/ItemPickerList/components/ListSearchInput.js +36 -51
- package/dist/components/ItemPickerList/components/LoadingItem.d.ts +1 -1
- package/dist/components/ItemPickerList/components/LoadingItem.js +10 -9
- package/dist/components/ItemPickerList/components/NoMoreItem.d.ts +1 -1
- package/dist/components/ItemPickerList/components/NoMoreItem.js +10 -9
- package/dist/components/ItemPickerList/components/index.js +14 -6
- package/dist/components/ItemPickerList/constants.d.ts +2 -2
- package/dist/components/ItemPickerList/constants.js +47 -26
- package/dist/components/ItemPickerList/hooks/index.js +8 -3
- package/dist/components/ItemPickerList/hooks/useFlattenFolders.d.ts +2 -2
- package/dist/components/ItemPickerList/hooks/useFlattenFolders.js +40 -61
- package/dist/components/ItemPickerList/hooks/useItemsInSections.d.ts +7 -7
- package/dist/components/ItemPickerList/hooks/useItemsInSections.js +342 -443
- package/dist/components/ItemPickerList/hooks/useItemsInSections.utils.d.ts +5 -5
- package/dist/components/ItemPickerList/hooks/useItemsInSections.utils.js +77 -74
- package/dist/components/ItemPickerList/hooks/useListHeight.d.ts +2 -2
- package/dist/components/ItemPickerList/hooks/useListHeight.js +37 -41
- package/dist/components/ItemPickerList/types/renderMode.js +8 -5
- package/dist/components/ItemPickerList/utils/actionItemsUtils.d.ts +4 -4
- package/dist/components/ItemPickerList/utils/actionItemsUtils.js +92 -92
- package/dist/components/ItemPickerList/utils/createTitleFromTitlePath.d.ts +2 -2
- package/dist/components/ItemPickerList/utils/createTitleFromTitlePath.js +7 -4
- package/dist/components/ItemPickerList/utils/findSectionById.d.ts +1 -1
- package/dist/components/ItemPickerList/utils/findSectionById.js +10 -12
- package/dist/components/ItemPickerList/utils/getContextAwareActions.d.ts +1 -1
- package/dist/components/ItemPickerList/utils/getContextAwareActions.js +19 -15
- package/dist/components/ItemPickerList/utils/getSearchByActionItems.d.ts +2 -2
- package/dist/components/ItemPickerList/utils/getSearchByActionItems.js +28 -29
- package/dist/components/ItemPickerList/utils/index.js +16 -4
- package/dist/components/ItemPickerList/utils/isNavKey.d.ts +1 -1
- package/dist/components/ItemPickerList/utils/isNavKey.js +6 -3
- package/dist/components/ItemPickerList/utils/resolveSectionId.d.ts +2 -2
- package/dist/components/ItemPickerList/utils/resolveSectionId.js +15 -9
- package/dist/components/ItemPickerList/utils/typeguards.utils.d.ts +5 -5
- package/dist/components/ItemPickerList/utils/typeguards.utils.js +23 -14
- package/dist/components/ItemPickerNew/ItemPickerNew.d.ts +4 -4
- package/dist/components/ItemPickerNew/ItemPickerNew.js +55 -100
- package/dist/components/ItemPickerNew/ItemPickerNew.types.d.ts +13 -13
- package/dist/components/ItemPickerNew/ItemPickerNew.types.js +1 -1
- package/dist/components/ItemPickerNew/types/actions.types.d.ts +2 -2
- package/dist/components/ItemPickerNew/types/actions.types.js +10 -6
- package/dist/components/ItemPickerNew/types/baseItemSectionType.types.d.ts +3 -3
- package/dist/components/ItemPickerNew/types/baseItemSectionType.types.js +1 -1
- package/dist/components/ItemPickerNew/types/itemPickerListTexts.types.d.ts +1 -1
- package/dist/components/ItemPickerNew/types/itemPickerListTexts.types.js +1 -1
- package/dist/components/ItemPickerTrigger/Trigger.d.ts +5 -5
- package/dist/components/ItemPickerTrigger/Trigger.js +71 -111
- package/dist/components/ItemPickerTrigger/Trigger.styles.d.ts +12 -12
- package/dist/components/ItemPickerTrigger/Trigger.styles.js +70 -93
- package/dist/components/ItemPickerTrigger/Trigger.types.d.ts +3 -3
- package/dist/components/ItemPickerTrigger/Trigger.types.js +1 -1
- package/dist/hooks/useDefaultTexts.d.ts +1 -1
- package/dist/hooks/useDefaultTexts.js +116 -121
- package/dist/index.js +14 -6
- package/dist/modules.d.js +1 -1
- package/dist/modules.d.ts +0 -0
- package/package.json +25 -25
|
@@ -1,226 +1,184 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { getFolderItems, getItems, getRecentItems, matchesSearchQuery } from './useItemsInSections.utils';
|
|
15
|
-
var getSectionHeight = function getSectionHeight(itemsCount, withTitle) {
|
|
16
|
-
var itemsHeight = itemsCount * ITEM_SIZE[itemSizes.DEFAULT];
|
|
17
|
-
var titleHeight = withTitle && itemsCount ? ITEM_SIZE.title : 0;
|
|
1
|
+
import { useState, useRef, useMemo, useCallback, useEffect } from "react";
|
|
2
|
+
import { itemSizes } from "@synerise/ds-list-item";
|
|
3
|
+
import { FIRST_PAGE, ITEMS_PER_SECTION_IN_SEARCH, ITEMS_PER_SECTION, ITEM_SIZE, SECTION_HEADER_HEIGHT, GET_ITEM_KEY, ITEMS_PER_PAGE, SECOND_PAGE } from "../constants.js";
|
|
4
|
+
import { RENDER_MODES } from "../types/renderMode.js";
|
|
5
|
+
import { isItems, isItemsConfig, isWithOutSections } from "../utils/typeguards.utils.js";
|
|
6
|
+
import { getActionItems, getSectionActionItems } from "../utils/actionItemsUtils.js";
|
|
7
|
+
import { getSearchByActionItems } from "../utils/getSearchByActionItems.js";
|
|
8
|
+
import { resolveSectionId } from "../utils/resolveSectionId.js";
|
|
9
|
+
import { useFlattenFolders } from "./useFlattenFolders.js";
|
|
10
|
+
import { matchesSearchQuery, getRecentItems, getFolderItems, getItems } from "./useItemsInSections.utils.js";
|
|
11
|
+
const getSectionHeight = (itemsCount, withTitle) => {
|
|
12
|
+
const itemsHeight = itemsCount * ITEM_SIZE[itemSizes.DEFAULT];
|
|
13
|
+
const titleHeight = withTitle && itemsCount ? ITEM_SIZE.title : 0;
|
|
18
14
|
return itemsHeight + titleHeight;
|
|
19
15
|
};
|
|
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
|
-
setContentHeight = _useState7[1];
|
|
70
|
-
var _useState8 = useState(isFixedItemsList),
|
|
71
|
-
isInitialDataLoaded = _useState8[0],
|
|
72
|
-
setIsInitialDataLoaded = _useState8[1];
|
|
73
|
-
var _useState9 = useState(false),
|
|
74
|
-
isLoading = _useState9[0],
|
|
75
|
-
setIsLoading = _useState9[1];
|
|
76
|
-
var _useState0 = useState(false),
|
|
77
|
-
isLoadingError = _useState0[0],
|
|
78
|
-
setIsLoadingError = _useState0[1];
|
|
79
|
-
var _useState1 = useState(false),
|
|
80
|
-
isLoadingMoreError = _useState1[0],
|
|
81
|
-
setIsLoadingMoreError = _useState1[1];
|
|
82
|
-
var _useState10 = useState(false),
|
|
83
|
-
isLoadingMore = _useState10[0],
|
|
84
|
-
setIsLoadingMore = _useState10[1];
|
|
85
|
-
var _useState11 = useState(false),
|
|
86
|
-
isLoadedAll = _useState11[0],
|
|
87
|
-
setIsLoadedAll = _useState11[1];
|
|
88
|
-
var _useState12 = useState(),
|
|
89
|
-
refreshTrigger = _useState12[0],
|
|
90
|
-
setRefreshTrigger = _useState12[1];
|
|
91
|
-
var _useState13 = useState(function () {
|
|
92
|
-
if (isFixedItemsList) {
|
|
93
|
-
var fixedItems = isItemsConfig(items) ? items.items : items;
|
|
94
|
-
if (searchQuery) {
|
|
95
|
-
return fixedItems.filter(function (item) {
|
|
96
|
-
return item.text && matchesSearchQuery(item.text, searchQuery);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return fixedItems;
|
|
16
|
+
const useItemsInSections = ({
|
|
17
|
+
items,
|
|
18
|
+
texts,
|
|
19
|
+
selectedItem,
|
|
20
|
+
sections,
|
|
21
|
+
recents,
|
|
22
|
+
actions,
|
|
23
|
+
searchQuery,
|
|
24
|
+
handleItemSelect,
|
|
25
|
+
onSectionChange,
|
|
26
|
+
getItemKey = GET_ITEM_KEY,
|
|
27
|
+
showItemsSectionLabel,
|
|
28
|
+
changeSearchQuery,
|
|
29
|
+
onLoadedData
|
|
30
|
+
}) => {
|
|
31
|
+
const [currentSection, setCurrentSection] = useState();
|
|
32
|
+
const [previousSection, setPreviousSection] = useState();
|
|
33
|
+
const [searchByAction, setSearchByAction] = useState();
|
|
34
|
+
const [searchByParamConfig, setSearchByParamConfig] = useState();
|
|
35
|
+
const [searchInAction, setSearchInAction] = useState();
|
|
36
|
+
const [searchInItem, setSearchInItem] = useState();
|
|
37
|
+
const {
|
|
38
|
+
currentSectionHasFolders,
|
|
39
|
+
currentFolders,
|
|
40
|
+
parentFolder,
|
|
41
|
+
currentPath
|
|
42
|
+
} = useFlattenFolders({
|
|
43
|
+
currentSection,
|
|
44
|
+
sections
|
|
45
|
+
});
|
|
46
|
+
const requestIdRef = useRef();
|
|
47
|
+
const pageToLoad = useRef(FIRST_PAGE);
|
|
48
|
+
const metaRef = useRef({});
|
|
49
|
+
const sectionTotals = useRef({});
|
|
50
|
+
const abortControllerRef = useRef();
|
|
51
|
+
const isFixedItemsList = isItems(items) || isItemsConfig(items);
|
|
52
|
+
const [contentHeight, setContentHeight] = useState();
|
|
53
|
+
const [isInitialDataLoaded, setIsInitialDataLoaded] = useState(isFixedItemsList);
|
|
54
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
55
|
+
const [isLoadingError, setIsLoadingError] = useState(false);
|
|
56
|
+
const [isLoadingMoreError, setIsLoadingMoreError] = useState(false);
|
|
57
|
+
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
58
|
+
const [isLoadedAll, setIsLoadedAll] = useState(false);
|
|
59
|
+
const [refreshTrigger, setRefreshTrigger] = useState();
|
|
60
|
+
const [currentItems, setCurrentItems] = useState(() => {
|
|
61
|
+
if (isFixedItemsList) {
|
|
62
|
+
const fixedItems = isItemsConfig(items) ? items.items : items;
|
|
63
|
+
if (searchQuery) {
|
|
64
|
+
return fixedItems.filter((item) => item.text && matchesSearchQuery(item.text, searchQuery));
|
|
100
65
|
}
|
|
101
|
-
return
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return (_section$folders = section.folders) == null ? void 0 : _section$folders.length;
|
|
123
|
-
}));
|
|
124
|
-
}, [hasSections, sections]);
|
|
125
|
-
var handleItemSelectExtended = useCallback(function (item) {
|
|
66
|
+
return fixedItems;
|
|
67
|
+
}
|
|
68
|
+
return [];
|
|
69
|
+
});
|
|
70
|
+
const isSearchInActionActive = !!searchInAction && !searchInItem;
|
|
71
|
+
const canPerformListActions = actions !== void 0 && !searchByAction && !searchByParamConfig && !isSearchInActionActive;
|
|
72
|
+
const listActions = searchQuery === "/" && canPerformListActions;
|
|
73
|
+
const hasSearchQuery = !!searchQuery;
|
|
74
|
+
const {
|
|
75
|
+
activeSectionId,
|
|
76
|
+
isListItemsRenderingMode
|
|
77
|
+
} = resolveSectionId({
|
|
78
|
+
currentSection,
|
|
79
|
+
searchInAction,
|
|
80
|
+
searchInItem
|
|
81
|
+
});
|
|
82
|
+
const activeSectionIdWithFallback = activeSectionId || "DEFAULT";
|
|
83
|
+
const hasCurrentSection = !!activeSectionId;
|
|
84
|
+
const hasSections = !isWithOutSections(sections);
|
|
85
|
+
const hasSectionsAndFolders = useMemo(() => hasSections && sections?.some((section) => section.folders?.length), [hasSections, sections]);
|
|
86
|
+
const handleItemSelectExtended = useCallback((item) => {
|
|
126
87
|
if (searchInAction && !searchInItem) {
|
|
127
|
-
changeSearchQuery(
|
|
88
|
+
changeSearchQuery("");
|
|
128
89
|
setSearchInItem(item);
|
|
129
|
-
setSearchByParamConfig(
|
|
130
|
-
searchInAction.onSearchInItemClick
|
|
90
|
+
setSearchByParamConfig(void 0);
|
|
91
|
+
searchInAction.onSearchInItemClick?.(item);
|
|
131
92
|
return;
|
|
132
93
|
}
|
|
133
|
-
handleItemSelect
|
|
94
|
+
handleItemSelect?.(item);
|
|
134
95
|
}, [changeSearchQuery, handleItemSelect, searchInAction, searchInItem]);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
var fallbackLimit = searchQuery ? ITEMS_PER_SECTION_IN_SEARCH : ITEMS_PER_SECTION;
|
|
96
|
+
const itemsLimitPerSection = useMemo(() => {
|
|
97
|
+
const fallbackLimit = searchQuery ? ITEMS_PER_SECTION_IN_SEARCH : ITEMS_PER_SECTION;
|
|
138
98
|
if (isFixedItemsList) {
|
|
139
|
-
|
|
140
|
-
return isItemsConfig(items) ? (_items$limitPerSectio = items.limitPerSection) != null ? _items$limitPerSectio : fallbackLimit : fallbackLimit;
|
|
99
|
+
return isItemsConfig(items) ? items.limitPerSection ?? fallbackLimit : fallbackLimit;
|
|
141
100
|
}
|
|
142
|
-
return
|
|
101
|
+
return items.limitPerSection ?? fallbackLimit;
|
|
143
102
|
}, [isFixedItemsList, searchQuery, items]);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
};
|
|
156
|
-
}
|
|
103
|
+
const {
|
|
104
|
+
listRenderingMode
|
|
105
|
+
} = useMemo(() => {
|
|
106
|
+
if (isListItemsRenderingMode) {
|
|
107
|
+
return {
|
|
108
|
+
listRenderingMode: RENDER_MODES.LIST_ITEMS
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (hasSectionsAndFolders) {
|
|
112
|
+
if (hasCurrentSection) {
|
|
113
|
+
if (!currentSectionHasFolders) {
|
|
157
114
|
return {
|
|
158
|
-
listRenderingMode: RENDER_MODES.
|
|
115
|
+
listRenderingMode: RENDER_MODES.LIST_ITEMS
|
|
159
116
|
};
|
|
160
117
|
}
|
|
161
|
-
return {
|
|
162
|
-
listRenderingMode: hasSearchQuery ? RENDER_MODES.LIST_ITEMS_IN_SECTIONS : RENDER_MODES.LIST_FOLDERS_IN_SECTIONS
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
if (hasSections && !hasCurrentSection) {
|
|
166
118
|
return {
|
|
167
119
|
listRenderingMode: RENDER_MODES.LIST_ITEMS_IN_SECTIONS
|
|
168
120
|
};
|
|
169
121
|
}
|
|
170
122
|
return {
|
|
171
|
-
listRenderingMode: RENDER_MODES.
|
|
123
|
+
listRenderingMode: hasSearchQuery ? RENDER_MODES.LIST_ITEMS_IN_SECTIONS : RENDER_MODES.LIST_FOLDERS_IN_SECTIONS
|
|
172
124
|
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
125
|
+
}
|
|
126
|
+
if (hasSections && !hasCurrentSection) {
|
|
127
|
+
return {
|
|
128
|
+
listRenderingMode: RENDER_MODES.LIST_ITEMS_IN_SECTIONS
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
listRenderingMode: RENDER_MODES.LIST_ITEMS
|
|
133
|
+
};
|
|
134
|
+
}, [hasCurrentSection, hasSections, hasSearchQuery, hasSectionsAndFolders, currentSectionHasFolders, isListItemsRenderingMode]);
|
|
135
|
+
const globalActionsLength = actions?.filter((action) => !action.sectionId).length || 0;
|
|
136
|
+
const recentsLength = recents?.length || 0;
|
|
137
|
+
const currentItemsLength = currentItems.length;
|
|
138
|
+
const resetCurrentSection = useCallback(() => {
|
|
139
|
+
setSearchInAction(void 0);
|
|
140
|
+
setSearchInItem(void 0);
|
|
141
|
+
setCurrentSection(void 0);
|
|
142
|
+
setPreviousSection(void 0);
|
|
185
143
|
}, []);
|
|
186
|
-
|
|
144
|
+
const goBack = useCallback(() => {
|
|
187
145
|
if (searchByAction) {
|
|
188
|
-
setSearchByAction(
|
|
146
|
+
setSearchByAction(void 0);
|
|
189
147
|
return;
|
|
190
148
|
}
|
|
191
149
|
if (searchInItem) {
|
|
192
|
-
changeSearchQuery(
|
|
193
|
-
setSearchByParamConfig(
|
|
194
|
-
setSearchInItem(
|
|
150
|
+
changeSearchQuery("");
|
|
151
|
+
setSearchByParamConfig(void 0);
|
|
152
|
+
setSearchInItem(void 0);
|
|
195
153
|
return;
|
|
196
154
|
}
|
|
197
155
|
if (searchInAction) {
|
|
198
|
-
changeSearchQuery(
|
|
199
|
-
setSearchInAction(
|
|
156
|
+
changeSearchQuery("");
|
|
157
|
+
setSearchInAction(void 0);
|
|
200
158
|
return;
|
|
201
159
|
}
|
|
202
160
|
if (searchQuery) {
|
|
203
161
|
setCurrentSection(previousSection);
|
|
204
|
-
setPreviousSection(
|
|
162
|
+
setPreviousSection(void 0);
|
|
205
163
|
return;
|
|
206
164
|
}
|
|
207
165
|
if (parentFolder) {
|
|
208
166
|
setCurrentSection(parentFolder);
|
|
209
167
|
return;
|
|
210
168
|
}
|
|
211
|
-
setCurrentSection(
|
|
169
|
+
setCurrentSection(void 0);
|
|
212
170
|
}, [searchInAction, searchByAction, searchQuery, parentFolder, previousSection, searchInItem, changeSearchQuery]);
|
|
213
|
-
|
|
171
|
+
const handleCurrentSectionChange = useCallback((section) => {
|
|
214
172
|
setPreviousSection(currentSection);
|
|
215
173
|
setCurrentSection(section);
|
|
216
174
|
}, [currentSection]);
|
|
217
|
-
|
|
175
|
+
const handleSectionChange = useCallback((section) => {
|
|
218
176
|
handleCurrentSectionChange(section);
|
|
219
|
-
onSectionChange
|
|
177
|
+
onSectionChange?.(section);
|
|
220
178
|
}, [onSectionChange, handleCurrentSectionChange]);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
currentItems.forEach(
|
|
179
|
+
const getLargestSectionHeight = useCallback(() => {
|
|
180
|
+
const itemsPerSection = {};
|
|
181
|
+
currentItems.forEach((item) => {
|
|
224
182
|
if (!item.sectionId) {
|
|
225
183
|
return;
|
|
226
184
|
}
|
|
@@ -233,7 +191,7 @@ export var useItemsInSections = function useItemsInSections(_ref) {
|
|
|
233
191
|
itemsPerSection[item.sectionId].items += ITEM_SIZE[itemSizes.DEFAULT];
|
|
234
192
|
});
|
|
235
193
|
if (actions) {
|
|
236
|
-
actions.forEach(
|
|
194
|
+
actions.forEach((item) => {
|
|
237
195
|
if (!item.sectionId) {
|
|
238
196
|
return;
|
|
239
197
|
}
|
|
@@ -246,183 +204,131 @@ export var useItemsInSections = function useItemsInSections(_ref) {
|
|
|
246
204
|
itemsPerSection[item.sectionId].actions += ITEM_SIZE[itemSizes.DEFAULT];
|
|
247
205
|
});
|
|
248
206
|
}
|
|
249
|
-
|
|
250
|
-
|
|
207
|
+
const largestSectionHeight = Object.values(itemsPerSection).reduce((maxHeight, sectionData) => {
|
|
208
|
+
const sectionHeight = sectionData.actions + sectionData.items + (+Boolean(sectionData.actions) + +Boolean(sectionData.items)) * ITEM_SIZE.title;
|
|
251
209
|
return Math.max(maxHeight, sectionHeight);
|
|
252
210
|
}, 0);
|
|
253
211
|
return largestSectionHeight + SECTION_HEADER_HEIGHT;
|
|
254
212
|
}, [currentItems, actions]);
|
|
255
|
-
|
|
213
|
+
const calculatedContentHeight = useMemo(() => {
|
|
256
214
|
if (isFixedItemsList && !searchQuery && !activeSectionId) {
|
|
257
|
-
|
|
258
|
-
|
|
215
|
+
const globalActionsHeight = getSectionHeight(globalActionsLength, !!globalActionsLength);
|
|
216
|
+
const recentHeight = getSectionHeight(recentsLength, !!recentsLength);
|
|
259
217
|
if (!hasSections) {
|
|
260
|
-
|
|
218
|
+
const mainItemsHeight = getSectionHeight(currentItemsLength, showItemsSectionLabel || !!(globalActionsHeight || recentHeight));
|
|
261
219
|
return mainItemsHeight + globalActionsHeight + recentHeight;
|
|
262
220
|
}
|
|
263
|
-
|
|
221
|
+
const largestSectionHeight = getLargestSectionHeight();
|
|
264
222
|
if (hasSectionsAndFolders) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return folderCount + (((_section$folders2 = section.folders) == null ? void 0 : _section$folders2.length) || 0);
|
|
268
|
-
}, 0));
|
|
269
|
-
return Math.max(_initialViewHeight, largestSectionHeight);
|
|
223
|
+
const initialViewHeight2 = globalActionsHeight + recentHeight + ITEM_SIZE.title * (sections.length + sections.reduce((folderCount, section) => folderCount + (section.folders?.length || 0), 0));
|
|
224
|
+
return Math.max(initialViewHeight2, largestSectionHeight);
|
|
270
225
|
}
|
|
271
|
-
|
|
272
|
-
var initialViewHeight = globalActionsHeight + recentHeight + ITEM_SIZE.title * sections.length + getSectionHeight(currentItemsLength, showItemsSectionLabel || !!(globalActionsHeight || recentHeight));
|
|
226
|
+
const initialViewHeight = globalActionsHeight + recentHeight + ITEM_SIZE.title * sections.length + getSectionHeight(currentItemsLength, showItemsSectionLabel || !!(globalActionsHeight || recentHeight));
|
|
273
227
|
return Math.max(initialViewHeight, largestSectionHeight);
|
|
274
228
|
}
|
|
275
|
-
return
|
|
229
|
+
return void 0;
|
|
276
230
|
}, [isFixedItemsList, searchQuery, activeSectionId, globalActionsLength, recentsLength, hasSections, getLargestSectionHeight, hasSectionsAndFolders, sections, currentItemsLength, showItemsSectionLabel]);
|
|
277
|
-
|
|
231
|
+
const isSelected = useCallback((item) => {
|
|
278
232
|
return !!(selectedItem && getItemKey(item) === getItemKey(selectedItem));
|
|
279
233
|
}, [getItemKey, selectedItem]);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
case 4:
|
|
321
|
-
setIsLoading(false);
|
|
322
|
-
pageToLoad.current = FIRST_PAGE + 1;
|
|
323
|
-
metaRef.current[activeSectionIdWithFallback] = meta;
|
|
324
|
-
onLoadedData == null || onLoadedData({
|
|
325
|
-
sectionId: activeSectionIdWithFallback,
|
|
326
|
-
meta: meta,
|
|
327
|
-
renderMode: listRenderingMode
|
|
328
|
-
});
|
|
329
|
-
setIsInitialDataLoaded(true);
|
|
330
|
-
setCurrentItems(_fetchedItems);
|
|
331
|
-
_context.n = 6;
|
|
332
|
-
break;
|
|
333
|
-
case 5:
|
|
334
|
-
_context.p = 5;
|
|
335
|
-
_t = _context.v;
|
|
336
|
-
setIsLoading(false);
|
|
337
|
-
setIsInitialDataLoaded(true);
|
|
338
|
-
setIsLoadingError(true);
|
|
339
|
-
case 6:
|
|
340
|
-
return _context.a(2);
|
|
341
|
-
case 7:
|
|
342
|
-
fetchedItems = [];
|
|
343
|
-
requests = listRenderingMode === RENDER_MODES.LIST_FOLDERS_IN_SECTIONS ? [Promise.resolve()] : currentFolders == null ? void 0 : currentFolders.map(function (folder) {
|
|
344
|
-
var sectionId = folder.id;
|
|
345
|
-
return items.loadItems({
|
|
346
|
-
page: FIRST_PAGE,
|
|
347
|
-
searchQuery: searchQuery,
|
|
348
|
-
limit: (items.limitPerSection || ITEMS_PER_SECTION) + 1,
|
|
349
|
-
sectionId: sectionId,
|
|
350
|
-
meta: undefined,
|
|
351
|
-
abortController: abortControllerRef.current,
|
|
352
|
-
searchKey: searchByParamConfig == null ? void 0 : searchByParamConfig.paramKey,
|
|
353
|
-
searchInItem: searchInItem
|
|
354
|
-
}).then(function (_ref3) {
|
|
355
|
-
var sectionItems = _ref3.items,
|
|
356
|
-
total = _ref3.total,
|
|
357
|
-
meta = _ref3.meta;
|
|
358
|
-
onLoadedData == null || onLoadedData({
|
|
359
|
-
sectionId: sectionId,
|
|
360
|
-
meta: meta,
|
|
361
|
-
renderMode: listRenderingMode
|
|
362
|
-
});
|
|
363
|
-
metaRef.current[folder.id] = meta;
|
|
364
|
-
sectionTotals.current[folder.id] = total;
|
|
365
|
-
fetchedItems = [].concat(fetchedItems, sectionItems);
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
_context.p = 8;
|
|
369
|
-
if (!requests) {
|
|
370
|
-
_context.n = 10;
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
_context.n = 9;
|
|
374
|
-
return Promise.allSettled(requests);
|
|
375
|
-
case 9:
|
|
376
|
-
_t2 = _context.v;
|
|
377
|
-
_context.n = 11;
|
|
378
|
-
break;
|
|
379
|
-
case 10:
|
|
380
|
-
_t2 = [];
|
|
381
|
-
case 11:
|
|
382
|
-
results = _t2;
|
|
383
|
-
if (!(currentRequestId !== requestIdRef.current)) {
|
|
384
|
-
_context.n = 12;
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
return _context.a(2);
|
|
388
|
-
case 12:
|
|
389
|
-
setIsLoading(false);
|
|
390
|
-
setIsInitialDataLoaded(true);
|
|
391
|
-
if (!results.every(function (result) {
|
|
392
|
-
return result.status === 'fulfilled';
|
|
393
|
-
})) {
|
|
394
|
-
_context.n = 13;
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
setCurrentItems(fetchedItems);
|
|
398
|
-
return _context.a(2);
|
|
399
|
-
case 13:
|
|
400
|
-
setIsLoadingError(true);
|
|
401
|
-
_context.n = 15;
|
|
402
|
-
break;
|
|
403
|
-
case 14:
|
|
404
|
-
_context.p = 14;
|
|
405
|
-
_t3 = _context.v;
|
|
406
|
-
setIsLoading(false);
|
|
407
|
-
setIsInitialDataLoaded(true);
|
|
408
|
-
setIsLoadingError(true);
|
|
409
|
-
case 15:
|
|
410
|
-
return _context.a(2);
|
|
234
|
+
const loadItems = useCallback(async () => {
|
|
235
|
+
if (isFixedItemsList || listActions || searchByAction) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
setIsLoading(true);
|
|
239
|
+
setIsLoadingError(false);
|
|
240
|
+
const currentRequestId = crypto.randomUUID();
|
|
241
|
+
requestIdRef.current = currentRequestId;
|
|
242
|
+
if (listRenderingMode === RENDER_MODES.LIST_ITEMS) {
|
|
243
|
+
try {
|
|
244
|
+
const {
|
|
245
|
+
items: fetchedItems2,
|
|
246
|
+
meta
|
|
247
|
+
} = await items.loadItems({
|
|
248
|
+
page: FIRST_PAGE,
|
|
249
|
+
searchQuery,
|
|
250
|
+
sectionId: activeSectionIdWithFallback,
|
|
251
|
+
limit: items.limitPerPage || ITEMS_PER_PAGE,
|
|
252
|
+
meta: void 0,
|
|
253
|
+
abortController: abortControllerRef.current,
|
|
254
|
+
searchKey: searchByParamConfig?.paramKey,
|
|
255
|
+
searchInItem
|
|
256
|
+
});
|
|
257
|
+
if (currentRequestId !== requestIdRef.current) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
setIsLoading(false);
|
|
261
|
+
pageToLoad.current = FIRST_PAGE + 1;
|
|
262
|
+
metaRef.current[activeSectionIdWithFallback] = meta;
|
|
263
|
+
onLoadedData?.({
|
|
264
|
+
sectionId: activeSectionIdWithFallback,
|
|
265
|
+
meta,
|
|
266
|
+
renderMode: listRenderingMode
|
|
267
|
+
});
|
|
268
|
+
setIsInitialDataLoaded(true);
|
|
269
|
+
setCurrentItems(fetchedItems2);
|
|
270
|
+
} catch (_event) {
|
|
271
|
+
setIsLoading(false);
|
|
272
|
+
setIsInitialDataLoaded(true);
|
|
273
|
+
setIsLoadingError(true);
|
|
411
274
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
let fetchedItems = [];
|
|
278
|
+
const requests = listRenderingMode === RENDER_MODES.LIST_FOLDERS_IN_SECTIONS ? [Promise.resolve()] : currentFolders?.map((folder) => {
|
|
279
|
+
const sectionId = folder.id;
|
|
280
|
+
return items.loadItems({
|
|
281
|
+
page: FIRST_PAGE,
|
|
282
|
+
searchQuery,
|
|
283
|
+
limit: (items.limitPerSection || ITEMS_PER_SECTION) + 1,
|
|
284
|
+
sectionId,
|
|
285
|
+
meta: void 0,
|
|
286
|
+
abortController: abortControllerRef.current,
|
|
287
|
+
searchKey: searchByParamConfig?.paramKey,
|
|
288
|
+
searchInItem
|
|
289
|
+
}).then(({
|
|
290
|
+
items: sectionItems,
|
|
291
|
+
total,
|
|
292
|
+
meta
|
|
293
|
+
}) => {
|
|
294
|
+
onLoadedData?.({
|
|
295
|
+
sectionId,
|
|
296
|
+
meta,
|
|
297
|
+
renderMode: listRenderingMode
|
|
298
|
+
});
|
|
299
|
+
metaRef.current[folder.id] = meta;
|
|
300
|
+
sectionTotals.current[folder.id] = total;
|
|
301
|
+
fetchedItems = [...fetchedItems, ...sectionItems];
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
try {
|
|
305
|
+
const results = requests ? await Promise.allSettled(requests) : [];
|
|
306
|
+
if (currentRequestId !== requestIdRef.current) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
setIsLoading(false);
|
|
310
|
+
setIsInitialDataLoaded(true);
|
|
311
|
+
if (results.every((result) => result.status === "fulfilled")) {
|
|
312
|
+
setCurrentItems(fetchedItems);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
setIsLoadingError(true);
|
|
316
|
+
} catch (_event) {
|
|
317
|
+
setIsLoading(false);
|
|
318
|
+
setIsInitialDataLoaded(true);
|
|
319
|
+
setIsLoadingError(true);
|
|
320
|
+
}
|
|
321
|
+
}, [searchByParamConfig, isFixedItemsList, currentFolders, listRenderingMode, items, listActions, searchQuery, searchByAction, onLoadedData, activeSectionIdWithFallback, searchInItem]);
|
|
322
|
+
useEffect(() => {
|
|
415
323
|
if (listActions) {
|
|
416
324
|
return;
|
|
417
325
|
}
|
|
418
326
|
if (isFixedItemsList) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
return item.sectionId === currentSection.id;
|
|
422
|
-
}) : allItems;
|
|
327
|
+
const allItems = isItemsConfig(items) ? items.items : items;
|
|
328
|
+
const itemsInSection = currentSection && !currentSectionHasFolders ? allItems.filter((item) => item.sectionId === currentSection.id) : allItems;
|
|
423
329
|
if (searchQuery) {
|
|
424
|
-
|
|
425
|
-
|
|
330
|
+
const matchingItems = itemsInSection.filter((item) => {
|
|
331
|
+
const matchValue = searchByParamConfig ? String(item[searchByParamConfig.paramKey]) : item.text;
|
|
426
332
|
return matchValue && matchesSearchQuery(matchValue, searchQuery);
|
|
427
333
|
});
|
|
428
334
|
setCurrentItems(matchingItems);
|
|
@@ -431,7 +337,7 @@ export var useItemsInSections = function useItemsInSections(_ref) {
|
|
|
431
337
|
setCurrentItems(itemsInSection);
|
|
432
338
|
}
|
|
433
339
|
}, [isFixedItemsList, isLoading, currentSection, isLoadingError, currentSectionHasFolders, currentItemsLength, items, listActions, searchQuery, searchByParamConfig]);
|
|
434
|
-
useEffect(
|
|
340
|
+
useEffect(() => {
|
|
435
341
|
pageToLoad.current = FIRST_PAGE;
|
|
436
342
|
metaRef.current = {};
|
|
437
343
|
setIsLoadedAll(false);
|
|
@@ -442,34 +348,28 @@ export var useItemsInSections = function useItemsInSections(_ref) {
|
|
|
442
348
|
loadItems();
|
|
443
349
|
}
|
|
444
350
|
}
|
|
445
|
-
return
|
|
446
|
-
|
|
447
|
-
(_abortControllerRef$c = abortControllerRef.current) == null || _abortControllerRef$c.abort();
|
|
351
|
+
return () => {
|
|
352
|
+
abortControllerRef.current?.abort();
|
|
448
353
|
abortControllerRef.current = new AbortController();
|
|
449
354
|
};
|
|
450
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
451
355
|
}, [activeSectionId, isFixedItemsList, searchQuery, listActions, refreshTrigger]);
|
|
452
|
-
useEffect(
|
|
453
|
-
|
|
356
|
+
useEffect(() => {
|
|
357
|
+
let timeout;
|
|
454
358
|
if (!hasSearchQuery && !hasCurrentSection && calculatedContentHeight) {
|
|
455
|
-
timeout = setTimeout(
|
|
456
|
-
return setContentHeight(calculatedContentHeight);
|
|
457
|
-
}, 50);
|
|
359
|
+
timeout = setTimeout(() => setContentHeight(calculatedContentHeight), 50);
|
|
458
360
|
}
|
|
459
|
-
return
|
|
361
|
+
return () => {
|
|
460
362
|
timeout && clearTimeout(timeout);
|
|
461
363
|
};
|
|
462
364
|
}, [calculatedContentHeight, hasCurrentSection, hasSearchQuery]);
|
|
463
|
-
|
|
464
|
-
|
|
365
|
+
const hasInfiniteScroll = !listActions && !isFixedItemsList && listRenderingMode === RENDER_MODES.LIST_ITEMS;
|
|
366
|
+
const refreshItems = useMemo(() => {
|
|
465
367
|
if (!isFixedItemsList) {
|
|
466
|
-
return
|
|
467
|
-
return setRefreshTrigger(Date.now());
|
|
468
|
-
};
|
|
368
|
+
return () => setRefreshTrigger(Date.now());
|
|
469
369
|
}
|
|
470
|
-
return
|
|
370
|
+
return void 0;
|
|
471
371
|
}, [isFixedItemsList]);
|
|
472
|
-
|
|
372
|
+
const handleScrollEndReach = useCallback(() => {
|
|
473
373
|
if (pageToLoad.current < SECOND_PAGE) {
|
|
474
374
|
return;
|
|
475
375
|
}
|
|
@@ -481,15 +381,16 @@ export var useItemsInSections = function useItemsInSections(_ref) {
|
|
|
481
381
|
items.loadItems({
|
|
482
382
|
page: pageToLoad.current,
|
|
483
383
|
limit: items.limitPerPage || ITEMS_PER_PAGE,
|
|
484
|
-
searchQuery
|
|
384
|
+
searchQuery,
|
|
485
385
|
sectionId: activeSectionIdWithFallback,
|
|
486
386
|
meta: metaRef.current[activeSectionIdWithFallback],
|
|
487
|
-
searchKey: searchByParamConfig
|
|
488
|
-
searchInItem
|
|
489
|
-
}).then(
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
387
|
+
searchKey: searchByParamConfig?.paramKey,
|
|
388
|
+
searchInItem
|
|
389
|
+
}).then(({
|
|
390
|
+
items: fetchedItems,
|
|
391
|
+
total,
|
|
392
|
+
meta
|
|
393
|
+
}) => {
|
|
493
394
|
sectionTotals.current[activeSectionIdWithFallback] = total;
|
|
494
395
|
metaRef.current[activeSectionIdWithFallback] = meta;
|
|
495
396
|
setIsLoadingMore(false);
|
|
@@ -498,138 +399,136 @@ export var useItemsInSections = function useItemsInSections(_ref) {
|
|
|
498
399
|
setIsLoadedAll(true);
|
|
499
400
|
}
|
|
500
401
|
pageToLoad.current += 1;
|
|
501
|
-
setCurrentItems([
|
|
502
|
-
})
|
|
402
|
+
setCurrentItems([...currentItems, ...fetchedItems]);
|
|
403
|
+
}).catch(() => {
|
|
503
404
|
setIsLoadingMore(false);
|
|
504
405
|
setIsLoadingMoreError(true);
|
|
505
406
|
});
|
|
506
407
|
}
|
|
507
408
|
}, [searchByParamConfig, isLoadingMore, hasInfiniteScroll, isLoadedAll, items, searchQuery, currentItems, activeSectionIdWithFallback, searchInItem]);
|
|
508
|
-
|
|
509
|
-
|
|
409
|
+
const mergedItemsList = useMemo(() => {
|
|
410
|
+
const isSearchInItemActive = !!searchInItem;
|
|
510
411
|
if (searchByAction) {
|
|
511
412
|
return getSearchByActionItems({
|
|
512
413
|
action: searchByAction,
|
|
513
|
-
setSearchByAction
|
|
514
|
-
setSearchByParamConfig
|
|
515
|
-
searchQuery
|
|
516
|
-
changeSearchQuery
|
|
414
|
+
setSearchByAction,
|
|
415
|
+
setSearchByParamConfig,
|
|
416
|
+
searchQuery,
|
|
417
|
+
changeSearchQuery
|
|
517
418
|
});
|
|
518
419
|
}
|
|
519
420
|
if (listActions) {
|
|
520
421
|
return getActionItems({
|
|
521
|
-
actions
|
|
522
|
-
texts
|
|
422
|
+
actions,
|
|
423
|
+
texts,
|
|
523
424
|
sectionId: activeSectionId,
|
|
524
|
-
setSearchByAction
|
|
525
|
-
changeSearchQuery
|
|
526
|
-
setSearchInAction
|
|
527
|
-
isSearchInItemActive
|
|
528
|
-
searchByParamConfig
|
|
529
|
-
setSearchByParamConfig
|
|
425
|
+
setSearchByAction,
|
|
426
|
+
changeSearchQuery,
|
|
427
|
+
setSearchInAction,
|
|
428
|
+
isSearchInItemActive,
|
|
429
|
+
searchByParamConfig,
|
|
430
|
+
setSearchByParamConfig
|
|
530
431
|
});
|
|
531
432
|
}
|
|
532
|
-
|
|
533
|
-
actions
|
|
534
|
-
texts
|
|
535
|
-
searchQuery
|
|
433
|
+
const sectionActions = getSectionActionItems({
|
|
434
|
+
actions,
|
|
435
|
+
texts,
|
|
436
|
+
searchQuery,
|
|
536
437
|
sectionId: activeSectionId,
|
|
537
|
-
setSearchByAction
|
|
538
|
-
changeSearchQuery
|
|
539
|
-
setSearchInAction
|
|
540
|
-
isSearchInItemActive
|
|
541
|
-
searchByParamConfig
|
|
542
|
-
setSearchByParamConfig
|
|
438
|
+
setSearchByAction,
|
|
439
|
+
changeSearchQuery,
|
|
440
|
+
setSearchInAction,
|
|
441
|
+
isSearchInItemActive,
|
|
442
|
+
searchByParamConfig,
|
|
443
|
+
setSearchByParamConfig
|
|
543
444
|
});
|
|
544
|
-
|
|
545
|
-
recents
|
|
546
|
-
texts
|
|
547
|
-
isSelected
|
|
548
|
-
searchQuery
|
|
549
|
-
handleItemSelect
|
|
445
|
+
const recentItems = activeSectionId || isSearchInItemActive || searchByParamConfig ? [] : getRecentItems({
|
|
446
|
+
recents,
|
|
447
|
+
texts,
|
|
448
|
+
isSelected,
|
|
449
|
+
searchQuery,
|
|
450
|
+
handleItemSelect,
|
|
550
451
|
isSearchParam: !!searchByParamConfig
|
|
551
452
|
});
|
|
552
|
-
|
|
553
|
-
sections
|
|
554
|
-
handleSectionChange
|
|
453
|
+
const folderItems = sections ? getFolderItems({
|
|
454
|
+
sections,
|
|
455
|
+
handleSectionChange
|
|
555
456
|
}) : [];
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
return item.sectionId === folder.id;
|
|
559
|
-
});
|
|
457
|
+
const listItems = !isListItemsRenderingMode && currentFolders ? currentFolders.flatMap((folder) => {
|
|
458
|
+
const itemsInFolder = currentItems.filter((item) => item.sectionId === folder.id);
|
|
560
459
|
return getItems({
|
|
561
460
|
items: itemsInFolder,
|
|
562
461
|
titlePath: folder.titles,
|
|
563
|
-
texts
|
|
564
|
-
searchQuery
|
|
462
|
+
texts,
|
|
463
|
+
searchQuery,
|
|
565
464
|
maxItems: itemsLimitPerSection,
|
|
566
|
-
showMoreOnClick:
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
isSelected: isSelected,
|
|
571
|
-
handleItemSelect: handleItemSelect,
|
|
465
|
+
showMoreOnClick: () => handleSectionChange(folder),
|
|
466
|
+
showItemsSectionLabel,
|
|
467
|
+
isSelected,
|
|
468
|
+
handleItemSelect,
|
|
572
469
|
isSearchParam: !!searchByParamConfig
|
|
573
470
|
});
|
|
574
471
|
}) : getItems({
|
|
575
472
|
items: currentItems,
|
|
576
|
-
texts
|
|
577
|
-
searchQuery
|
|
578
|
-
showItemsSectionLabel
|
|
579
|
-
isSelected
|
|
473
|
+
texts,
|
|
474
|
+
searchQuery,
|
|
475
|
+
showItemsSectionLabel,
|
|
476
|
+
isSelected,
|
|
580
477
|
handleItemSelect: handleItemSelectExtended,
|
|
581
478
|
isSearchParam: !!searchByParamConfig
|
|
582
479
|
});
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
480
|
+
const listItemsLength = listItems.length;
|
|
481
|
+
const isNoActionsRecentList = isSearchInActionActive || !listItemsLength && isSearchInItemActive;
|
|
482
|
+
const composedList = isNoActionsRecentList ? [] : [...sectionActions, ...recentItems];
|
|
586
483
|
switch (listRenderingMode) {
|
|
587
484
|
case RENDER_MODES.LIST_ITEMS:
|
|
588
|
-
return [
|
|
485
|
+
return [...composedList, ...listItems];
|
|
589
486
|
case RENDER_MODES.LIST_FOLDERS_IN_SECTIONS:
|
|
590
|
-
return [
|
|
487
|
+
return [...composedList, ...folderItems];
|
|
591
488
|
case RENDER_MODES.LIST_ITEMS_IN_SECTIONS:
|
|
592
489
|
default:
|
|
593
|
-
return [
|
|
490
|
+
return [...composedList, ...listItems];
|
|
594
491
|
}
|
|
595
492
|
}, [listActions, activeSectionId, actions, texts, searchQuery, recents, currentItems, showItemsSectionLabel, sections, currentFolders, itemsLimitPerSection, listRenderingMode, isSelected, handleItemSelect, handleSectionChange, setSearchByParamConfig, searchByAction, searchByParamConfig, changeSearchQuery, handleItemSelectExtended, isSearchInActionActive, searchInItem, isListItemsRenderingMode]);
|
|
596
|
-
|
|
597
|
-
var _abortControllerRef$c2;
|
|
493
|
+
const reloadActiveSection = useCallback(() => {
|
|
598
494
|
pageToLoad.current = FIRST_PAGE;
|
|
599
495
|
metaRef.current = {};
|
|
600
496
|
setIsLoadedAll(false);
|
|
601
497
|
setIsLoadingMore(false);
|
|
602
498
|
sectionTotals.current = {};
|
|
603
|
-
|
|
499
|
+
abortControllerRef.current?.abort();
|
|
604
500
|
abortControllerRef.current = new AbortController();
|
|
605
501
|
if (!listActions) {
|
|
606
502
|
loadItems();
|
|
607
503
|
}
|
|
608
504
|
}, [listActions, loadItems]);
|
|
609
505
|
return {
|
|
610
|
-
currentSection: !listActions ? currentSection :
|
|
611
|
-
currentPath
|
|
612
|
-
goBack
|
|
613
|
-
resetCurrentSection
|
|
506
|
+
currentSection: !listActions ? currentSection : void 0,
|
|
507
|
+
currentPath,
|
|
508
|
+
goBack,
|
|
509
|
+
resetCurrentSection,
|
|
614
510
|
setCurrentSection: handleCurrentSectionChange,
|
|
615
|
-
mergedItemsList
|
|
511
|
+
mergedItemsList,
|
|
616
512
|
isLoading: isLoading || !isInitialDataLoaded,
|
|
617
|
-
isLoadingMore
|
|
618
|
-
isLoadedAll
|
|
619
|
-
handleScrollEndReach
|
|
620
|
-
refreshItems
|
|
621
|
-
isLoadingError
|
|
622
|
-
isLoadingMoreError
|
|
623
|
-
contentHeight
|
|
513
|
+
isLoadingMore,
|
|
514
|
+
isLoadedAll,
|
|
515
|
+
handleScrollEndReach,
|
|
516
|
+
refreshItems,
|
|
517
|
+
isLoadingError,
|
|
518
|
+
isLoadingMoreError,
|
|
519
|
+
contentHeight,
|
|
624
520
|
refreshEnabled: !listActions,
|
|
625
|
-
searchByAction
|
|
626
|
-
searchByParamConfig
|
|
627
|
-
setSearchByParamConfig
|
|
628
|
-
listActions
|
|
629
|
-
searchInItem
|
|
630
|
-
searchInAction
|
|
631
|
-
canPerformListActions
|
|
632
|
-
reloadActiveSection
|
|
633
|
-
activeSectionId
|
|
521
|
+
searchByAction,
|
|
522
|
+
searchByParamConfig,
|
|
523
|
+
setSearchByParamConfig,
|
|
524
|
+
listActions,
|
|
525
|
+
searchInItem,
|
|
526
|
+
searchInAction,
|
|
527
|
+
canPerformListActions,
|
|
528
|
+
reloadActiveSection,
|
|
529
|
+
activeSectionId
|
|
634
530
|
};
|
|
635
|
-
};
|
|
531
|
+
};
|
|
532
|
+
export {
|
|
533
|
+
useItemsInSections
|
|
534
|
+
};
|