diff --git a/apps/web/package.json b/apps/web/package.json index 98bf020..38a602d 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -23,7 +23,8 @@ "next-seo": "^6.5.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-icons": "^5.0.1" + "react-icons": "^5.0.1", + "use-debounce": "^10.0.0" }, "devDependencies": { "@ducanh2912/next-pwa": "^10.2.5", diff --git a/apps/web/pages/compounds/index.tsx b/apps/web/pages/compounds/index.tsx index 73a3c03..ca45840 100644 --- a/apps/web/pages/compounds/index.tsx +++ b/apps/web/pages/compounds/index.tsx @@ -6,57 +6,16 @@ import { Optional } from '@poolofdeath20/util'; import data from '@periotable/data'; -import useSearchQuery from '../../src/web/hooks/search'; import Seo from '../../src/web/components/seo'; import ListOfCompounds, { type Compounds, } from '../../src/web/components/compounds'; const Compounds = () => { - const allCompounds = data.flatMap((value) => { + const compounds = data.flatMap((value) => { return value.compounds; }) as Compounds; - const [value, setValue] = useSearchQuery(); - - const [compounds, setCompounds] = React.useState(allCompounds); - - React.useEffect(() => { - setCompounds( - value - .map((value) => { - return value.toLowerCase(); - }) - .map((value) => { - return allCompounds.filter((match) => { - const molecularFormulaMatch = match.molecularformula - .toLowerCase() - .includes(value); - - switch (molecularFormulaMatch) { - case true: { - return true; - } - case false: { - const nameMatches = match.allnames.filter( - (name) => { - return name - .toLowerCase() - .includes(value); - } - ); - - return nameMatches.length; - } - } - }); - }) - .unwrapOrElse(() => { - return allCompounds; - }) - ); - }, [value.unwrapOrGet('')]); - return ( { /> diff --git a/apps/web/pages/elements/[name]/index.tsx b/apps/web/pages/elements/[name]/index.tsx index 30e7df8..edfbd21 100644 --- a/apps/web/pages/elements/[name]/index.tsx +++ b/apps/web/pages/elements/[name]/index.tsx @@ -34,7 +34,6 @@ import ListOfCompounds, { type Compounds, } from '../../../src/web/components/compounds'; import { BigTile } from '../../../src/web/components/table/element'; -import useSearchQuery from '../../../src/web/hooks/search'; import useBreakpoint from '../../../src/web/hooks/break-point'; import { useHeaderHeight } from '../../../src/web/components/common/header'; import { obtainNameFromUrl } from '../../../src/web/util/asset'; @@ -325,59 +324,14 @@ const generatePostfix = () => { const Compounds = ({ element }: GetStaticPropsType) => { if (!element.compounds.length) { - return There are no compound known; + return There are no known compound; } - const [value, setValue] = useSearchQuery(); - - const [compounds, setCompounds] = React.useState( - element.compounds as Compounds - ); - - React.useEffect(() => { - setCompounds( - value - .map((value) => { - return value.toLowerCase(); - }) - .map((value) => { - return element.compounds.filter((compound) => { - const molecularFormulaMatch = compound.molecularformula - .toLowerCase() - .includes(value); - - switch (molecularFormulaMatch) { - case true: { - return true; - } - case false: { - const nameMatches = compound.allnames.filter( - (name) => { - return name - .toLowerCase() - .includes(value); - } - ); - - return nameMatches.length; - } - } - }); - }) - .unwrapOrElse(() => { - return element.compounds; - }) - ); - }, [value.unwrapOrGet('')]); - return ( ); }; diff --git a/apps/web/src/web/components/common/footer/index.tsx b/apps/web/src/web/components/common/footer/index.tsx index 33dc7c5..cd381ad 100644 --- a/apps/web/src/web/components/common/footer/index.tsx +++ b/apps/web/src/web/components/common/footer/index.tsx @@ -146,7 +146,7 @@ const Footer = () => { Component: SiTypescript, }, { - link: 'mui.com/joy-ui', + link: 'mui.com/joy-ui/getting-started', Component: SiMui, }, ].map((props) => { diff --git a/apps/web/src/web/components/common/input/index.tsx b/apps/web/src/web/components/common/input/index.tsx index 1225ce8..380351d 100644 --- a/apps/web/src/web/components/common/input/index.tsx +++ b/apps/web/src/web/components/common/input/index.tsx @@ -29,9 +29,7 @@ const SearchBar = ( onChange={(event) => { const { value } = event.target; - props.search.setValue( - value ? Optional.from(value) : Optional.none() - ); + props.search.setValue(Optional.some(value)); }} /> diff --git a/apps/web/src/web/components/compounds/index.tsx b/apps/web/src/web/components/compounds/index.tsx index c3ddf52..6d8909f 100644 --- a/apps/web/src/web/components/compounds/index.tsx +++ b/apps/web/src/web/components/compounds/index.tsx @@ -16,11 +16,13 @@ import { MdOutlineChevronLeft, MdOutlineChevronRight } from 'react-icons/md'; import { type DeepReadonly, - Optional, Defined, type Return, + formQueryParamStringFromRecord, } from '@poolofdeath20/util'; +import { useDebounce } from 'use-debounce'; + import InternalLink from '../link/internal'; import ExternalLink from '../link/external'; import SearchBar from '../common/input'; @@ -29,6 +31,8 @@ import { usePagination, useRowsPerPage, } from '../../hooks/pagination'; +import useSearchQuery from '../../hooks/search'; +import useBreakpoint from '../../hooks/break-point'; import { spaceToUnderscore } from '../../../common/string'; @@ -153,6 +157,7 @@ const RowsSelect = ( Rows per page: