From 401364d746efd497fc3d6f0d04be5bcb3258a18e Mon Sep 17 00:00:00 2001 From: "thomas.ekstrand" Date: Tue, 13 Feb 2024 10:20:24 -0600 Subject: [PATCH] Code cleanup and fix linting/formatting --- src/components/FaqAccordion.tsx | 36 ++++++++++++--------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/components/FaqAccordion.tsx b/src/components/FaqAccordion.tsx index d1c8c3e8..1c475bcf 100644 --- a/src/components/FaqAccordion.tsx +++ b/src/components/FaqAccordion.tsx @@ -1,5 +1,4 @@ -import React, { useEffect, useState } from 'react'; -import BrowserOnly from '@docusaurus/BrowserOnly'; +import BrowserOnly from "@docusaurus/BrowserOnly"; import { Accordion, AccordionItem, @@ -21,7 +20,7 @@ export interface Faq { * @type {Function} */ const getOpenFaqItemsFromUrl = (slug: string): string[] => { - if (typeof window !== 'undefined') { + if (typeof window !== "undefined") { // Use URLSearchParams to parse the query parameters from the current URL const searchParams = new URLSearchParams(window.location.search); @@ -29,24 +28,22 @@ const getOpenFaqItemsFromUrl = (slug: string): string[] => { const openFaqItemsString = searchParams.get(`openFaqItems-${slug}`); // If the parameter exists, split it by commas into an array; otherwise, return an empty array - console.log(slug, openFaqItemsString ? openFaqItemsString.split(",") : []); return openFaqItemsString ? openFaqItemsString.split(",") : []; } }; /** -* Updates query parameters in the url when items are opened -* so that a link can be shared with the faq item already opened -*/ + * Updates query parameters in the url when items are opened + * so that a link can be shared with the faq item already opened + */ const handleChange = ( openFaqItems: (string | number)[], - slug: string + slug: string, ): void => { - // Get current url params const searchParams = new URLSearchParams(window.location.search); if (openFaqItems.length > 0) { - // Convert openFaqItems to a comma-separated string and update/add the parameter + // Create comma-separated string and update/add the parameter searchParams.set( `openFaqItems-${slug}`, openFaqItems.map(String).join(","), @@ -61,20 +58,10 @@ const handleChange = ( window.location.pathname }?${searchParams.toString()}`; - // Use history.pushState to change the URL without reloading the page + // Change the URL without reloading the page window.history.pushState({ path: newUrl }, "", newUrl); }; -/** - * We need to get the query params using docusaurus' router - * because `window` isn't available server side - * @return {[type]} [description] - */ -const useQuery = () => { - const { search } = useLocation(); - return React.useMemo(() => new URLSearchParams(search), [search]); -}; - export const FaqAccordion = ({ rows, slug, @@ -101,17 +88,20 @@ export const FaqAccordion = ({