@blocklet/list 0.9.17 → 0.9.20
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 +4 -1
- package/lib/components/autocomplete/index.js +29 -34
- package/lib/components/autocomplete/item.js +13 -35
- package/lib/contexts/filter.js +5 -5
- package/lib/libs/prop-types.js +9 -4
- package/package.json +2 -2
- package/src/base.js +2 -1
- package/src/components/autocomplete/index.js +10 -22
- package/src/components/autocomplete/item.js +7 -21
- package/src/contexts/filter.js +3 -3
- package/src/libs/prop-types.js +4 -2
package/lib/base.js
CHANGED
|
@@ -50,6 +50,7 @@ function ListBase() {
|
|
|
50
50
|
handleSort,
|
|
51
51
|
handleCategory,
|
|
52
52
|
handlePrice,
|
|
53
|
+
handleSearchSelect,
|
|
53
54
|
t,
|
|
54
55
|
getCategoryLocale,
|
|
55
56
|
priceOptions
|
|
@@ -71,7 +72,9 @@ function ListBase() {
|
|
|
71
72
|
className: "filter-bar",
|
|
72
73
|
display: "flex",
|
|
73
74
|
alignItems: "center",
|
|
74
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_autocomplete.default, {
|
|
75
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_autocomplete.default, {
|
|
76
|
+
onSelect: handleSearchSelect
|
|
77
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
75
78
|
mt: 0,
|
|
76
79
|
ml: "16px",
|
|
77
80
|
className: "filter-container",
|
|
@@ -7,6 +7,8 @@ exports.default = Autocomplete;
|
|
|
7
7
|
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
10
12
|
var _client = require("react-dom/client");
|
|
11
13
|
|
|
12
14
|
var _autocompleteJs = require("@algolia/autocomplete-js");
|
|
@@ -35,7 +37,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
35
37
|
|
|
36
38
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
37
39
|
|
|
38
|
-
function Autocomplete() {
|
|
40
|
+
function Autocomplete(_ref) {
|
|
41
|
+
let {
|
|
42
|
+
onSelect
|
|
43
|
+
} = _ref;
|
|
39
44
|
const containerRef = (0, _react.useRef)(null);
|
|
40
45
|
const panelRootRef = (0, _react.useRef)(null);
|
|
41
46
|
const rootRef = (0, _react.useRef)(null);
|
|
@@ -44,8 +49,7 @@ function Autocomplete() {
|
|
|
44
49
|
filters,
|
|
45
50
|
endpoint,
|
|
46
51
|
handleKeyword,
|
|
47
|
-
t
|
|
48
|
-
serverUrl
|
|
52
|
+
t
|
|
49
53
|
} = (0, _filter.useFilterContext)();
|
|
50
54
|
const muiTheme = (0, _styles.useTheme)();
|
|
51
55
|
const getResults = (0, _react.useCallback)(async params => {
|
|
@@ -56,20 +60,6 @@ function Autocomplete() {
|
|
|
56
60
|
});
|
|
57
61
|
return data.dataList || [];
|
|
58
62
|
}, [storeApi]);
|
|
59
|
-
const getBlockletDetail = (0, _react.useCallback)(item => {
|
|
60
|
-
let blockletDetail = (0, _urlJoin.default)(endpoint, "/blocklets/".concat(item.did));
|
|
61
|
-
|
|
62
|
-
if (serverUrl) {
|
|
63
|
-
blockletDetail = "".concat(blockletDetail, "?server-url=").concat(encodeURIComponent(serverUrl));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return blockletDetail;
|
|
67
|
-
}, [endpoint, serverUrl]);
|
|
68
|
-
|
|
69
|
-
const onClickItem = detailUrl => {
|
|
70
|
-
window.location.href = detailUrl;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
63
|
const onSubmit = (0, _react.useCallback)(e => {
|
|
74
64
|
handleKeyword(e.state.query);
|
|
75
65
|
}, [handleKeyword]);
|
|
@@ -89,10 +79,10 @@ function Autocomplete() {
|
|
|
89
79
|
render: () => {}
|
|
90
80
|
},
|
|
91
81
|
|
|
92
|
-
render(
|
|
82
|
+
render(_ref2, root) {
|
|
93
83
|
let {
|
|
94
84
|
children
|
|
95
|
-
} =
|
|
85
|
+
} = _ref2;
|
|
96
86
|
|
|
97
87
|
if (!panelRootRef.current || rootRef.current !== root) {
|
|
98
88
|
var _panelRootRef$current;
|
|
@@ -119,10 +109,10 @@ function Autocomplete() {
|
|
|
119
109
|
onSubmit,
|
|
120
110
|
onReset,
|
|
121
111
|
|
|
122
|
-
getSources(
|
|
112
|
+
getSources(_ref3) {
|
|
123
113
|
let {
|
|
124
114
|
query
|
|
125
|
-
} =
|
|
115
|
+
} = _ref3;
|
|
126
116
|
|
|
127
117
|
const params = _objectSpread(_objectSpread({}, filters), {}, {
|
|
128
118
|
sortBy: _constant.default[filters.sortBy],
|
|
@@ -139,29 +129,31 @@ function Autocomplete() {
|
|
|
139
129
|
},
|
|
140
130
|
|
|
141
131
|
// 选中后填充 搜索框中值
|
|
142
|
-
getItemInputValue(
|
|
132
|
+
getItemInputValue(_ref4) {
|
|
143
133
|
let {
|
|
144
134
|
item
|
|
145
|
-
} =
|
|
135
|
+
} = _ref4;
|
|
146
136
|
return item.title;
|
|
147
137
|
},
|
|
148
138
|
|
|
149
|
-
|
|
139
|
+
onSelect(_ref5) {
|
|
150
140
|
let {
|
|
151
141
|
item
|
|
152
|
-
} =
|
|
153
|
-
|
|
154
|
-
|
|
142
|
+
} = _ref5;
|
|
143
|
+
onSelect({
|
|
144
|
+
blocklet: item,
|
|
145
|
+
detailUrl: (0, _urlJoin.default)(endpoint, "/blocklets/".concat(item.did)),
|
|
146
|
+
storeUrl: endpoint
|
|
147
|
+
});
|
|
155
148
|
},
|
|
156
149
|
|
|
157
150
|
templates: {
|
|
158
151
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
159
|
-
item(
|
|
152
|
+
item(_ref6) {
|
|
160
153
|
let {
|
|
161
154
|
item
|
|
162
|
-
} =
|
|
155
|
+
} = _ref6;
|
|
163
156
|
const logoUrl = item.logo ? (0, _urlJoin.default)(endpoint, 'assets', item.did, item.logo) : null;
|
|
164
|
-
const blockletDetail = getBlockletDetail(item);
|
|
165
157
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.ThemeProvider, {
|
|
166
158
|
theme: muiTheme,
|
|
167
159
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.ThemeProvider, {
|
|
@@ -171,8 +163,7 @@ function Autocomplete() {
|
|
|
171
163
|
title: (item === null || item === void 0 ? void 0 : item.title) || (item === null || item === void 0 ? void 0 : item.name),
|
|
172
164
|
did: item.did,
|
|
173
165
|
description: item.description,
|
|
174
|
-
cover: logoUrl
|
|
175
|
-
onMainClick: () => onClickItem(blockletDetail)
|
|
166
|
+
cover: logoUrl
|
|
176
167
|
})
|
|
177
168
|
})
|
|
178
169
|
});
|
|
@@ -190,9 +181,13 @@ function Autocomplete() {
|
|
|
190
181
|
return () => {
|
|
191
182
|
search.destroy();
|
|
192
183
|
};
|
|
193
|
-
}, [endpoint, filters,
|
|
184
|
+
}, [endpoint, filters, getResults, muiTheme, onReset, onSubmit, onSelect, t]);
|
|
194
185
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
195
186
|
className: "bl-search-container",
|
|
196
187
|
ref: containerRef
|
|
197
188
|
});
|
|
198
|
-
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
Autocomplete.propTypes = {
|
|
192
|
+
onSelect: _propTypes.default.func.isRequired
|
|
193
|
+
};
|
|
@@ -17,7 +17,7 @@ var _Avatar = _interopRequireDefault(require("@arcblock/did-connect/lib/Avatar")
|
|
|
17
17
|
|
|
18
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
19
|
|
|
20
|
-
const _excluded = ["cover", "
|
|
20
|
+
const _excluded = ["cover", "item", "className"];
|
|
21
21
|
|
|
22
22
|
var _templateObject;
|
|
23
23
|
|
|
@@ -40,46 +40,22 @@ const Div = _styled.default.div(_templateObject || (_templateObject = _taggedTem
|
|
|
40
40
|
function Blocklet(_ref) {
|
|
41
41
|
let {
|
|
42
42
|
cover,
|
|
43
|
-
onMainClick,
|
|
44
43
|
item,
|
|
45
44
|
className
|
|
46
45
|
} = _ref,
|
|
47
46
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
48
47
|
|
|
49
|
-
const wrapHandler = function wrapHandler(handler) {
|
|
50
|
-
let stopFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => false;
|
|
51
|
-
return function (e) {
|
|
52
|
-
if (stopFn()) {
|
|
53
|
-
e.preventDefault();
|
|
54
|
-
e.stopPropagation();
|
|
55
|
-
} else if (handler instanceof Function) {
|
|
56
|
-
e.preventDefault();
|
|
57
|
-
e.stopPropagation();
|
|
58
|
-
|
|
59
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
60
|
-
args[_key - 1] = arguments[_key];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
handler(...args);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const _onMainClick = wrapHandler(onMainClick);
|
|
69
|
-
|
|
70
48
|
const {
|
|
71
49
|
did,
|
|
72
50
|
description,
|
|
73
51
|
title,
|
|
74
52
|
name
|
|
75
53
|
} = item;
|
|
76
|
-
const blockletTitle = title || name;
|
|
77
54
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Div, _objectSpread(_objectSpread({
|
|
78
55
|
className: "".concat(className, " arcblock-blocklet")
|
|
79
56
|
}, rest), {}, {
|
|
80
57
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
81
58
|
className: "arcblock-blocklet__content",
|
|
82
|
-
onClick: _onMainClick,
|
|
83
59
|
children: [cover ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
84
60
|
className: "arcblock-blocklet__cover",
|
|
85
61
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Img.default, {
|
|
@@ -103,7 +79,7 @@ function Blocklet(_ref) {
|
|
|
103
79
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ShowAttributes, {
|
|
104
80
|
item: item,
|
|
105
81
|
attribute: "title",
|
|
106
|
-
value:
|
|
82
|
+
value: title || name
|
|
107
83
|
})
|
|
108
84
|
}), description && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
109
85
|
component: "div",
|
|
@@ -124,13 +100,11 @@ function Blocklet(_ref) {
|
|
|
124
100
|
|
|
125
101
|
Blocklet.propTypes = {
|
|
126
102
|
cover: _propTypes.default.string,
|
|
127
|
-
onMainClick: _propTypes.default.func,
|
|
128
103
|
className: _propTypes.default.string,
|
|
129
104
|
item: _propTypes.default.object.isRequired
|
|
130
105
|
};
|
|
131
106
|
Blocklet.defaultProps = {
|
|
132
107
|
cover: null,
|
|
133
|
-
onMainClick: null,
|
|
134
108
|
className: null
|
|
135
109
|
};
|
|
136
110
|
|
|
@@ -140,13 +114,17 @@ function ShowAttributes(_ref2) {
|
|
|
140
114
|
attribute,
|
|
141
115
|
value
|
|
142
116
|
} = _ref2;
|
|
143
|
-
|
|
144
|
-
if (item._formatted)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
117
|
+
|
|
118
|
+
if (item._formatted) {
|
|
119
|
+
// eslint-disable-next-line react/no-danger
|
|
120
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
121
|
+
"data-cy": "bl-autocomplete-item",
|
|
122
|
+
dangerouslySetInnerHTML: {
|
|
123
|
+
__html: item._formatted[attribute]
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
150
128
|
return value;
|
|
151
129
|
}
|
|
152
130
|
|
package/lib/contexts/filter.js
CHANGED
|
@@ -50,8 +50,8 @@ function FilterProvider(_ref) {
|
|
|
50
50
|
locale,
|
|
51
51
|
blockletRender,
|
|
52
52
|
onFilterChange,
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
onSearchSelect,
|
|
54
|
+
extraFilter
|
|
55
55
|
} = _ref;
|
|
56
56
|
|
|
57
57
|
const storeApi = _axios.default.create({
|
|
@@ -114,7 +114,7 @@ function FilterProvider(_ref) {
|
|
|
114
114
|
const {
|
|
115
115
|
data
|
|
116
116
|
} = await storeApi.get(_constant.default.categoriesPath);
|
|
117
|
-
return data;
|
|
117
|
+
return Array.isArray(data) ? data : [];
|
|
118
118
|
}, {
|
|
119
119
|
initialData: []
|
|
120
120
|
});
|
|
@@ -162,7 +162,6 @@ function FilterProvider(_ref) {
|
|
|
162
162
|
categoryOptions,
|
|
163
163
|
priceOptions,
|
|
164
164
|
storeApi,
|
|
165
|
-
serverUrl,
|
|
166
165
|
hasNextPage: blockletsState.list.length < blockletsState.total,
|
|
167
166
|
handleSort: sort => {
|
|
168
167
|
const changeData = _objectSpread(_objectSpread({}, finalFilters), {}, {
|
|
@@ -239,8 +238,9 @@ function FilterProvider(_ref) {
|
|
|
239
238
|
|
|
240
239
|
return (blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$owner = blocklet.owner) === null || _blocklet$owner === void 0 ? void 0 : _blocklet$owner.did) === finalFilters.owner;
|
|
241
240
|
})) === 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) || '';
|
|
242
|
-
}
|
|
241
|
+
},
|
|
243
242
|
|
|
243
|
+
handleSearchSelect: onSearchSelect
|
|
244
244
|
};
|
|
245
245
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
|
|
246
246
|
value: filterStore,
|
package/lib/libs/prop-types.js
CHANGED
|
@@ -22,15 +22,20 @@ const propTypes = {
|
|
|
22
22
|
endpoint: _propTypes.default.string.isRequired,
|
|
23
23
|
blockletRender: _propTypes.default.func.isRequired,
|
|
24
24
|
onFilterChange: _propTypes.default.func,
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
onSearchSelect: _propTypes.default.func,
|
|
26
|
+
locale: _propTypes.default.oneOf(['zh', 'en'])
|
|
27
27
|
};
|
|
28
28
|
exports.propTypes = propTypes;
|
|
29
29
|
const defaultProps = {
|
|
30
30
|
locale: 'zh',
|
|
31
31
|
filters: {},
|
|
32
32
|
onFilterChange: () => {},
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
onSearchSelect: _ref => {
|
|
34
|
+
let {
|
|
35
|
+
detailUrl
|
|
36
|
+
} = _ref;
|
|
37
|
+
window.location.href = detailUrl;
|
|
38
|
+
},
|
|
39
|
+
extraFilter: list => list
|
|
35
40
|
};
|
|
36
41
|
exports.defaultProps = defaultProps;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/list",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.20",
|
|
4
4
|
"description": "Common ux components of blocklet",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"eslint": "^8.22.0",
|
|
69
69
|
"prettier": "^2.7.1"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "7e8a387a49a0f0164bcd39ff938372bd1d5d113d"
|
|
72
72
|
}
|
package/src/base.js
CHANGED
|
@@ -21,6 +21,7 @@ function ListBase() {
|
|
|
21
21
|
handleSort,
|
|
22
22
|
handleCategory,
|
|
23
23
|
handlePrice,
|
|
24
|
+
handleSearchSelect,
|
|
24
25
|
t,
|
|
25
26
|
getCategoryLocale,
|
|
26
27
|
priceOptions,
|
|
@@ -38,7 +39,7 @@ function ListBase() {
|
|
|
38
39
|
<StyledMin>
|
|
39
40
|
<FilterContainer>
|
|
40
41
|
<Box className="filter-bar" display="flex" alignItems="center">
|
|
41
|
-
<Autocomplete />
|
|
42
|
+
<Autocomplete onSelect={handleSearchSelect} />
|
|
42
43
|
<Box mt={0} ml="16px" className="filter-container">
|
|
43
44
|
<Hidden mdUp>
|
|
44
45
|
{/* 小屏幕下类别 */}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createElement, Fragment, useEffect, useRef, useCallback } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
2
3
|
import { createRoot } from 'react-dom/client';
|
|
3
4
|
import { autocomplete } from '@algolia/autocomplete-js';
|
|
4
5
|
|
|
@@ -11,11 +12,11 @@ import { debounced } from '../../libs/utils';
|
|
|
11
12
|
import { useFilterContext } from '../../contexts/filter';
|
|
12
13
|
import Blocklet from './item';
|
|
13
14
|
|
|
14
|
-
export default function Autocomplete() {
|
|
15
|
+
export default function Autocomplete({ onSelect }) {
|
|
15
16
|
const containerRef = useRef(null);
|
|
16
17
|
const panelRootRef = useRef(null);
|
|
17
18
|
const rootRef = useRef(null);
|
|
18
|
-
const { storeApi, filters, endpoint, handleKeyword, t
|
|
19
|
+
const { storeApi, filters, endpoint, handleKeyword, t } = useFilterContext();
|
|
19
20
|
const muiTheme = useTheme();
|
|
20
21
|
|
|
21
22
|
const getResults = useCallback(
|
|
@@ -27,20 +28,6 @@ export default function Autocomplete() {
|
|
|
27
28
|
[storeApi]
|
|
28
29
|
);
|
|
29
30
|
|
|
30
|
-
const getBlockletDetail = useCallback(
|
|
31
|
-
(item) => {
|
|
32
|
-
let blockletDetail = joinUrl(endpoint, `/blocklets/${item.did}`);
|
|
33
|
-
if (serverUrl) {
|
|
34
|
-
blockletDetail = `${blockletDetail}?server-url=${encodeURIComponent(serverUrl)}`;
|
|
35
|
-
}
|
|
36
|
-
return blockletDetail;
|
|
37
|
-
},
|
|
38
|
-
[endpoint, serverUrl]
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const onClickItem = (detailUrl) => {
|
|
42
|
-
window.location.href = detailUrl;
|
|
43
|
-
};
|
|
44
31
|
const onSubmit = useCallback(
|
|
45
32
|
(e) => {
|
|
46
33
|
handleKeyword(e.state.query);
|
|
@@ -100,15 +87,13 @@ export default function Autocomplete() {
|
|
|
100
87
|
getItemInputValue({ item }) {
|
|
101
88
|
return item.title;
|
|
102
89
|
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return blockletDetail;
|
|
90
|
+
onSelect({ item }) {
|
|
91
|
+
onSelect({ blocklet: item, detailUrl: joinUrl(endpoint, `/blocklets/${item.did}`), storeUrl: endpoint });
|
|
106
92
|
},
|
|
107
93
|
templates: {
|
|
108
94
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
109
95
|
item({ item }) {
|
|
110
96
|
const logoUrl = item.logo ? joinUrl(endpoint, 'assets', item.did, item.logo) : null;
|
|
111
|
-
const blockletDetail = getBlockletDetail(item);
|
|
112
97
|
return (
|
|
113
98
|
<MuiThemeProvider theme={muiTheme}>
|
|
114
99
|
<EmotionThemeProvider theme={muiTheme}>
|
|
@@ -118,7 +103,6 @@ export default function Autocomplete() {
|
|
|
118
103
|
did={item.did}
|
|
119
104
|
description={item.description}
|
|
120
105
|
cover={logoUrl}
|
|
121
|
-
onMainClick={() => onClickItem(blockletDetail)}
|
|
122
106
|
/>
|
|
123
107
|
</EmotionThemeProvider>
|
|
124
108
|
</MuiThemeProvider>
|
|
@@ -136,7 +120,11 @@ export default function Autocomplete() {
|
|
|
136
120
|
return () => {
|
|
137
121
|
search.destroy();
|
|
138
122
|
};
|
|
139
|
-
}, [endpoint, filters,
|
|
123
|
+
}, [endpoint, filters, getResults, muiTheme, onReset, onSubmit, onSelect, t]);
|
|
140
124
|
|
|
141
125
|
return <div className="bl-search-container" ref={containerRef} />;
|
|
142
126
|
}
|
|
127
|
+
|
|
128
|
+
Autocomplete.propTypes = {
|
|
129
|
+
onSelect: PropTypes.func.isRequired,
|
|
130
|
+
};
|
|
@@ -60,26 +60,12 @@ const Div = styled.div`
|
|
|
60
60
|
}
|
|
61
61
|
`;
|
|
62
62
|
|
|
63
|
-
export default function Blocklet({ cover,
|
|
64
|
-
const wrapHandler =
|
|
65
|
-
(handler, stopFn = () => false) =>
|
|
66
|
-
(e, ...args) => {
|
|
67
|
-
if (stopFn()) {
|
|
68
|
-
e.preventDefault();
|
|
69
|
-
e.stopPropagation();
|
|
70
|
-
} else if (handler instanceof Function) {
|
|
71
|
-
e.preventDefault();
|
|
72
|
-
e.stopPropagation();
|
|
73
|
-
handler(...args);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const _onMainClick = wrapHandler(onMainClick);
|
|
63
|
+
export default function Blocklet({ cover, item, className, ...rest }) {
|
|
77
64
|
const { did, description, title, name } = item;
|
|
78
|
-
const blockletTitle = title || name;
|
|
79
65
|
|
|
80
66
|
return (
|
|
81
67
|
<Div className={`${className} arcblock-blocklet`} {...rest}>
|
|
82
|
-
<div className="arcblock-blocklet__content"
|
|
68
|
+
<div className="arcblock-blocklet__content">
|
|
83
69
|
{cover ? (
|
|
84
70
|
<div className="arcblock-blocklet__cover">
|
|
85
71
|
<Img src={cover} />
|
|
@@ -94,7 +80,7 @@ export default function Blocklet({ cover, onMainClick, item, className, ...rest
|
|
|
94
80
|
<div className="arcblock-blocklet__info">
|
|
95
81
|
<div className="arcblock-blocklet__text">
|
|
96
82
|
<Typography component="h3" variant="h3" className="arcblock-blocklet__title" title={title}>
|
|
97
|
-
<ShowAttributes item={item} attribute="title" value={
|
|
83
|
+
<ShowAttributes item={item} attribute="title" value={title || name} />
|
|
98
84
|
</Typography>
|
|
99
85
|
{description && (
|
|
100
86
|
<Typography component="div" variant="body2" className="arcblock-blocklet__describe" title={description}>
|
|
@@ -110,21 +96,21 @@ export default function Blocklet({ cover, onMainClick, item, className, ...rest
|
|
|
110
96
|
|
|
111
97
|
Blocklet.propTypes = {
|
|
112
98
|
cover: PropTypes.string,
|
|
113
|
-
onMainClick: PropTypes.func,
|
|
114
99
|
className: PropTypes.string,
|
|
115
100
|
item: PropTypes.object.isRequired,
|
|
116
101
|
};
|
|
117
102
|
|
|
118
103
|
Blocklet.defaultProps = {
|
|
119
104
|
cover: null,
|
|
120
|
-
onMainClick: null,
|
|
121
105
|
className: null,
|
|
122
106
|
};
|
|
123
107
|
|
|
124
108
|
function ShowAttributes({ item, attribute, value }) {
|
|
125
|
-
|
|
126
|
-
|
|
109
|
+
if (item._formatted) {
|
|
110
|
+
// eslint-disable-next-line react/no-danger
|
|
127
111
|
return <span data-cy="bl-autocomplete-item" dangerouslySetInnerHTML={{ __html: item._formatted[attribute] }} />;
|
|
112
|
+
}
|
|
113
|
+
|
|
128
114
|
return value;
|
|
129
115
|
}
|
|
130
116
|
ShowAttributes.propTypes = {
|
package/src/contexts/filter.js
CHANGED
|
@@ -18,8 +18,8 @@ function FilterProvider({
|
|
|
18
18
|
locale,
|
|
19
19
|
blockletRender,
|
|
20
20
|
onFilterChange,
|
|
21
|
+
onSearchSelect,
|
|
21
22
|
extraFilter,
|
|
22
|
-
serverUrl,
|
|
23
23
|
}) {
|
|
24
24
|
const storeApi = axios.create({
|
|
25
25
|
baseURL: endpoint,
|
|
@@ -72,7 +72,7 @@ function FilterProvider({
|
|
|
72
72
|
} = useRequest(
|
|
73
73
|
async () => {
|
|
74
74
|
const { data } = await storeApi.get(constant.categoriesPath);
|
|
75
|
-
return data;
|
|
75
|
+
return Array.isArray(data) ? data : [];
|
|
76
76
|
},
|
|
77
77
|
{ initialData: [] }
|
|
78
78
|
);
|
|
@@ -114,7 +114,6 @@ function FilterProvider({
|
|
|
114
114
|
categoryOptions,
|
|
115
115
|
priceOptions,
|
|
116
116
|
storeApi,
|
|
117
|
-
serverUrl,
|
|
118
117
|
hasNextPage: blockletsState.list.length < blockletsState.total,
|
|
119
118
|
handleSort: (sort) => {
|
|
120
119
|
const changeData = {
|
|
@@ -169,6 +168,7 @@ function FilterProvider({
|
|
|
169
168
|
const blocklets = blockletList;
|
|
170
169
|
return blocklets.find((blocklet) => blocklet?.owner?.did === finalFilters.owner)?.owner?.name || '';
|
|
171
170
|
},
|
|
171
|
+
handleSearchSelect: onSearchSelect,
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
return <Provider value={filterStore}>{children}</Provider>;
|
package/src/libs/prop-types.js
CHANGED
|
@@ -13,16 +13,18 @@ const propTypes = {
|
|
|
13
13
|
endpoint: PropTypes.string.isRequired,
|
|
14
14
|
blockletRender: PropTypes.func.isRequired,
|
|
15
15
|
onFilterChange: PropTypes.func,
|
|
16
|
+
onSearchSelect: PropTypes.func,
|
|
16
17
|
locale: PropTypes.oneOf(['zh', 'en']),
|
|
17
|
-
serverUrl: PropTypes.string,
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const defaultProps = {
|
|
21
21
|
locale: 'zh',
|
|
22
22
|
filters: {},
|
|
23
23
|
onFilterChange: () => {},
|
|
24
|
+
onSearchSelect: ({ detailUrl }) => {
|
|
25
|
+
window.location.href = detailUrl;
|
|
26
|
+
},
|
|
24
27
|
extraFilter: (list) => list,
|
|
25
|
-
serverUrl: null,
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
export { propTypes, defaultProps };
|