diff --git a/src/components/Navbar/index.tsx b/src/components/Navbar/index.tsx index 77b869a6..fcfe2124 100644 --- a/src/components/Navbar/index.tsx +++ b/src/components/Navbar/index.tsx @@ -1,6 +1,6 @@ import type { NavbarProps as MantineNavbarProps } from '@mantine/core'; -import { Navbar as MantineNavbar, NavLink, Select ,Anchor,Card, Box, Modal ,Text ,Image} from '@mantine/core'; -import { IconNews, IconCodeCircle2, IconCheck, IconFileAlert, IconReload, IconHelpCircle, IconLogout, IconUser } from '@tabler/icons-react'; +import { Navbar as MantineNavbar, NavLink, Select, Anchor, Card, Box, Modal, Text, Image } from '@mantine/core'; +import { IconNews, IconCodeCircle2, IconCheck, IconFileAlert, IconReload, IconHelpCircle, IconLogout, IconUser } from '@tabler/icons-react'; import { FC, useEffect, useState } from 'react'; import docImage from '@/assets/images/doc.webp'; import githubLogo from '@/assets/images/github-logo.webp'; @@ -31,9 +31,10 @@ const Navbar: FC = (props) => { const [activeStream, setActiveStream] = useState(""); const [searchValue, setSearchValue] = useState(""); const { classes } = useNavbarStyles(); + const [currentPage, setCurrentPage] = useState("/logs"); const { container, linkBtnActive, linkBtn, - selectStreambtn ,streamsBtn ,lowerContainer , - actionBtn, helpTitle, helpDescription ,userBtn} = classes; + selectStreambtn, streamsBtn, lowerContainer, + actionBtn, helpTitle, helpDescription, userBtn } = classes; const { streamName } = useParams(); const nav = useNavigate(); const [, , removeCredentials] = useLocalStorage({ key: 'credentials' }); @@ -70,7 +71,7 @@ const Navbar: FC = (props) => { if (streamName) { setActiveStream(streamName); setSearchValue(streamName); - if (streamName !== subLogQuery.get().streamName) { + if (currentPage !== location.pathname) { const now = dayjs(); subLogQuery.set((state) => { state.streamName = streamName || ''; @@ -78,31 +79,23 @@ const Navbar: FC = (props) => { state.endTime = now.toDate(); }); subLogSelectedTimeRange.set(DEFAULT_FIXED_DURATIONS.name); + subLogSearch.set((state) => { + state.search = ''; + state.filters = {}; + }); + subRefreshInterval.set(null); + setCurrentPage(location.pathname); } } else if (streams && Boolean(streams.length)) { navigate(`/${streams[0].name}/logs`); } - }, [streams ,location]); + }, [streams, location]); const handleChange = (value: string) => { setActiveStream(value); setSearchValue(value); navigate(`/${value}/logs`); - if (value !== subLogQuery.get().streamName) { - const now = dayjs(); - subLogQuery.set((state) => { - state.streamName = value || ''; - state.startTime = now.subtract(DEFAULT_FIXED_DURATIONS.milliseconds, 'milliseconds').toDate(); - state.endTime = now.toDate(); - }); - subLogSelectedTimeRange.set(DEFAULT_FIXED_DURATIONS.name); - subLogSearch.set((state) => { - state.search = '', - state.filters = {} - }); - subRefreshInterval.set(null); - } }; useEffect(() => { @@ -142,12 +135,12 @@ const Navbar: FC = (props) => { return ( -