From e3b91dfea266f88c32d41a3b314de5fde3943b70 Mon Sep 17 00:00:00 2001 From: Anthony Lukach Date: Thu, 24 Oct 2024 15:26:24 -0700 Subject: [PATCH] Simplify, add default query --- frontend/src/store/query/query.epics.ts | 12 ++++-------- frontend/src/store/query/utils.ts | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/frontend/src/store/query/query.epics.ts b/frontend/src/store/query/query.epics.ts index 9456a1f..53d1722 100644 --- a/frontend/src/store/query/query.epics.ts +++ b/frontend/src/store/query/query.epics.ts @@ -32,6 +32,8 @@ import { import { getQueryString } from "./query.selectors"; import { getQueryFromString } from "./utils"; +const DEFAULT_QUERY = "sort:updated repo:developmentseed/now repo:developmentseed/how repo:developmentseed/ds-business repo:developmentseed/ds-team repo:developmentseed/operations repo:developmentseed/communications repo:developmentseed/ds-realwork repo:developmentseed/labs repo:developmentseed/ds-projectops repo:developmentseed/ds-devops repo:developmentseed/ds-metrics repo:developmentseed/ds-handbook repo:developmentseed/conferences-events"; + const queryChanged = ([prevState, curState]: [RootState, RootState]) => JSON.stringify(prevState.query.query) !== JSON.stringify(curState.query.query); @@ -75,14 +77,8 @@ const loadFromUrl: RootEpic = (action$, state$, { config }) => getQueryFromString( // Highly convoluted workflow to remove `code` & `state` from URL new URLSearchParams( - Object.fromEntries( - Array.from( - new URLSearchParams( - state$.value.router.location.search - ).entries() - ).filter(([k, v]) => !["code", "state"].includes(k)) - ) - ).toString() + state$.value.router.location.search + ).get('q') || DEFAULT_QUERY ) ) ) diff --git a/frontend/src/store/query/utils.ts b/frontend/src/store/query/utils.ts index 5c44cc9..441be49 100644 --- a/frontend/src/store/query/utils.ts +++ b/frontend/src/store/query/utils.ts @@ -1,8 +1,8 @@ import { QueryState } from "./query.reducer"; export const getQueryFromString = (url: string) => - decodeURIComponent(url.slice(2)) - .split("+") + url + .split(" ") .map(v => v.split(":")) .reduce( (acc, v) => ({