import { last } from "lodash-es"; import { ArchiveIcon, Globe2Icon, HomeIcon } from "lucide-react"; import { observer } from "mobx-react-lite"; import { matchPath, NavLink, useLocation } from "react-router-dom"; import useDebounce from "react-use/lib/useDebounce"; import SearchBar from "@/components/SearchBar"; import useCurrentUser from "@/hooks/useCurrentUser"; import { Routes } from "@/router"; import { useMemoList } from "@/store/v1"; import { userStore } from "@/store/v2"; import { cn } from "@/utils"; import { useTranslate } from "@/utils/i18n"; import MemoFilters from "../MemoFilters"; import StatisticsView from "../StatisticsView"; import ShortcutsSection from "./ShortcutsSection"; import TagsSection from "./TagsSection"; interface NavLinkItem { id: string; path: string; title: string; icon: React.ReactNode; } interface Props { className?: string; } const HomeSidebar = observer((props: Props) => { const t = useTranslate(); const location = useLocation(); const currentUser = useCurrentUser(); const memoList = useMemoList(); const homeNavLink: NavLinkItem = { id: "header-home", path: Routes.ROOT, title: t("common.home"), icon: , }; const exploreNavLink: NavLinkItem = { id: "header-explore", path: Routes.EXPLORE, title: t("common.explore"), icon: , }; const archivedNavLink: NavLinkItem = { id: "header-archived", path: Routes.ARCHIVED, title: t("common.archived"), icon: , }; const navLinks: NavLinkItem[] = currentUser ? [homeNavLink, exploreNavLink, archivedNavLink] : [exploreNavLink]; useDebounce( async () => { let parent: string | undefined = undefined; if (location.pathname === Routes.ROOT && currentUser) { parent = currentUser.name; } if (matchPath("/u/:username", location.pathname) !== null) { const username = last(location.pathname.split("/")); const user = await userStore.getOrFetchUserByUsername(username || ""); parent = user.name; } await userStore.fetchUserStats(parent); }, 300, [memoList.size(), userStore.state.statsStateId, location.pathname], ); return ( ); }); export default HomeSidebar;