Skip to content

Commit

Permalink
feat: 👷 tools page scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Dec 4, 2023
1 parent adbf842 commit 6cd05cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ui/components/pages/tools/tools.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ import Grid from '@mui/material/Grid';
import Card from '@mui/material/Card';
import { TreeFilter } from 'ui/components/shared/treeFilter/treeFilter';
import { ProductContentBloc } from 'ui/components/pages/tools/productContentBloc/productContentBloc';
import { scrollToElement } from 'ui/utils/scrollToElement';

export const Tools = () => {
const { classes, cx } = useStyles();
const [searchParams, updateParams] = useTreeUrlParams();

// TODO -> Refactor using ref and no setTimeout

const [products, setProducts] = useState([]);

const { getProducts } = useContext(CoreApiContext);

window.scrollTo();

useEffect(() => {
getProducts().then((r) => setProducts(r));
}, [getProducts]);

return (
<div className={classes.wrapper}>
<div className={classes.container}>
Expand All @@ -32,6 +38,7 @@ export const Tools = () => {
setTreeState={updateParams}
tree={products['children'] ?? []}
autoComplete={{ isEnabled: false }}
onSelect={scrollToElement}
/>
</Card>
</Box>
Expand Down
13 changes: 13 additions & 0 deletions src/ui/utils/scrollToElement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const scrollToElement = (id) => {
const element = document.getElementById(id);

if (!element) return;

return setTimeout(
() =>
element.scrollIntoView({
behavior: 'smooth',
}),
100
);
};

0 comments on commit 6cd05cb

Please sign in to comment.