@blocklet/list 0.8.33 → 0.8.34

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/base.js CHANGED
@@ -13,6 +13,10 @@ var _material = require("@mui/material");
13
13
 
14
14
  var _Face = _interopRequireDefault(require("@mui/icons-material/Face"));
15
15
 
16
+ var _reactErrorBoundary = require("react-error-boundary");
17
+
18
+ var _ErrorBoundary = require("@arcblock/ux/lib/ErrorBoundary");
19
+
16
20
  var _filter = require("./contexts/filter");
17
21
 
18
22
  var _customSelect = _interopRequireDefault(require("./components/custom-select"));
@@ -104,8 +108,11 @@ function ListBase() {
104
108
  handlePrice(null);
105
109
  }
106
110
  })]
107
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_list.default, {
108
- blocklets: blockletList
111
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactErrorBoundary.ErrorBoundary, {
112
+ FallbackComponent: _ErrorBoundary.ErrorFallback,
113
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_list.default, {
114
+ blocklets: blockletList
115
+ })
109
116
  })]
110
117
  })]
111
118
  });
@@ -33,7 +33,7 @@ function Aside() {
33
33
  value: filters.price,
34
34
  onChange: handlePrice
35
35
  })
36
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
36
+ }), categoryOptions.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
37
37
  style: {
38
38
  marginTop: '16px'
39
39
  },
@@ -68,7 +68,7 @@ function FilterIcon() {
68
68
  onChange: v => {
69
69
  handelChange('price', v);
70
70
  }
71
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
71
+ }), categoryOptions.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
72
72
  style: {
73
73
  marginTop: '16px'
74
74
  },
@@ -11,20 +11,18 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
11
11
 
12
12
  var _Empty = _interopRequireDefault(require("@arcblock/ux/lib/Empty"));
13
13
 
14
- var _Alert = _interopRequireDefault(require("@arcblock/ux/lib/Alert"));
15
-
16
14
  var _Box = _interopRequireDefault(require("@mui/material/Box"));
17
15
 
18
16
  var _Grid = _interopRequireDefault(require("@mui/material/Grid"));
19
17
 
20
18
  var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
21
19
 
20
+ var _ErrorBoundary = require("@arcblock/ux/lib/ErrorBoundary");
21
+
22
22
  var _empty = require("./empty");
23
23
 
24
24
  var _filter = require("../../contexts/filter");
25
25
 
26
- var _utils = require("../../libs/utils");
27
-
28
26
  var _jsxRuntime = require("react/jsx-runtime");
29
27
 
30
28
  const _excluded = ["blocklets"];
@@ -55,17 +53,14 @@ function BlockletList(_ref) {
55
53
  blockletList,
56
54
  getCategoryLocale,
57
55
  filters,
58
- t
56
+ t,
57
+ endpoint
59
58
  } = (0, _filter.useFilterContext)();
60
59
  const showFilterTip = !!selectedCategory || !!filters.price;
61
60
 
62
61
  if (errors.fetchBlockletsError) {
63
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
64
- type: "error",
65
- variant: "icon",
66
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
67
- children: (0, _utils.formatError)(errors.fetchBlockletsError)
68
- })
62
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ErrorBoundary.ErrorFallback, {
63
+ error: new Error("Failed to fetch blocklets from ".concat(endpoint, ": ").concat(errors.fetchBlockletsError.message))
69
64
  });
70
65
  }
71
66
 
@@ -17,6 +17,8 @@ var _orderBy = _interopRequireDefault(require("lodash/orderBy"));
17
17
 
18
18
  var _axios = _interopRequireDefault(require("axios"));
19
19
 
20
+ var _isArray = _interopRequireDefault(require("lodash/isArray"));
21
+
20
22
  var _utils = require("../libs/utils");
21
23
 
22
24
  var _locale = _interopRequireDefault(require("../assets/locale"));
@@ -44,7 +46,6 @@ function FilterProvider(_ref) {
44
46
  let {
45
47
  filters,
46
48
  children,
47
- baseUrl,
48
49
  endpoint,
49
50
  locale,
50
51
  blockletRender,
@@ -63,9 +64,14 @@ function FilterProvider(_ref) {
63
64
  run: fetchBlocklets
64
65
  } = (0, _ahooks.useRequest)(async () => {
65
66
  const {
66
- data: list
67
+ data
67
68
  } = await storeApi.get('/api/blocklets.json');
68
- return list;
69
+
70
+ if (!(0, _isArray.default)(data)) {
71
+ throw new Error('/api/blocklets.json response is not array');
72
+ }
73
+
74
+ return data;
69
75
  }, {
70
76
  initialData: [],
71
77
  manual: true
@@ -77,9 +83,14 @@ function FilterProvider(_ref) {
77
83
  run: fetchCategories
78
84
  } = (0, _ahooks.useRequest)(async () => {
79
85
  const {
80
- data: list
86
+ data
81
87
  } = await storeApi.get('/api/blocklets/categories');
82
- return list;
88
+
89
+ if (!(0, _isArray.default)(data)) {
90
+ throw new Error('/api/blocklets/categories response is not array');
91
+ }
92
+
93
+ return data;
83
94
  }, {
84
95
  initialData: [],
85
96
  manual: true
@@ -174,7 +185,6 @@ function FilterProvider(_ref) {
174
185
  filters: finalFilters,
175
186
  selectedCategory,
176
187
  categoryList,
177
- baseUrl,
178
188
  blockletRender,
179
189
  locale,
180
190
  categoryOptions,
@@ -234,9 +244,10 @@ function FilterProvider(_ref) {
234
244
  },
235
245
 
236
246
  get developerName() {
237
- var _allBlocklets$find, _allBlocklets$find$ow;
247
+ var _blocklets$find, _blocklets$find$owner;
238
248
 
239
- return ((_allBlocklets$find = allBlocklets.find(blocklet => blocklet.owner.did === finalFilters.developer)) === null || _allBlocklets$find === void 0 ? void 0 : (_allBlocklets$find$ow = _allBlocklets$find.owner) === null || _allBlocklets$find$ow === void 0 ? void 0 : _allBlocklets$find$ow.name) || '';
249
+ const blocklets = allBlocklets || [];
250
+ return ((_blocklets$find = blocklets.find(blocklet => blocklet.owner.did === finalFilters.developer)) === null || _blocklets$find === void 0 ? void 0 : (_blocklets$find$owner = _blocklets$find.owner) === null || _blocklets$find$owner === void 0 ? void 0 : _blocklets$find$owner.name) || '';
240
251
  }
241
252
 
242
253
  };
@@ -22,12 +22,10 @@ const propTypes = {
22
22
  endpoint: _propTypes.default.string.isRequired,
23
23
  blockletRender: _propTypes.default.func.isRequired,
24
24
  onFilterChange: _propTypes.default.func,
25
- baseUrl: _propTypes.default.string,
26
25
  locale: _propTypes.default.oneOf(['zh', 'en'])
27
26
  };
28
27
  exports.propTypes = propTypes;
29
28
  const defaultProps = {
30
- baseUrl: null,
31
29
  locale: 'zh',
32
30
  filters: {},
33
31
  onFilterChange: () => {},
package/lib/libs/utils.js CHANGED
@@ -68,7 +68,9 @@ const getCategoryOptions = function getCategoryOptions() {
68
68
 
69
69
  exports.getCategoryOptions = getCategoryOptions;
70
70
 
71
- const getCategories = (list, developerDid) => {
71
+ const getCategories = function getCategories() {
72
+ let list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
73
+ let developerDid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
72
74
  const filterList = list.filter(item => developerDid ? item.owner.did === developerDid : true);
73
75
  const Categories = filterList.map(item => item.category);
74
76
  const res = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/list",
3
- "version": "0.8.33",
3
+ "version": "0.8.34",
4
4
  "description": "Common ux components of blocklet",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -38,7 +38,7 @@
38
38
  "react": ">=18.1.0"
39
39
  },
40
40
  "dependencies": {
41
- "@arcblock/ux": "^2.1.17",
41
+ "@arcblock/ux": "^2.1.19",
42
42
  "@emotion/react": "^11.9.0",
43
43
  "@emotion/styled": "^11.8.1",
44
44
  "@mui/icons-material": "^5.6.2",
@@ -47,6 +47,7 @@
47
47
  "flat": "^5.0.2",
48
48
  "lodash": "^4.17.21",
49
49
  "prop-types": "^15.7.2",
50
+ "react-error-boundary": "^3.1.4",
50
51
  "styled-components": "5.3.5",
51
52
  "url-join": "^4.0.1"
52
53
  },
@@ -62,5 +63,5 @@
62
63
  "eslint": "^8.16.0",
63
64
  "prettier": "^2.6.2"
64
65
  },
65
- "gitHead": "5e7c02cb3dfd0edff3f8290509f754b10bbc61bc"
66
+ "gitHead": "fed8918e15b5bd8cb3f4bac84b32434b58dda21b"
66
67
  }
package/src/base.js CHANGED
@@ -2,6 +2,8 @@ import styled from 'styled-components';
2
2
  import SortIcon from '@mui/icons-material/Sort';
3
3
  import { Box, Hidden } from '@mui/material';
4
4
  import FaceIcon from '@mui/icons-material/Face';
5
+ import { ErrorBoundary } from 'react-error-boundary';
6
+ import { ErrorFallback } from '@arcblock/ux/lib/ErrorBoundary';
5
7
 
6
8
  import { useFilterContext } from './contexts/filter';
7
9
  import CustomSelect from './components/custom-select';
@@ -76,7 +78,9 @@ function ListBase() {
76
78
  }}
77
79
  />
78
80
  </Box>
79
- <BlockletList blocklets={blockletList} />
81
+ <ErrorBoundary FallbackComponent={ErrorFallback}>
82
+ <BlockletList blocklets={blockletList} />
83
+ </ErrorBoundary>
80
84
  </StyledMin>
81
85
  </Box>
82
86
  );
@@ -12,14 +12,16 @@ function Aside() {
12
12
  <div>
13
13
  <FilterGroup title={t('common.price')} options={priceOptions} value={filters.price} onChange={handlePrice} />
14
14
  </div>
15
- <div style={{ marginTop: '16px' }}>
16
- <FilterGroup
17
- title={t('common.category')}
18
- options={categoryOptions}
19
- value={selectedCategory}
20
- onChange={handleCategory}
21
- />
22
- </div>
15
+ {categoryOptions.length > 0 && (
16
+ <div style={{ marginTop: '16px' }}>
17
+ <FilterGroup
18
+ title={t('common.category')}
19
+ options={categoryOptions}
20
+ value={selectedCategory}
21
+ onChange={handleCategory}
22
+ />
23
+ </div>
24
+ )}
23
25
  </StyledAside>
24
26
  );
25
27
  }
@@ -36,16 +36,18 @@ function FilterIcon() {
36
36
  handelChange('price', v);
37
37
  }}
38
38
  />
39
- <div style={{ marginTop: '16px' }}>
40
- <FilterGroup
41
- title={t('common.category')}
42
- options={categoryOptions}
43
- value={selectedCategory}
44
- onChange={(v) => {
45
- handelChange('category', v);
46
- }}
47
- />
48
- </div>
39
+ {categoryOptions.length > 0 && (
40
+ <div style={{ marginTop: '16px' }}>
41
+ <FilterGroup
42
+ title={t('common.category')}
43
+ options={categoryOptions}
44
+ value={selectedCategory}
45
+ onChange={(v) => {
46
+ handelChange('category', v);
47
+ }}
48
+ />
49
+ </div>
50
+ )}
49
51
  </Dialog>
50
52
  </StyledDiv>
51
53
  );
@@ -1,26 +1,25 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import styled from 'styled-components';
3
3
  import Empty from '@arcblock/ux/lib/Empty';
4
- import Alert from '@arcblock/ux/lib/Alert';
5
4
  import Box from '@mui/material/Box';
6
5
  import Grid from '@mui/material/Grid';
7
6
  import CircularProgress from '@mui/material/CircularProgress';
7
+ import { ErrorFallback } from '@arcblock/ux/lib/ErrorBoundary';
8
8
 
9
9
  import { NoResults, EmptyTitle, NoResultsTips } from './empty';
10
10
  import { useFilterContext } from '../../contexts/filter';
11
- import { formatError } from '../../libs/utils';
12
11
 
13
12
  export default function BlockletList({ blocklets, ...rest }) {
14
- const { blockletRender, errors, loadings, selectedCategory, blockletList, getCategoryLocale, filters, t } =
13
+ const { blockletRender, errors, loadings, selectedCategory, blockletList, getCategoryLocale, filters, t, endpoint } =
15
14
  useFilterContext();
16
15
 
17
16
  const showFilterTip = !!selectedCategory || !!filters.price;
18
17
 
19
18
  if (errors.fetchBlockletsError) {
20
19
  return (
21
- <Alert type="error" variant="icon">
22
- <div>{formatError(errors.fetchBlockletsError)}</div>
23
- </Alert>
20
+ <ErrorFallback
21
+ error={new Error(`Failed to fetch blocklets from ${endpoint}: ${errors.fetchBlockletsError.message}`)}
22
+ />
24
23
  );
25
24
  }
26
25
  if (loadings.fetchBlockletsLoading) {
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import { useRequest } from 'ahooks';
4
4
  import orderBy from 'lodash/orderBy';
5
5
  import axios from 'axios';
6
- // import joinUrl from 'url-join';
6
+ import isArray from 'lodash/isArray';
7
7
 
8
8
  import { getCategories, filterBlockletByPrice, replaceTranslate, getPrices, getCategoryOptions } from '../libs/utils';
9
9
  import translations from '../assets/locale';
@@ -12,7 +12,7 @@ import { propTypes, defaultProps } from '../libs/prop-types';
12
12
  const Filter = createContext({});
13
13
  const { Provider, Consumer } = Filter;
14
14
 
15
- function FilterProvider({ filters, children, baseUrl, endpoint, locale, blockletRender, onFilterChange, extraFilter }) {
15
+ function FilterProvider({ filters, children, endpoint, locale, blockletRender, onFilterChange, extraFilter }) {
16
16
  const storeApi = axios.create({
17
17
  baseURL: endpoint,
18
18
  });
@@ -23,8 +23,11 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
23
23
  run: fetchBlocklets,
24
24
  } = useRequest(
25
25
  async () => {
26
- const { data: list } = await storeApi.get('/api/blocklets.json');
27
- return list;
26
+ const { data } = await storeApi.get('/api/blocklets.json');
27
+ if (!isArray(data)) {
28
+ throw new Error('/api/blocklets.json response is not array');
29
+ }
30
+ return data;
28
31
  },
29
32
  { initialData: [], manual: true }
30
33
  );
@@ -36,8 +39,11 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
36
39
  run: fetchCategories,
37
40
  } = useRequest(
38
41
  async () => {
39
- const { data: list } = await storeApi.get('/api/blocklets/categories');
40
- return list;
42
+ const { data } = await storeApi.get('/api/blocklets/categories');
43
+ if (!isArray(data)) {
44
+ throw new Error('/api/blocklets/categories response is not array');
45
+ }
46
+ return data;
41
47
  },
42
48
  { initialData: [], manual: true }
43
49
  );
@@ -59,7 +65,6 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
59
65
  popularity: sortByPopularity,
60
66
  publishAt: sortByPublish,
61
67
  };
62
-
63
68
  let blocklets = allBlocklets || [];
64
69
  // 按照付费/免费筛选
65
70
  blocklets = filterBlockletByPrice(blocklets, finalFilters.price);
@@ -98,10 +103,8 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
98
103
 
99
104
  return replaceTranslate(translations[locale][key], data);
100
105
  };
101
-
102
106
  const categoryOptions = useMemo(() => getCategoryOptions(categoryList, locale), [categoryList, locale]);
103
107
  const priceOptions = getPrices(translate);
104
-
105
108
  const filterStore = {
106
109
  errors: { fetchBlockletsError, fetchCategoriesError },
107
110
  loadings: { fetchBlockletsLoading, fetchCategoriesLoading },
@@ -111,7 +114,6 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
111
114
  filters: finalFilters,
112
115
  selectedCategory,
113
116
  categoryList,
114
- baseUrl,
115
117
  blockletRender,
116
118
  locale,
117
119
  categoryOptions,
@@ -157,7 +159,8 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
157
159
  return result;
158
160
  },
159
161
  get developerName() {
160
- return allBlocklets.find((blocklet) => blocklet.owner.did === finalFilters.developer)?.owner?.name || '';
162
+ const blocklets = allBlocklets || [];
163
+ return blocklets.find((blocklet) => blocklet.owner.did === finalFilters.developer)?.owner?.name || '';
161
164
  },
162
165
  };
163
166
 
@@ -13,12 +13,10 @@ const propTypes = {
13
13
  endpoint: PropTypes.string.isRequired,
14
14
  blockletRender: PropTypes.func.isRequired,
15
15
  onFilterChange: PropTypes.func,
16
- baseUrl: PropTypes.string,
17
16
  locale: PropTypes.oneOf(['zh', 'en']),
18
17
  };
19
18
 
20
19
  const defaultProps = {
21
- baseUrl: null,
22
20
  locale: 'zh',
23
21
  filters: {},
24
22
  onFilterChange: () => {},
package/src/libs/utils.js CHANGED
@@ -44,7 +44,7 @@ const getCategoryOptions = (list = [], locale = 'en') => {
44
44
  * @param {*} developerDid
45
45
  * @returns
46
46
  */
47
- const getCategories = (list, developerDid) => {
47
+ const getCategories = (list = [], developerDid = null) => {
48
48
  const filterList = list.filter((item) => (developerDid ? item.owner.did === developerDid : true));
49
49
  const Categories = filterList.map((item) => item.category);
50
50
  const res = new Map();