From fb8c1b122ef8d15fb015ebf4a606c5655a4425f9 Mon Sep 17 00:00:00 2001 From: Zining Date: Fri, 22 Nov 2024 14:51:23 -0500 Subject: [PATCH] add query improvement --- .../src/features/search/query/querySlice.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mcweb/frontend/src/features/search/query/querySlice.js b/mcweb/frontend/src/features/search/query/querySlice.js index 83f818311..bd9782703 100644 --- a/mcweb/frontend/src/features/search/query/querySlice.js +++ b/mcweb/frontend/src/features/search/query/querySlice.js @@ -145,23 +145,24 @@ const querySlice = createSlice({ }, addQuery: (state, { payload }) => { const freezeState = state; + const lastQuery = freezeState[freezeState.length - 1] || {}; freezeState.push( { queryString: '', queryList: [[], [], []], negatedQueryList: [[], [], []], - platform: payload.platform, - startDate, - endDate: dayjs(latestAllowedEndDate(DEFAULT_PROVIDER)).format('MM/DD/YYYY'), - collections: [], - previewCollections: [], - sources: [], - previewSources: [], + platform: payload.platform || lastQuery.platform || DEFAULT_PROVIDER, + startDate: lastQuery.startDate || startDate, + endDate: lastQuery.endDate || dayjs(latestAllowedEndDate(DEFAULT_PROVIDER)).format('MM/DD/YYYY'), + collections: [...(lastQuery.collections || [])], + previewCollections: [...(lastQuery.previewCollections || [])], + sources: [...(lastQuery.sources || [])], + previewSources: [...(lastQuery.previewSources || [])], lastSearchTime: dayjs().unix(), isFromDateValid: true, isToDateValid: true, anyAll: 'any', - advanced: payload.advanced, + advanced: payload.advanced || false, name: 'Query', edited: false, }, @@ -269,4 +270,4 @@ export const { setInitialSearchTime, } = querySlice.actions; -export default querySlice.reducer; +export default querySlice.reducer; \ No newline at end of file