From 780bbd08649b98c931521d9782e433c06bafb523 Mon Sep 17 00:00:00 2001 From: Noam Levi Date: Mon, 2 Sep 2024 15:32:07 +0300 Subject: [PATCH] close sidebar on change page --- src/components/Sidebar/index.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index dced768..b3ca23a 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -1,5 +1,6 @@ import { Button, Code, Divider, Drawer, DrawerProps, NavLink, NavLinkProps, Stack, Switch, Text, Title, useMantineColorScheme } from '@mantine/core' -import { Link, LinkProps, useMatchRoute } from '@tanstack/react-router' +import { Link, LinkProps, useLocation, useMatchRoute } from '@tanstack/react-router' +import { useEffect } from 'react' import { MoonStarsIcon, SunIcon } from '@/assets' import { useSwipe, useWordleStore } from '@/hooks' @@ -34,16 +35,21 @@ const Sidebar = ({ opened, onClose, ...props }: SidebarProps) => { state.resetStore, state.time, ]) + const location = useLocation() const { colorScheme, toggleColorScheme } = useMantineColorScheme() + const handleResetStore = () => { + resetStore() + onClose() + } + useSwipe({ left: onClose }) - const handleResetStore = () => { - resetStore() + useEffect(() => { onClose() - } + }, [location]) return (