@blocklet/list 0.9.21 → 0.9.24
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/components/autocomplete/index.js +1 -1
- package/lib/components/autocomplete/item.js +0 -2
- package/lib/contexts/filter.js +21 -19
- package/package.json +3 -3
- package/src/components/autocomplete/index.js +2 -7
- package/src/components/autocomplete/item.js +2 -2
- package/src/contexts/filter.js +18 -13
|
@@ -95,6 +95,7 @@ function Autocomplete(_ref) {
|
|
|
95
95
|
panelRootRef.current.render(children);
|
|
96
96
|
},
|
|
97
97
|
|
|
98
|
+
autoFocus: true,
|
|
98
99
|
classNames: {
|
|
99
100
|
panel: 'bl-autocomplete-panel',
|
|
100
101
|
label: 'bl-autocomplete-label',
|
|
@@ -160,7 +161,6 @@ function Autocomplete(_ref) {
|
|
|
160
161
|
theme: muiTheme,
|
|
161
162
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_item.default, {
|
|
162
163
|
item: item,
|
|
163
|
-
title: (item === null || item === void 0 ? void 0 : item.title) || (item === null || item === void 0 ? void 0 : item.name),
|
|
164
164
|
did: item.did,
|
|
165
165
|
description: item.description,
|
|
166
166
|
cover: logoUrl
|
|
@@ -75,7 +75,6 @@ function Blocklet(_ref) {
|
|
|
75
75
|
component: "h3",
|
|
76
76
|
variant: "h3",
|
|
77
77
|
className: "arcblock-blocklet__title",
|
|
78
|
-
title: title,
|
|
79
78
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ShowAttributes, {
|
|
80
79
|
item: item,
|
|
81
80
|
attribute: "title",
|
|
@@ -85,7 +84,6 @@ function Blocklet(_ref) {
|
|
|
85
84
|
component: "div",
|
|
86
85
|
variant: "body2",
|
|
87
86
|
className: "arcblock-blocklet__describe",
|
|
88
|
-
title: description,
|
|
89
87
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ShowAttributes, {
|
|
90
88
|
item: item,
|
|
91
89
|
attribute: "description",
|
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.24",
|
|
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": "942087559070e1d4805c153ad72fc5fe6c78740f"
|
|
72
72
|
}
|
|
@@ -56,6 +56,7 @@ export default function Autocomplete({ onSelect }) {
|
|
|
56
56
|
|
|
57
57
|
panelRootRef.current.render(children);
|
|
58
58
|
},
|
|
59
|
+
autoFocus: true,
|
|
59
60
|
classNames: {
|
|
60
61
|
panel: 'bl-autocomplete-panel',
|
|
61
62
|
label: 'bl-autocomplete-label',
|
|
@@ -97,13 +98,7 @@ export default function Autocomplete({ onSelect }) {
|
|
|
97
98
|
return (
|
|
98
99
|
<MuiThemeProvider theme={muiTheme}>
|
|
99
100
|
<EmotionThemeProvider theme={muiTheme}>
|
|
100
|
-
<Blocklet
|
|
101
|
-
item={item}
|
|
102
|
-
title={item?.title || item?.name}
|
|
103
|
-
did={item.did}
|
|
104
|
-
description={item.description}
|
|
105
|
-
cover={logoUrl}
|
|
106
|
-
/>
|
|
101
|
+
<Blocklet item={item} did={item.did} description={item.description} cover={logoUrl} />
|
|
107
102
|
</EmotionThemeProvider>
|
|
108
103
|
</MuiThemeProvider>
|
|
109
104
|
);
|
|
@@ -79,11 +79,11 @@ export default function Blocklet({ cover, item, className, ...rest }) {
|
|
|
79
79
|
)}
|
|
80
80
|
<div className="arcblock-blocklet__info">
|
|
81
81
|
<div className="arcblock-blocklet__text">
|
|
82
|
-
<Typography component="h3" variant="h3" className="arcblock-blocklet__title"
|
|
82
|
+
<Typography component="h3" variant="h3" className="arcblock-blocklet__title">
|
|
83
83
|
<ShowAttributes item={item} attribute="title" value={title || name} />
|
|
84
84
|
</Typography>
|
|
85
85
|
{description && (
|
|
86
|
-
<Typography component="div" variant="body2" className="arcblock-blocklet__describe"
|
|
86
|
+
<Typography component="div" variant="body2" className="arcblock-blocklet__describe">
|
|
87
87
|
<ShowAttributes item={item} attribute="description" value={description} />
|
|
88
88
|
</Typography>
|
|
89
89
|
)}
|
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
|
|