This repository was archived by the owner on Dec 8, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +30
-4
lines changed Expand file tree Collapse file tree 1 file changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -123,15 +123,27 @@ export default {
123123 this .showModal = true ;
124124 },
125125 async setResult (result ) {
126- await new Promise (resolve =>
126+ await new Promise (resolve => {
127127 setTimeout (async () => {
128+ // shuffle the results if no search string given
129+ let shuffled;
130+ if (this .searchText .length > 0 ) {
131+ shuffled = result .items ;
132+ } else {
133+ shuffled = this .shuffle (result .items );
134+ }
135+
136+ console .log (" shuffled" , shuffled);
128137 for (const [key , value ] of Object .entries (result)) {
129- Vue .set (this .pageData , key, value);
138+ if (key !== " items" ) {
139+ Vue .set (this .pageData , key, value);
140+ }
130141 }
142+ Vue .set (this .pageData , " items" , shuffled);
131143 await this .updateQueryParams ();
132144 resolve ();
133- }, 1000 )
134- );
145+ }, 1000 );
146+ } );
135147 },
136148 async search () {
137149 if (this .searchText === " " ) {
@@ -207,6 +219,20 @@ export default {
207219 } else {
208220 this .search ();
209221 }
222+ },
223+ /**
224+ * Shuffles array in place.
225+ * @param {Array} a items An array containing the items.
226+ */
227+ shuffle (a ) {
228+ var j, x, i;
229+ for (i = a .length - 1 ; i > 0 ; i-- ) {
230+ j = Math .floor (Math .random () * (i + 1 ));
231+ x = a[i];
232+ a[i] = a[j];
233+ a[j] = x;
234+ }
235+ return a;
210236 }
211237 },
212238 computed: {
You can’t perform that action at this time.
0 commit comments