@blocklet/list 0.9.22 → 0.9.23
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/lib/contexts/filter.js
CHANGED
|
@@ -70,13 +70,16 @@ function FilterProvider(_ref) {
|
|
|
70
70
|
pageSize: (0, _utils.isMobileScreen)() ? _constant.default.mobilePageSize : _constant.default.pageSize,
|
|
71
71
|
defaultCurrentPage: _constant.default.defaultCurrentPage
|
|
72
72
|
});
|
|
73
|
+
const [fetchBlockletsError, setFetchBlockletsError] = (0, _react.useState)(null);
|
|
73
74
|
const {
|
|
74
|
-
data: blockletsState
|
|
75
|
-
|
|
75
|
+
data: blockletsState = {
|
|
76
|
+
list: [],
|
|
77
|
+
total: 0
|
|
78
|
+
},
|
|
76
79
|
loading: fetchBlockletsLoading,
|
|
77
80
|
loadMore: _loadMore,
|
|
78
81
|
loadingMore
|
|
79
|
-
} = (0, _ahooks.
|
|
82
|
+
} = (0, _ahooks.useInfiniteScroll)(async d => {
|
|
80
83
|
var _d$list;
|
|
81
84
|
|
|
82
85
|
const params = _objectSpread(_objectSpread({}, finalFilters), {}, {
|
|
@@ -90,33 +93,29 @@ function FilterProvider(_ref) {
|
|
|
90
93
|
} = await storeApi.get(_constant.default.blockletsPath, {
|
|
91
94
|
params
|
|
92
95
|
});
|
|
93
|
-
return
|
|
96
|
+
return {
|
|
97
|
+
list: (data === null || data === void 0 ? void 0 : data.dataList) || [],
|
|
98
|
+
total: (data === null || data === void 0 ? void 0 : data.total) || 0
|
|
99
|
+
};
|
|
94
100
|
}, {
|
|
95
|
-
initialData: {
|
|
96
|
-
list: [],
|
|
97
|
-
total: 0
|
|
98
|
-
},
|
|
99
|
-
loadMore: true,
|
|
100
101
|
isNoMore: d => d ? d.list.length >= d.total : false,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
refreshDeps: [endpoint, filters]
|
|
102
|
+
reloadDeps: [endpoint, filters],
|
|
103
|
+
onError: e => {
|
|
104
|
+
setFetchBlockletsError(e);
|
|
105
|
+
}
|
|
108
106
|
});
|
|
109
107
|
const {
|
|
110
|
-
data: allCategories,
|
|
108
|
+
data: allCategories = [],
|
|
111
109
|
error: fetchCategoriesError,
|
|
112
|
-
loading: fetchCategoriesLoading
|
|
110
|
+
loading: fetchCategoriesLoading,
|
|
111
|
+
run: fetchCategories
|
|
113
112
|
} = (0, _ahooks.useRequest)(async () => {
|
|
114
113
|
const {
|
|
115
114
|
data
|
|
116
115
|
} = await storeApi.get(_constant.default.categoriesPath);
|
|
117
116
|
return Array.isArray(data) ? data : [];
|
|
118
117
|
}, {
|
|
119
|
-
|
|
118
|
+
manual: true
|
|
120
119
|
});
|
|
121
120
|
const categoryList = (0, _react.useMemo)(() => {
|
|
122
121
|
const list = allCategories || []; // 分类按照名称排序
|
|
@@ -242,6 +241,9 @@ function FilterProvider(_ref) {
|
|
|
242
241
|
|
|
243
242
|
handleSearchSelect: onSearchSelect
|
|
244
243
|
};
|
|
244
|
+
(0, _react.useEffect)(() => {
|
|
245
|
+
fetchCategories(); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
246
|
+
}, [endpoint]);
|
|
245
247
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
|
|
246
248
|
value: filterStore,
|
|
247
249
|
children: children
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/list",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.23",
|
|
4
4
|
"description": "Common ux components of blocklet",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@emotion/react": "^11.10.0",
|
|
47
47
|
"@emotion/styled": "^11.10.0",
|
|
48
48
|
"@mui/icons-material": "^5.8.4",
|
|
49
|
-
"ahooks": "^
|
|
49
|
+
"ahooks": "^3.7.0",
|
|
50
50
|
"algoliasearch": "^4.14.2",
|
|
51
51
|
"axios": "^0.27.2",
|
|
52
52
|
"color": "^4.2.3",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"eslint": "^8.22.0",
|
|
69
69
|
"prettier": "^2.7.1"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "ea58ea3f43c1d1f8d9d6208d9a27380aac3c8994"
|
|
72
72
|
}
|
package/src/contexts/filter.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useContext, createContext, useMemo } from 'react';
|
|
1
|
+
import { useContext, createContext, useMemo, useState, useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { useRequest, useReactive } from 'ahooks';
|
|
3
|
+
import { useRequest, useReactive, useInfiniteScroll } from 'ahooks';
|
|
4
4
|
import orderBy from 'lodash/orderBy';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import { replaceTranslate, getPrices, getCategoryOptions, isMobileScreen, getCurrentPage } from '../libs/utils';
|
|
@@ -37,13 +37,14 @@ function FilterProvider({
|
|
|
37
37
|
defaultCurrentPage: constant.defaultCurrentPage,
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
const [fetchBlockletsError, setFetchBlockletsError] = useState(null);
|
|
41
|
+
|
|
40
42
|
const {
|
|
41
|
-
data: blockletsState,
|
|
42
|
-
error: fetchBlockletsError,
|
|
43
|
+
data: blockletsState = { list: [], total: 0 },
|
|
43
44
|
loading: fetchBlockletsLoading,
|
|
44
45
|
loadMore,
|
|
45
46
|
loadingMore,
|
|
46
|
-
} =
|
|
47
|
+
} = useInfiniteScroll(
|
|
47
48
|
async (d) => {
|
|
48
49
|
const params = {
|
|
49
50
|
...finalFilters,
|
|
@@ -52,29 +53,28 @@ function FilterProvider({
|
|
|
52
53
|
pageSize: paginateState.pageSize,
|
|
53
54
|
};
|
|
54
55
|
const { data = {} } = await storeApi.get(constant.blockletsPath, { params });
|
|
55
|
-
return data;
|
|
56
|
+
return { list: data?.dataList || [], total: data?.total || 0 };
|
|
56
57
|
},
|
|
57
58
|
{
|
|
58
|
-
initialData: { list: [], total: 0 },
|
|
59
|
-
loadMore: true,
|
|
60
59
|
isNoMore: (d) => (d ? d.list.length >= d.total : false),
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
reloadDeps: [endpoint, filters],
|
|
61
|
+
onError: (e) => {
|
|
62
|
+
setFetchBlockletsError(e);
|
|
63
63
|
},
|
|
64
|
-
refreshDeps: [endpoint, filters],
|
|
65
64
|
}
|
|
66
65
|
);
|
|
67
66
|
|
|
68
67
|
const {
|
|
69
|
-
data: allCategories,
|
|
68
|
+
data: allCategories = [],
|
|
70
69
|
error: fetchCategoriesError,
|
|
71
70
|
loading: fetchCategoriesLoading,
|
|
71
|
+
run: fetchCategories,
|
|
72
72
|
} = useRequest(
|
|
73
73
|
async () => {
|
|
74
74
|
const { data } = await storeApi.get(constant.categoriesPath);
|
|
75
75
|
return Array.isArray(data) ? data : [];
|
|
76
76
|
},
|
|
77
|
-
{
|
|
77
|
+
{ manual: true }
|
|
78
78
|
);
|
|
79
79
|
|
|
80
80
|
const categoryList = useMemo(() => {
|
|
@@ -171,6 +171,11 @@ function FilterProvider({
|
|
|
171
171
|
handleSearchSelect: onSearchSelect,
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
fetchCategories();
|
|
176
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
|
+
}, [endpoint]);
|
|
178
|
+
|
|
174
179
|
return <Provider value={filterStore}>{children}</Provider>;
|
|
175
180
|
}
|
|
176
181
|
|