Skip to content

Commit 2441388

Browse files
authored
Fix query (#25)
* fix(search): store search input in url with debounce * fix(footer): updated mui joy link * fix(ui): fix general background color * test(snapshot): updated snapshot with new ui
1 parent 1645769 commit 2441388

File tree

150 files changed

+268
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+268
-209
lines changed

apps/web/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"next-seo": "^6.5.0",
2424
"react": "^18.2.0",
2525
"react-dom": "^18.2.0",
26-
"react-icons": "^5.0.1"
26+
"react-icons": "^5.0.1",
27+
"use-debounce": "^10.0.0"
2728
},
2829
"devDependencies": {
2930
"@ducanh2912/next-pwa": "^10.2.5",

apps/web/pages/compounds/index.tsx

+2-46
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,16 @@ import { Optional } from '@poolofdeath20/util';
66

77
import data from '@periotable/data';
88

9-
import useSearchQuery from '../../src/web/hooks/search';
109
import Seo from '../../src/web/components/seo';
1110
import ListOfCompounds, {
1211
type Compounds,
1312
} from '../../src/web/components/compounds';
1413

1514
const Compounds = () => {
16-
const allCompounds = data.flatMap((value) => {
15+
const compounds = data.flatMap((value) => {
1716
return value.compounds;
1817
}) as Compounds;
1918

20-
const [value, setValue] = useSearchQuery();
21-
22-
const [compounds, setCompounds] = React.useState(allCompounds);
23-
24-
React.useEffect(() => {
25-
setCompounds(
26-
value
27-
.map((value) => {
28-
return value.toLowerCase();
29-
})
30-
.map((value) => {
31-
return allCompounds.filter((match) => {
32-
const molecularFormulaMatch = match.molecularformula
33-
.toLowerCase()
34-
.includes(value);
35-
36-
switch (molecularFormulaMatch) {
37-
case true: {
38-
return true;
39-
}
40-
case false: {
41-
const nameMatches = match.allnames.filter(
42-
(name) => {
43-
return name
44-
.toLowerCase()
45-
.includes(value);
46-
}
47-
);
48-
49-
return nameMatches.length;
50-
}
51-
}
52-
});
53-
})
54-
.unwrapOrElse(() => {
55-
return allCompounds;
56-
})
57-
);
58-
}, [value.unwrapOrGet('')]);
59-
6019
return (
6120
<Box display="flex" justifyContent="center" alignItems="center" pb={8}>
6221
<Seo
@@ -72,12 +31,9 @@ const Compounds = () => {
7231
/>
7332
<Box width="90%">
7433
<ListOfCompounds
34+
useNativeRouter={false}
7535
compounds={compounds}
7636
path="/compounds"
77-
search={{
78-
value,
79-
setValue,
80-
}}
8137
/>
8238
</Box>
8339
</Box>

apps/web/pages/elements/[name]/index.tsx

+3-49
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import ListOfCompounds, {
3434
type Compounds,
3535
} from '../../../src/web/components/compounds';
3636
import { BigTile } from '../../../src/web/components/table/element';
37-
import useSearchQuery from '../../../src/web/hooks/search';
3837
import useBreakpoint from '../../../src/web/hooks/break-point';
3938
import { useHeaderHeight } from '../../../src/web/components/common/header';
4039
import { obtainNameFromUrl } from '../../../src/web/util/asset';
@@ -325,59 +324,14 @@ const generatePostfix = () => {
325324

326325
const Compounds = ({ element }: GetStaticPropsType) => {
327326
if (!element.compounds.length) {
328-
return <Typography>There are no compound known</Typography>;
327+
return <Typography>There are no known compound</Typography>;
329328
}
330329

331-
const [value, setValue] = useSearchQuery();
332-
333-
const [compounds, setCompounds] = React.useState(
334-
element.compounds as Compounds
335-
);
336-
337-
React.useEffect(() => {
338-
setCompounds(
339-
value
340-
.map((value) => {
341-
return value.toLowerCase();
342-
})
343-
.map((value) => {
344-
return element.compounds.filter((compound) => {
345-
const molecularFormulaMatch = compound.molecularformula
346-
.toLowerCase()
347-
.includes(value);
348-
349-
switch (molecularFormulaMatch) {
350-
case true: {
351-
return true;
352-
}
353-
case false: {
354-
const nameMatches = compound.allnames.filter(
355-
(name) => {
356-
return name
357-
.toLowerCase()
358-
.includes(value);
359-
}
360-
);
361-
362-
return nameMatches.length;
363-
}
364-
}
365-
});
366-
})
367-
.unwrapOrElse(() => {
368-
return element.compounds;
369-
})
370-
);
371-
}, [value.unwrapOrGet('')]);
372-
373330
return (
374331
<ListOfCompounds
375-
compounds={compounds}
332+
useNativeRouter
333+
compounds={element.compounds}
376334
path={`${element.path}/list-of-compounds`}
377-
search={{
378-
value,
379-
setValue,
380-
}}
381335
/>
382336
);
383337
};

apps/web/src/web/components/common/footer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const Footer = () => {
146146
Component: SiTypescript,
147147
},
148148
{
149-
link: 'mui.com/joy-ui',
149+
link: 'mui.com/joy-ui/getting-started',
150150
Component: SiMui,
151151
},
152152
].map((props) => {

apps/web/src/web/components/common/input/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ const SearchBar = (
2929
onChange={(event) => {
3030
const { value } = event.target;
3131

32-
props.search.setValue(
33-
value ? Optional.from(value) : Optional.none()
34-
);
32+
props.search.setValue(Optional.some(value));
3533
}}
3634
/>
3735
</Box>

0 commit comments

Comments
 (0)