55
55
</v-row >
56
56
<v-row justify =" center" v-else class =" card-wrapper" >
57
57
<BallotCard
58
- v-for =" (item, i) in pageData.items"
58
+ v-for =" (item, i) in pageData.items[pageData.page - 1] "
59
59
:key =" i"
60
60
v-bind =" item"
61
61
:is-voting-disabled =" isVotingDisabled"
66
66
<v-pagination
67
67
v-model =" pageData.page"
68
68
:length =" pageData.totalPages"
69
+ @input =" nextPageOnClick"
69
70
circle
70
71
></v-pagination >
71
72
</v-row >
@@ -106,13 +107,13 @@ export default {
106
107
item: null ,
107
108
per: 10 ,
108
109
pageData: {
109
- hasNext: false ,
110
- hasPrev: false ,
111
- nextNum: false ,
110
+ // hasNext: false,
111
+ // hasPrev: false,
112
+ // nextNum: false,
112
113
page: - 1 ,
113
114
items: [],
114
- prevNum: null ,
115
- totalItems: 0 ,
115
+ // prevNum: null,
116
+ // totalItems: 0,
116
117
totalPages: 0
117
118
}
118
119
};
@@ -122,6 +123,10 @@ export default {
122
123
this .item = item;
123
124
this .showModal = true ;
124
125
},
126
+ nextPageOnClick (page ) {
127
+ Vue .set (this .pageData , " page" , page);
128
+ this .updateQueryParams ();
129
+ },
125
130
async setResult (result ) {
126
131
await new Promise (resolve => {
127
132
setTimeout (async () => {
@@ -133,12 +138,22 @@ export default {
133
138
shuffled = this .shuffle (result .items );
134
139
}
135
140
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 ));
140
145
}
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);
142
157
await this .updateQueryParams ();
143
158
resolve ();
144
159
}, 1000 );
@@ -148,17 +163,13 @@ export default {
148
163
if (this .searchText === " " ) {
149
164
return this .loadPage ();
150
165
}
151
- this .pageData .page = 1 ;
166
+ // this.pageData.page = 1;
152
167
this .requestIndex ++ ;
153
168
this .requestCount ++ ;
154
169
const requestIndex = this .requestIndex ;
155
170
const searchText = this .searchText ;
156
171
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 );
162
173
if (
163
174
this .searchText === searchText &&
164
175
this .requestIndex === requestIndex
@@ -183,7 +194,7 @@ export default {
183
194
async loadPage () {
184
195
this .requestCount ++ ;
185
196
try {
186
- const results = await voting .getBallot (this . pageData . page , this . per );
197
+ const results = await voting .getBallot (1 , 2000 );
187
198
await this .setResult (results);
188
199
} catch (err) {
189
200
if (err .status === 404 ) {
@@ -242,18 +253,18 @@ export default {
242
253
watch: {
243
254
searchText () {
244
255
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 ();
256
256
}
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
+ // }
257
268
},
258
269
async mounted () {
259
270
this .searchText =
@@ -262,6 +273,8 @@ export default {
262
273
this .$route .query .page === undefined
263
274
? 1
264
275
: parseInt (this .$route .query .page );
276
+
277
+ this .refresh ();
265
278
}
266
279
};
267
280
</script >
0 commit comments