Skip to content

Commit

Permalink
DIGG-439: Removing url params from dataset-series page
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaMunterud committed Dec 11, 2024
1 parent 86773f2 commit 09e4280
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions features/entryscape/dataset-series-page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Entry } from "@entryscape/entrystore-js";
import { useRouter } from "next/router";
import useTranslation from "next-translate/useTranslation";
import { FC, useContext, useEffect, useMemo } from "react";
Expand All @@ -8,10 +9,33 @@ import { Heading } from "@/components/typography/heading";
import { createSearchProviderSettings } from "@/features/search/search-page/search-page-entryscape/search-page-provider-settings";
import { SearchResults } from "@/features/search/search-results";
import { EntrystoreContext } from "@/providers/entrystore-provider";
import SearchProvider, { SearchContext } from "@/providers/search-provider";
import SearchProvider, {
SearchContext,
SearchContextData,
} from "@/providers/search-provider";
import { SettingsContext } from "@/providers/settings-provider";
import { linkBase } from "@/utilities";

const SearchSection: FC<{ search: SearchContextData; entry: Entry }> = ({
search,
entry,
}) => {
useEffect(() => {
if (!search) return;

// Perform initial search
search
.set({
page: 0,
query: "",
fetchFacets: true,
})
.then(() => search.doSearch(false, false, false, false));
}, [entry]);

return null;
};

export const DatasetSeriesPage: FC = () => {
const { pathname } = useRouter() || {};
const { env, setBreadcrumb } = useContext(SettingsContext);
Expand All @@ -32,21 +56,6 @@ export const DatasetSeriesPage: FC = () => {
});
}, [pathname, entry]);

useEffect(() => {
// Check if there are no query parameters or if they're empty
if (!router.query.q && !router.query.f) {
// Update URL with default query parameters
router.replace(
{
pathname: router.pathname,
query: { ...router.query, q: "", f: "" },
},
undefined,
{ shallow: true },
);
}
}, [router.isReady]);

const searchProviderSettings = useMemo(
() => createSearchProviderSettings(env, lang),
[env, lang],
Expand Down Expand Up @@ -81,6 +90,7 @@ export const DatasetSeriesPage: FC = () => {
<SearchContext.Consumer>
{(search) => (
<div className="mt-xl bg-white py-xl">
<SearchSection search={search} entry={entry.entry} />
<Container>
<div
className={
Expand Down

0 comments on commit 09e4280

Please sign in to comment.