Skip to content

Commit 52e6a15

Browse files
committed
feat(website): remember sort-by option value for the package list
1 parent 2ad375a commit 52e6a15

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

docs/.vuepress/theme/common.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Common
2+
3+
const SortType = {
4+
name: "name",
5+
pop: "pop",
6+
createdAt: "createdAt",
7+
updatedAt: "updatedAt"
8+
};
9+
10+
export default {
11+
SortType
12+
};

docs/.vuepress/theme/layouts/PackageList.vue

+15-11
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,13 @@ import { reverse, uniq } from "lodash/array";
143143
import { trim } from "lodash/string";
144144

145145
import AppLayout from "@theme/layouts/AppLayout.vue";
146+
import common from "@theme/common";
146147
import LazyPackageCard from "@theme/components/LazyPackageCard.vue";
147148
import NavLink from "@theme/components/NavLink.vue";
148149
import PackageLayoutControl from "@theme/components/PackageLayoutControl.vue";
149150
import util from "@root/docs/.vuepress/util";
150151

151-
const SortType = {
152-
name: "name",
153-
pop: "pop",
154-
createdAt: "createdAt",
155-
updatedAt: "updatedAt"
156-
};
152+
const SortType = common.SortType;
157153

158154
export default {
159155
components: {
@@ -167,7 +163,6 @@ export default {
167163
return {
168164
active: true,
169165
topicValue: "",
170-
sort: SortType.updatedAt,
171166
sortList: [
172167
{ text: "Name", value: SortType.name },
173168
{ text: "Popularity", value: SortType.pop },
@@ -247,8 +242,13 @@ export default {
247242
return query;
248243
},
249244

250-
stateText() {
251-
return this.active ? "Ready to Use" : "Pending";
245+
sort: {
246+
get() {
247+
return this.$store.getters.packageListSort;
248+
},
249+
set(value) {
250+
this.$store.dispatch("setPackageListSort", { value });
251+
}
252252
},
253253

254254
sortOptions() {
@@ -261,6 +261,10 @@ export default {
261261
});
262262
},
263263

264+
stateText() {
265+
return this.active ? "Ready to Use" : "Pending";
266+
},
267+
264268
timeField() {
265269
if (this.sort == SortType.createdAt) {
266270
return SortType.createdAt;
@@ -331,8 +335,8 @@ export default {
331335
this.active = this.$route.query.active != "0";
332336
// sort
333337
const sort = this.$route.query.sort;
334-
if (this.sortList.map(x => x.value).includes(sort)) this.sort = sort;
335-
else this.sort = SortType.updatedAt;
338+
if (this.sortList.map(x => x.value).includes(sort) && sort != this.sort)
339+
this.$store.dispatch("setPackageListSort", { value: sort });
336340
// unity
337341
const unity = this.$route.query.unity;
338342
if (this.unityOptions.map(x => x.value).includes(unity))

docs/.vuepress/theme/store.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import axios from "axios";
22
import createPersistedState from "vuex-persistedstate";
33
import urljoin from "url-join";
4-
import util from "@root/docs/.vuepress/util";
54
import Vue from "vue";
65
import Vuex from "vuex";
76

7+
import common from "@theme/common";
8+
import util from "@root/docs/.vuepress/util";
9+
10+
const SortType = common.SortType;
11+
812
Vue.use(Vuex);
913

1014
let _store = null;
@@ -21,13 +25,15 @@ export function getStore(isServer) {
2125
packagesExtra: [],
2226
recentPackages: [],
2327
preferHorizontalLayout: false,
24-
siteInfo: {}
28+
siteInfo: {},
29+
packageListSort: SortType.updatedAt
2530
},
2631
getters: {
2732
packagesExtra: state => state.packagesExtra,
2833
recentPackages: state => state.recentPackages,
2934
preferHorizontalLayout: state => state.preferHorizontalLayout,
30-
siteInfo: state => state.siteInfo
35+
siteInfo: state => state.siteInfo,
36+
packageListSort: state => state.packageListSort
3137
},
3238
actions: {
3339
async fetchPackagesExtra({ commit }) {
@@ -73,6 +79,9 @@ export function getStore(isServer) {
7379
},
7480
setPreferHorizontalLayout({ commit }, { value }) {
7581
commit("setPreferHorizontalLayout", value);
82+
},
83+
setPackageListSort({ commit }, { value }) {
84+
commit("setPackageListSort", value);
7685
}
7786
},
7887
mutations: {
@@ -87,6 +96,9 @@ export function getStore(isServer) {
8796
},
8897
setPreferHorizontalLayout: (state, preferHorizontalLayout) => {
8998
state.preferHorizontalLayout = preferHorizontalLayout;
99+
},
100+
setPackageListSort: (state, packageListSort) => {
101+
state.packageListSort = packageListSort;
90102
}
91103
}
92104
});

0 commit comments

Comments
 (0)