Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit e602c98

Browse files
update VoteLeaderboardSearch to shuffle on empty string, update pagination component and local state to reflect this
1 parent 432cf1d commit e602c98

File tree

1 file changed

+42
-29
lines changed

1 file changed

+42
-29
lines changed

src/components/VoteLeaderboardSearch.vue

+42-29
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</v-row>
5656
<v-row justify="center" v-else class="card-wrapper">
5757
<BallotCard
58-
v-for="(item, i) in pageData.items"
58+
v-for="(item, i) in pageData.items[pageData.page - 1]"
5959
:key="i"
6060
v-bind="item"
6161
:is-voting-disabled="isVotingDisabled"
@@ -66,6 +66,7 @@
6666
<v-pagination
6767
v-model="pageData.page"
6868
:length="pageData.totalPages"
69+
@input="nextPageOnClick"
6970
circle
7071
></v-pagination>
7172
</v-row>
@@ -106,13 +107,13 @@ export default {
106107
item: null,
107108
per: 10,
108109
pageData: {
109-
hasNext: false,
110-
hasPrev: false,
111-
nextNum: false,
110+
// hasNext: false,
111+
// hasPrev: false,
112+
// nextNum: false,
112113
page: -1,
113114
items: [],
114-
prevNum: null,
115-
totalItems: 0,
115+
// prevNum: null,
116+
// totalItems: 0,
116117
totalPages: 0
117118
}
118119
};
@@ -122,6 +123,10 @@ export default {
122123
this.item = item;
123124
this.showModal = true;
124125
},
126+
nextPageOnClick(page) {
127+
Vue.set(this.pageData, "page", page);
128+
this.updateQueryParams();
129+
},
125130
async setResult(result) {
126131
await new Promise(resolve => {
127132
setTimeout(async () => {
@@ -133,12 +138,22 @@ export default {
133138
shuffled = this.shuffle(result.items);
134139
}
135140
136-
for (const [key, value] of Object.entries(result)) {
137-
if (key !== "items") {
138-
Vue.set(this.pageData, key, value);
139-
}
141+
// push into sub arrays
142+
let postShuffled = [];
143+
while (shuffled.length > 0) {
144+
postShuffled.push(shuffled.splice(0, 10));
140145
}
141-
Vue.set(this.pageData, "items", shuffled);
146+
147+
// set data
148+
Vue.set(this.pageData, "items", postShuffled);
149+
Vue.set(this.pageData, "totalPages", this.pageData.items.length);
150+
151+
// for (const [key, value] of Object.entries(result)) {
152+
// if (key !== "items") {
153+
// Vue.set(this.pageData, key, value);
154+
// }
155+
// }
156+
// Vue.set(this.pageData, "items", shuffled);
142157
await this.updateQueryParams();
143158
resolve();
144159
}, 1000);
@@ -148,17 +163,13 @@ export default {
148163
if (this.searchText === "") {
149164
return this.loadPage();
150165
}
151-
this.pageData.page = 1;
166+
// this.pageData.page = 1;
152167
this.requestIndex++;
153168
this.requestCount++;
154169
const requestIndex = this.requestIndex;
155170
const searchText = this.searchText;
156171
try {
157-
const results = await voting.search(
158-
this.searchText,
159-
this.pageData.page,
160-
this.per
161-
);
172+
const results = await voting.search(this.searchText, 1, 2000);
162173
if (
163174
this.searchText === searchText &&
164175
this.requestIndex === requestIndex
@@ -183,7 +194,7 @@ export default {
183194
async loadPage() {
184195
this.requestCount++;
185196
try {
186-
const results = await voting.getBallot(this.pageData.page, this.per);
197+
const results = await voting.getBallot(1, 2000);
187198
await this.setResult(results);
188199
} catch (err) {
189200
if (err.status === 404) {
@@ -242,18 +253,18 @@ export default {
242253
watch: {
243254
searchText() {
244255
this.search();
245-
},
246-
["pageData.page"]() {
247-
this.refresh();
248-
},
249-
["$route.query.page"](val) {
250-
const page = parseInt(val);
251-
if (this.pageData.page === page) {
252-
return;
253-
}
254-
this.pageData.page = page;
255-
this.refresh();
256256
}
257+
// ["pageData.page"]() {
258+
// this.refresh();
259+
// },
260+
// ["$route.query.page"](val) {
261+
// const page = parseInt(val);
262+
// if (this.pageData.page === page) {
263+
// return;
264+
// }
265+
// this.pageData.page = page;
266+
// this.refresh();
267+
// }
257268
},
258269
async mounted() {
259270
this.searchText =
@@ -262,6 +273,8 @@ export default {
262273
this.$route.query.page === undefined
263274
? 1
264275
: parseInt(this.$route.query.page);
276+
277+
this.refresh();
265278
}
266279
};
267280
</script>

0 commit comments

Comments
 (0)