diff --git a/frontend/src/components/Common/CategoryTab/CategoryTab.tsx b/frontend/src/components/Common/CategoryTab/CategoryTab.tsx index 42e2ba02d..8796c65f1 100644 --- a/frontend/src/components/Common/CategoryTab/CategoryTab.tsx +++ b/frontend/src/components/Common/CategoryTab/CategoryTab.tsx @@ -1,4 +1,6 @@ import { Button, theme } from '@fun-eat/design-system'; +import { useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; import type { CSSProp } from 'styled-components'; import styled from 'styled-components'; @@ -12,10 +14,21 @@ interface CategoryMenuProps { const CategoryTab = ({ menuVariant }: CategoryMenuProps) => { const { data: categories } = useCategoryQuery(menuVariant); + const { categoryIds } = useCategoryValueContext(); const { selectCategory } = useCategoryActionContext(); const currentCategoryId = categoryIds[menuVariant]; + const location = useLocation(); + const queryParams = new URLSearchParams(location.search); + const categoryIdFromURL = queryParams.get('category'); + + useEffect(() => { + if (categoryIdFromURL) { + selectCategory(menuVariant, parseInt(categoryIdFromURL)); + } + }, [location]); + return ( {categories.map((menu) => {