From b2de5cd04898c3a6e723b76b9083765895788019 Mon Sep 17 00:00:00 2001 From: Hidde de Vries Date: Tue, 17 Dec 2024 13:41:16 +0100 Subject: [PATCH] refactor: remove dep on BrowserOnly --- docs/componenten/README.mdx | 3 +-- src/components/ComponentOverview.tsx | 29 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/componenten/README.mdx b/docs/componenten/README.mdx index c07421a4126..99af050e495 100644 --- a/docs/componenten/README.mdx +++ b/docs/componenten/README.mdx @@ -15,10 +15,9 @@ keywords: --- import { ComponentOverview } from "@site/src/components/ComponentOverview"; -import BrowserOnly from "@docusaurus/BrowserOnly"; # Componenten De componenten van NL Design System worden met een [estafette aanpak](/handboek/estafettemodel) gemaakt en kunnen dus verschillende statussen hebben. -{() => } + diff --git a/src/components/ComponentOverview.tsx b/src/components/ComponentOverview.tsx index 93b05bcc803..e5c71808d57 100644 --- a/src/components/ComponentOverview.tsx +++ b/src/components/ComponentOverview.tsx @@ -21,10 +21,7 @@ export const ComponentOverview = () => { HALL_OF_FAME: 'hallOfFame', ONLY_IMPLEMENTED: 'geenImplementatie', }; - const category = useCurrentSidebarCategory(); - const { location } = window; - const params = new URLSearchParams(location.search); const getComponent = (item: PropSidebarItemLink) => item['title'] && @@ -41,16 +38,25 @@ export const ComponentOverview = () => { .map((item) => ({ ...item, ...getComponent(item) })); const [filteredComponents, setFilteredComponents] = useState(components); - const [showTodo, setShowTodo] = useState(!params.has(SEARCH_PARAM, SEARCH_VALUES.TODO)); - const [showHelpWanted, setShowHelpWanted] = useState(!params.has(SEARCH_PARAM, SEARCH_VALUES.HELP_WANTED)); - const [showCommunity, setShowCommunity] = useState(!params.has(SEARCH_PARAM, SEARCH_VALUES.COMMUNITY)); - const [showCandidate, setShowCandidate] = useState(!params.has(SEARCH_PARAM, SEARCH_VALUES.CANDIDATE)); - const [showHallOfFame, setShowHallOfFame] = useState(!params.has(SEARCH_PARAM, SEARCH_VALUES.HALL_OF_FAME)); - const [showOnlyImplemented, setshowOnlyImplemented] = useState( - params.has(SEARCH_PARAM, SEARCH_VALUES.ONLY_IMPLEMENTED), - ); + const [showTodo, setShowTodo] = useState(true); + const [showHelpWanted, setShowHelpWanted] = useState(true); + const [showCommunity, setShowCommunity] = useState(true); + const [showCandidate, setShowCandidate] = useState(true); + const [showHallOfFame, setShowHallOfFame] = useState(true); + const [showOnlyImplemented, setshowOnlyImplemented] = useState(true); useEffect(() => { + const { location } = window || { search: '' }; + const params = new URLSearchParams(location.search); + + /* set initial state only inside effect, as they rely on window information */ + setShowTodo(!params.has(SEARCH_PARAM, SEARCH_VALUES.TODO)); + setShowHelpWanted(!params.has(SEARCH_PARAM, SEARCH_VALUES.HELP_WANTED)); + setShowCommunity(!params.has(SEARCH_PARAM, SEARCH_VALUES.COMMUNITY)); + setShowCandidate(!params.has(SEARCH_PARAM, SEARCH_VALUES.CANDIDATE)); + setShowHallOfFame(!params.has(SEARCH_PARAM, SEARCH_VALUES.HALL_OF_FAME)); + setshowOnlyImplemented(params.has(SEARCH_PARAM, SEARCH_VALUES.ONLY_IMPLEMENTED)); + setFilteredComponents(() => components .filter((c) => { @@ -131,7 +137,6 @@ export const ComponentOverview = () => { { className: 'utrecht-accordion--nlds-subtle', headingLevel: 2, - expanded: params.size > 0, // TODO: Make Pull Request for Utrecht Accordion to allow `ReactNode` // eslint-disable-next-line @typescript-eslint/no-explicit-any