@blocklet/list 0.8.22 → 0.8.25
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/aside.js +1 -1
- package/lib/components/filter/group.js +1 -1
- package/lib/components/filter/icon.js +1 -1
- package/lib/contexts/filter.js +35 -34
- package/package.json +3 -3
- package/src/components/aside.js +1 -1
- package/src/components/filter/group.js +4 -3
- package/src/components/filter/icon.js +1 -1
- package/src/contexts/filter.js +26 -26
package/lib/components/aside.js
CHANGED
|
@@ -32,7 +32,7 @@ const Aside = () => {
|
|
|
32
32
|
onChange: handlePrice
|
|
33
33
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
34
34
|
style: {
|
|
35
|
-
marginTop: '
|
|
35
|
+
marginTop: '16px'
|
|
36
36
|
}
|
|
37
37
|
}, /*#__PURE__*/_react.default.createElement(_filter2.FilterGroup, {
|
|
38
38
|
title: t('common.category'),
|
|
@@ -38,7 +38,7 @@ function FilterGroup(_ref) {
|
|
|
38
38
|
const StyledDiv = _styledComponents.default.div.withConfig({
|
|
39
39
|
displayName: "group__StyledDiv",
|
|
40
40
|
componentId: "sc-1lj02tr-0"
|
|
41
|
-
})([".title{font-size:18px;font-weight:bold;margin-bottom:", ";}.list{}.item{font-size:16px;
|
|
41
|
+
})([".title{font-size:18px;font-weight:bold;margin-bottom:", ";}.list{}.item{font-size:16px;padding:", ";color:#9397a1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-transform:capitalize;cursor:pointer;&:hover{background-color:", ";color:initial;font-weight:bold;}}.select{color:", ";font-weight:bold;}"], props => props.theme.spacing(1), props => props.theme.spacing(1), props => props.theme.palette.grey[50], props => props.theme.palette.primary.main);
|
|
42
42
|
|
|
43
43
|
FilterGroup.propTypes = {
|
|
44
44
|
title: _propTypes.default.string.isRequired,
|
package/lib/contexts/filter.js
CHANGED
|
@@ -85,15 +85,21 @@ function FilterProvider(_ref) {
|
|
|
85
85
|
initialData: [],
|
|
86
86
|
manual: true
|
|
87
87
|
});
|
|
88
|
-
|
|
89
|
-
const
|
|
88
|
+
|
|
89
|
+
const finalFilters = _objectSpread({
|
|
90
|
+
sortBy: 'popularity',
|
|
91
|
+
sortDirection: 'desc'
|
|
92
|
+
}, filters);
|
|
93
|
+
|
|
94
|
+
const selectedCategory = finalFilters.category;
|
|
95
|
+
const hasDeveloperFilter = !!finalFilters.developer;
|
|
90
96
|
const categoryState = (0, _react.useMemo)(() => {
|
|
91
97
|
return !hasDeveloperFilter ? {
|
|
92
98
|
data: allCategories
|
|
93
|
-
} : (0, _utils.getCategories)(allBlocklets,
|
|
99
|
+
} : (0, _utils.getCategories)(allBlocklets, finalFilters.developer);
|
|
94
100
|
}, [hasDeveloperFilter, allCategories]);
|
|
95
101
|
const blockletList = (0, _react.useMemo)(() => {
|
|
96
|
-
var
|
|
102
|
+
var _finalFilters$keyword;
|
|
97
103
|
|
|
98
104
|
const sortByName = x => {
|
|
99
105
|
var _x$title, _x$name;
|
|
@@ -114,27 +120,27 @@ function FilterProvider(_ref) {
|
|
|
114
120
|
popularity: sortByPopularity,
|
|
115
121
|
publishAt: sortByPublish
|
|
116
122
|
};
|
|
117
|
-
let
|
|
123
|
+
let blocklets = allBlocklets || []; // 按照付费/免费筛选
|
|
118
124
|
|
|
119
|
-
|
|
125
|
+
blocklets = (0, _utils.filterBlockletByPrice)(blocklets, finalFilters.price); // 按照分类筛选
|
|
120
126
|
|
|
121
|
-
|
|
127
|
+
blocklets = blocklets.filter(item => {
|
|
122
128
|
var _item$category;
|
|
123
129
|
|
|
124
130
|
return selectedCategory ? (item === null || item === void 0 ? void 0 : (_item$category = item.category) === null || _item$category === void 0 ? void 0 : _item$category.name) === selectedCategory : true;
|
|
125
131
|
}); // 按照作者筛选
|
|
126
132
|
|
|
127
|
-
|
|
128
|
-
const lowerSearch = (
|
|
133
|
+
blocklets = blocklets.filter(item => finalFilters !== null && finalFilters !== void 0 && finalFilters.developer ? item.owner.did === finalFilters.developer : true);
|
|
134
|
+
const lowerSearch = (finalFilters === null || finalFilters === void 0 ? void 0 : (_finalFilters$keyword = finalFilters.keyword) === null || _finalFilters$keyword === void 0 ? void 0 : _finalFilters$keyword.toLocaleLowerCase()) || ''; // 按照搜索筛选
|
|
129
135
|
|
|
130
|
-
|
|
136
|
+
blocklets = blocklets.filter(item => {
|
|
131
137
|
var _ref2, _item$description, _item$version;
|
|
132
138
|
|
|
133
139
|
return ((_ref2 = (item === null || item === void 0 ? void 0 : item.title) || (item === null || item === void 0 ? void 0 : item.name)) === null || _ref2 === void 0 ? void 0 : _ref2.toLocaleLowerCase().includes(lowerSearch)) || ((_item$description = item.description) === null || _item$description === void 0 ? void 0 : _item$description.toLocaleLowerCase().includes(lowerSearch)) || (item === null || item === void 0 ? void 0 : (_item$version = item.version) === null || _item$version === void 0 ? void 0 : _item$version.toLocaleLowerCase().includes(lowerSearch));
|
|
134
140
|
}); // 排序
|
|
135
141
|
|
|
136
|
-
return (0, _orderBy.default)(
|
|
137
|
-
}, [allBlocklets,
|
|
142
|
+
return (0, _orderBy.default)(blocklets, [sortMap[finalFilters.sortBy]], [finalFilters.sortDirection]);
|
|
143
|
+
}, [allBlocklets, finalFilters]);
|
|
138
144
|
const categoryList = (0, _react.useMemo)(() => {
|
|
139
145
|
const list = categoryState.data || []; // 分类按照名称排序
|
|
140
146
|
|
|
@@ -164,10 +170,7 @@ function FilterProvider(_ref) {
|
|
|
164
170
|
endpoint,
|
|
165
171
|
blockletList,
|
|
166
172
|
t: translate,
|
|
167
|
-
filters:
|
|
168
|
-
sortBy: 'popularity',
|
|
169
|
-
sortDirection: 'desc'
|
|
170
|
-
}, filters),
|
|
173
|
+
filters: finalFilters,
|
|
171
174
|
selectedCategory,
|
|
172
175
|
categoryList,
|
|
173
176
|
baseUrl,
|
|
@@ -176,7 +179,7 @@ function FilterProvider(_ref) {
|
|
|
176
179
|
categoryOptions,
|
|
177
180
|
priceOptions,
|
|
178
181
|
handleSort: sort => {
|
|
179
|
-
const changeData = _objectSpread(_objectSpread({},
|
|
182
|
+
const changeData = _objectSpread(_objectSpread({}, finalFilters), {}, {
|
|
180
183
|
sortBy: sort,
|
|
181
184
|
sortDirection: sort === 'nameAsc' ? 'asc' : 'desc'
|
|
182
185
|
});
|
|
@@ -184,36 +187,34 @@ function FilterProvider(_ref) {
|
|
|
184
187
|
onFilterChange(changeData);
|
|
185
188
|
},
|
|
186
189
|
handleKeyword: keyWord => {
|
|
187
|
-
const changeData = _objectSpread(_objectSpread({},
|
|
190
|
+
const changeData = _objectSpread(_objectSpread({}, finalFilters), {}, {
|
|
188
191
|
keyword: keyWord || undefined
|
|
189
192
|
});
|
|
190
193
|
|
|
191
194
|
onFilterChange(changeData);
|
|
192
195
|
},
|
|
193
196
|
handlePrice: price => {
|
|
194
|
-
const changeData = _objectSpread(_objectSpread({},
|
|
195
|
-
price: price ===
|
|
197
|
+
const changeData = _objectSpread(_objectSpread({}, finalFilters), {}, {
|
|
198
|
+
price: price === finalFilters.price ? undefined : price
|
|
196
199
|
});
|
|
197
200
|
|
|
198
201
|
onFilterChange(changeData);
|
|
199
202
|
},
|
|
200
203
|
handleCategory: category => {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
onFilterChange(changeData);
|
|
207
|
-
} else {
|
|
208
|
-
const changeData = _objectSpread(_objectSpread({}, filters), {}, {
|
|
209
|
-
category: category === filters.category ? undefined : category
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
onFilterChange(changeData);
|
|
204
|
+
let finalCategory = category;
|
|
205
|
+
|
|
206
|
+
if (category === 'all' || category === finalFilters.category) {
|
|
207
|
+
finalCategory = undefined;
|
|
213
208
|
}
|
|
209
|
+
|
|
210
|
+
const changeData = _objectSpread(_objectSpread({}, finalFilters), {}, {
|
|
211
|
+
category: finalCategory
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
onFilterChange(changeData);
|
|
214
215
|
},
|
|
215
216
|
handleDeveloper: developer => {
|
|
216
|
-
const changeData = _objectSpread(_objectSpread({},
|
|
217
|
+
const changeData = _objectSpread(_objectSpread({}, finalFilters), {}, {
|
|
217
218
|
developer: developer || undefined
|
|
218
219
|
});
|
|
219
220
|
|
|
@@ -234,7 +235,7 @@ function FilterProvider(_ref) {
|
|
|
234
235
|
get developerName() {
|
|
235
236
|
var _allBlocklets$find, _allBlocklets$find$ow;
|
|
236
237
|
|
|
237
|
-
return ((_allBlocklets$find = allBlocklets.find(
|
|
238
|
+
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) || '';
|
|
238
239
|
}
|
|
239
240
|
|
|
240
241
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/list",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.25",
|
|
4
4
|
"description": "Common ux components of blocklet",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"react": ">=18.1.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@arcblock/ux": "^2.1.
|
|
40
|
+
"@arcblock/ux": "^2.1.7",
|
|
41
41
|
"@emotion/react": "^11.9.0",
|
|
42
42
|
"@emotion/styled": "^11.8.1",
|
|
43
43
|
"@mui/icons-material": "^5.6.2",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"babel-plugin-inline-react-svg": "^2.0.1",
|
|
59
59
|
"babel-plugin-styled-components": "^1.10.7"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "303ef1bcac78a377b26b5992cce688cad2318bf2"
|
|
62
62
|
}
|
package/src/components/aside.js
CHANGED
|
@@ -13,7 +13,7 @@ const Aside = () => {
|
|
|
13
13
|
<div>
|
|
14
14
|
<FilterGroup title={t('common.price')} options={priceOptions} value={filters.price} onChange={handlePrice} />
|
|
15
15
|
</div>
|
|
16
|
-
<div style={{ marginTop: '
|
|
16
|
+
<div style={{ marginTop: '16px' }}>
|
|
17
17
|
<FilterGroup
|
|
18
18
|
title={t('common.category')}
|
|
19
19
|
options={categoryOptions}
|
|
@@ -28,14 +28,13 @@ const StyledDiv = styled.div`
|
|
|
28
28
|
.title {
|
|
29
29
|
font-size: 18px;
|
|
30
30
|
font-weight: bold;
|
|
31
|
-
margin-bottom: ${(props) => props.theme.spacing(
|
|
31
|
+
margin-bottom: ${(props) => props.theme.spacing(1)};
|
|
32
32
|
}
|
|
33
33
|
.list {
|
|
34
34
|
}
|
|
35
35
|
.item {
|
|
36
36
|
font-size: 16px;
|
|
37
|
-
|
|
38
|
-
padding: ${(props) => props.theme.spacing(2)} ${(props) => props.theme.spacing(1)};
|
|
37
|
+
padding: ${(props) => props.theme.spacing(1)};
|
|
39
38
|
color: #9397a1;
|
|
40
39
|
overflow: hidden;
|
|
41
40
|
text-overflow: ellipsis;
|
|
@@ -45,10 +44,12 @@ const StyledDiv = styled.div`
|
|
|
45
44
|
&:hover {
|
|
46
45
|
background-color: ${(props) => props.theme.palette.grey[50]};
|
|
47
46
|
color: initial;
|
|
47
|
+
font-weight: bold;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
.select {
|
|
51
51
|
color: ${(props) => props.theme.palette.primary.main};
|
|
52
|
+
font-weight: bold;
|
|
52
53
|
}
|
|
53
54
|
`;
|
|
54
55
|
|
package/src/contexts/filter.js
CHANGED
|
@@ -16,7 +16,6 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
|
|
|
16
16
|
const storeApi = axios.create({
|
|
17
17
|
baseURL: endpoint,
|
|
18
18
|
});
|
|
19
|
-
|
|
20
19
|
const {
|
|
21
20
|
data: allBlocklets,
|
|
22
21
|
error: fetchBlockletsError,
|
|
@@ -43,11 +42,11 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
|
|
|
43
42
|
{ initialData: [], manual: true }
|
|
44
43
|
);
|
|
45
44
|
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const hasDeveloperFilter = !!
|
|
45
|
+
const finalFilters = { sortBy: 'popularity', sortDirection: 'desc', ...filters };
|
|
46
|
+
const selectedCategory = finalFilters.category;
|
|
47
|
+
const hasDeveloperFilter = !!finalFilters.developer;
|
|
49
48
|
const categoryState = useMemo(() => {
|
|
50
|
-
return !hasDeveloperFilter ? { data: allCategories } : getCategories(allBlocklets,
|
|
49
|
+
return !hasDeveloperFilter ? { data: allCategories } : getCategories(allBlocklets, finalFilters.developer);
|
|
51
50
|
}, [hasDeveloperFilter, allCategories]);
|
|
52
51
|
|
|
53
52
|
const blockletList = useMemo(() => {
|
|
@@ -61,16 +60,18 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
|
|
|
61
60
|
publishAt: sortByPublish,
|
|
62
61
|
};
|
|
63
62
|
|
|
64
|
-
let
|
|
63
|
+
let blocklets = allBlocklets || [];
|
|
65
64
|
// 按照付费/免费筛选
|
|
66
|
-
|
|
65
|
+
blocklets = filterBlockletByPrice(blocklets, finalFilters.price);
|
|
67
66
|
// 按照分类筛选
|
|
68
|
-
|
|
67
|
+
blocklets = blocklets.filter((item) => (selectedCategory ? item?.category?.name === selectedCategory : true));
|
|
69
68
|
// 按照作者筛选
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
blocklets = blocklets.filter((item) =>
|
|
70
|
+
finalFilters?.developer ? item.owner.did === finalFilters.developer : true
|
|
71
|
+
);
|
|
72
|
+
const lowerSearch = finalFilters?.keyword?.toLocaleLowerCase() || '';
|
|
72
73
|
// 按照搜索筛选
|
|
73
|
-
|
|
74
|
+
blocklets = blocklets.filter((item) => {
|
|
74
75
|
return (
|
|
75
76
|
(item?.title || item?.name)?.toLocaleLowerCase().includes(lowerSearch) ||
|
|
76
77
|
item.description?.toLocaleLowerCase().includes(lowerSearch) ||
|
|
@@ -78,8 +79,8 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
|
|
|
78
79
|
);
|
|
79
80
|
});
|
|
80
81
|
// 排序
|
|
81
|
-
return orderBy(
|
|
82
|
-
}, [allBlocklets,
|
|
82
|
+
return orderBy(blocklets, [sortMap[finalFilters.sortBy]], [finalFilters.sortDirection]);
|
|
83
|
+
}, [allBlocklets, finalFilters]);
|
|
83
84
|
|
|
84
85
|
const categoryList = useMemo(() => {
|
|
85
86
|
const list = categoryState.data || [];
|
|
@@ -105,7 +106,7 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
|
|
|
105
106
|
endpoint,
|
|
106
107
|
blockletList,
|
|
107
108
|
t: translate,
|
|
108
|
-
filters:
|
|
109
|
+
filters: finalFilters,
|
|
109
110
|
selectedCategory,
|
|
110
111
|
categoryList,
|
|
111
112
|
baseUrl,
|
|
@@ -115,34 +116,33 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
|
|
|
115
116
|
priceOptions,
|
|
116
117
|
handleSort: (sort) => {
|
|
117
118
|
const changeData = {
|
|
118
|
-
...
|
|
119
|
+
...finalFilters,
|
|
119
120
|
sortBy: sort,
|
|
120
121
|
sortDirection: sort === 'nameAsc' ? 'asc' : 'desc',
|
|
121
122
|
};
|
|
122
123
|
onFilterChange(changeData);
|
|
123
124
|
},
|
|
124
125
|
handleKeyword: (keyWord) => {
|
|
125
|
-
const changeData = { ...
|
|
126
|
+
const changeData = { ...finalFilters, keyword: keyWord || undefined };
|
|
126
127
|
onFilterChange(changeData);
|
|
127
128
|
},
|
|
128
129
|
handlePrice: (price) => {
|
|
129
130
|
const changeData = {
|
|
130
|
-
...
|
|
131
|
-
price: price ===
|
|
131
|
+
...finalFilters,
|
|
132
|
+
price: price === finalFilters.price ? undefined : price,
|
|
132
133
|
};
|
|
133
134
|
onFilterChange(changeData);
|
|
134
135
|
},
|
|
135
136
|
handleCategory: (category) => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
} else {
|
|
140
|
-
const changeData = { ...filters, category: category === filters.category ? undefined : category };
|
|
141
|
-
onFilterChange(changeData);
|
|
137
|
+
let finalCategory = category;
|
|
138
|
+
if (category === 'all' || category === finalFilters.category) {
|
|
139
|
+
finalCategory = undefined;
|
|
142
140
|
}
|
|
141
|
+
const changeData = { ...finalFilters, category: finalCategory };
|
|
142
|
+
onFilterChange(changeData);
|
|
143
143
|
},
|
|
144
144
|
handleDeveloper: (developer) => {
|
|
145
|
-
const changeData = { ...
|
|
145
|
+
const changeData = { ...finalFilters, developer: developer || undefined };
|
|
146
146
|
onFilterChange(changeData);
|
|
147
147
|
},
|
|
148
148
|
getCategoryLocale: (category) => {
|
|
@@ -155,7 +155,7 @@ function FilterProvider({ filters, children, baseUrl, endpoint, locale, blocklet
|
|
|
155
155
|
return result;
|
|
156
156
|
},
|
|
157
157
|
get developerName() {
|
|
158
|
-
return allBlocklets.find((
|
|
158
|
+
return allBlocklets.find((blocklet) => blocklet.owner.did === finalFilters.developer)?.owner?.name || '';
|
|
159
159
|
},
|
|
160
160
|
};
|
|
161
161
|
|