@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.
@@ -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',
@@ -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
- error: fetchBlockletsError,
75
+ data: blockletsState = {
76
+ list: [],
77
+ total: 0
78
+ },
76
79
  loading: fetchBlockletsLoading,
77
80
  loadMore: _loadMore,
78
81
  loadingMore
79
- } = (0, _ahooks.useRequest)(async d => {
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 data;
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
- formatResult: response => {
102
- return {
103
- list: response === null || response === void 0 ? void 0 : response.dataList,
104
- total: response.total
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
- initialData: []
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.22",
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": "^2.10.14",
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": "e44cb12eb38523186f7b86d0693c2fa712c8700e"
71
+ "gitHead": "ea58ea3f43c1d1f8d9d6208d9a27380aac3c8994"
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',
@@ -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
- } = useRequest(
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
- formatResult: (response) => {
62
- return { list: response?.dataList, total: response.total };
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
- { initialData: [] }
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