125125 <label class =" label" >Show:</label >
126126 <div class =" control" >
127127 <div class =" select" >
128- <select v-model =" cveListSearchStore.pagination.numberPerPage" aria-label =" Select how many search results to show" >
128+ <select v-model =" cveListSearchStore.pagination.numberPerPage"
129+ aria-label =" Select how many search results to show" >
129130 <option v-for =" num in cveListSearchStore.pagination.numberPerPageOptions" :key =" `page-${num}`" :value =" num" >
130131 {{ num }}
131132 </option >
135136 <label for =" sort" class =" label" >Sort by:</label >
136137 <div class =" control" >
137138 <div class =" select" >
138- <select name =" partner" v-model =" cveListSearchStore.pagination.sortBy" aria-label =" Select a sort option" >
139+ <select name =" partner" v-model =" cveListSearchStore.pagination.sortBy"
140+ aria-label =" Select a sort option" >
139141 <option v-for =" sort in cveListSearchStore.pagination.sortByOptions" :key =" sort.key"
140- :value =" sort"
141- >
142+ :value =" sort" >
142143 {{ sort.label }}
143144 </option >
144145 </select >
274275import { useCveListSearchStore } from ' @/stores/cveListSearch' ;
275276import { useGenericGlobalsStore } from ' @/stores/genericGlobals' ;
276277import { usePartnerStore } from ' @/stores/partners' ;
277- import { computed , createApp , watch } from ' vue' ;
278+ import { computed , createApp , ref , watch } from ' vue' ;
278279import { useRouter } from ' vue-router' ;
279280import ServiceUnavailable from ' @/components/ServiceUnavailable.vue'
280281
@@ -286,12 +287,29 @@ const app = createApp({});
286287
287288app .component (' ServiceUnavailable' , ServiceUnavailable);
288289
290+ // Keeping track of the current settings for the results per page and
291+ // sort option prevents the watches from doing searches just because the
292+ // cveListSearchStore is reset (which triggers a watch). We really only
293+ // want one of these watches triggered if the user actually changes the
294+ // value.
295+
296+ let currNumPerPage = ref (cveListSearchStore .pagination .numberPerPage );
297+ let currSortByLabel = ref (cveListSearchStore .pagination .sortBy .label );
298+
289299watch (()=> cveListSearchStore .pagination .numberPerPage , ()=> {
290- if (! cveListSearchStore .isSearching ) cveListSearchStore .handleNumberPerPageChange ();
300+ if (! cveListSearchStore .isSearching
301+ && cveListSearchStore .pagination .numberPerPage !== currNumPerPage .value ) {
302+ currNumPerPage .value = cveListSearchStore .pagination .numberPerPage ;
303+ cveListSearchStore .handleNumberPerPageChange ();
304+ }
291305}, { deep: true });
292306
293307watch (()=> cveListSearchStore .pagination .sortBy , ()=> {
294- if (! cveListSearchStore .isSearching ) cveListSearchStore .sortResults ();
308+ if (! cveListSearchStore .isSearching
309+ && cveListSearchStore .pagination .sortBy .label !== currSortByLabel .value ) {
310+ currSortByLabel .value = cveListSearchStore .pagination .sortBy .label ;
311+ cveListSearchStore .sortResults ();
312+ }
295313}, { deep: true });
296314
297315function backToTop () {
0 commit comments