mirror of https://github.com/usememos/memos
refactor: home layout
parent
9107a941ca
commit
271a8c8c28
@ -1,39 +0,0 @@
|
||||
import useDebounce from "react-use/lib/useDebounce";
|
||||
import SearchBar from "@/components/SearchBar";
|
||||
import { useUserStatsStore } from "@/store/v1";
|
||||
import { cn } from "@/utils";
|
||||
import TagsSection from "../HomeSidebar/TagsSection";
|
||||
import MemoFilters from "../MemoFilters";
|
||||
import StatisticsView from "../StatisticsView";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const ExploreSidebar = (props: Props) => {
|
||||
const userStatsStore = useUserStatsStore();
|
||||
|
||||
useDebounce(
|
||||
async () => {
|
||||
await userStatsStore.listUserStats();
|
||||
},
|
||||
300,
|
||||
[userStatsStore.stateId],
|
||||
);
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={cn(
|
||||
"relative w-full h-auto max-h-screen overflow-auto hide-scrollbar flex flex-col justify-start items-start",
|
||||
props.className,
|
||||
)}
|
||||
>
|
||||
<SearchBar />
|
||||
<MemoFilters />
|
||||
<StatisticsView />
|
||||
<TagsSection readonly={true} />
|
||||
</aside>
|
||||
);
|
||||
};
|
||||
|
||||
export default ExploreSidebar;
|
@ -1,38 +0,0 @@
|
||||
import { Drawer } from "@mui/joy";
|
||||
import { Button } from "@usememos/mui";
|
||||
import { SearchIcon } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import ExploreSidebar from "./ExploreSidebar";
|
||||
|
||||
const ExploreSidebarDrawer = () => {
|
||||
const location = useLocation();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setOpen(false);
|
||||
}, [location.pathname]);
|
||||
|
||||
const toggleDrawer = (inOpen: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => {
|
||||
if (event.type === "keydown" && ((event as React.KeyboardEvent).key === "Tab" || (event as React.KeyboardEvent).key === "Shift")) {
|
||||
return;
|
||||
}
|
||||
|
||||
setOpen(inOpen);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button variant="plain" className="!bg-transparent px-2" onClick={toggleDrawer(true)}>
|
||||
<SearchIcon className="w-5 h-auto dark:text-gray-400" />
|
||||
</Button>
|
||||
<Drawer anchor="right" size="sm" open={open} onClose={toggleDrawer(false)}>
|
||||
<div className="w-full h-full px-4 bg-zinc-100 dark:bg-zinc-900">
|
||||
<ExploreSidebar className="py-4" />
|
||||
</div>
|
||||
</Drawer>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ExploreSidebarDrawer;
|
@ -1,4 +0,0 @@
|
||||
import ExploreSidebar from "./ExploreSidebar";
|
||||
import ExploreSidebarDrawer from "./ExploreSidebarDrawer";
|
||||
|
||||
export { ExploreSidebar, ExploreSidebarDrawer };
|
@ -0,0 +1,38 @@
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { Outlet } from "react-router-dom";
|
||||
import { HomeSidebar, HomeSidebarDrawer } from "@/components/HomeSidebar";
|
||||
import MobileHeader from "@/components/MobileHeader";
|
||||
import useResponsiveWidth from "@/hooks/useResponsiveWidth";
|
||||
import { cn } from "@/utils";
|
||||
|
||||
const HomeLayout = observer(() => {
|
||||
const { md, lg } = useResponsiveWidth();
|
||||
|
||||
return (
|
||||
<section className="@container w-full min-h-full flex flex-col justify-start items-center">
|
||||
{!md && (
|
||||
<MobileHeader>
|
||||
<HomeSidebarDrawer />
|
||||
</MobileHeader>
|
||||
)}
|
||||
<div className={cn("w-full min-h-full flex flex-row justify-start items-start")}>
|
||||
{md && (
|
||||
<div
|
||||
className={cn(
|
||||
"sticky top-0 left-0 shrink-0 h-[100svh] transition-all",
|
||||
"border-r border-gray-200 dark:border-zinc-800",
|
||||
lg ? "px-5 w-72" : "px-4 w-56",
|
||||
)}
|
||||
>
|
||||
<HomeSidebar className={cn("py-6")} />
|
||||
</div>
|
||||
)}
|
||||
<div className={cn("w-full mx-auto px-4 sm:px-6 sm:pt-3 md:pt-6 pb-8", md && "max-w-3xl")}>
|
||||
<Outlet />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
});
|
||||
|
||||
export default HomeLayout;
|
@ -1,13 +0,0 @@
|
||||
import { Suspense } from "react";
|
||||
import { Outlet } from "react-router-dom";
|
||||
import Loading from "@/pages/Loading";
|
||||
|
||||
const SuspenseWrapper = () => {
|
||||
return (
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Outlet />
|
||||
</Suspense>
|
||||
);
|
||||
};
|
||||
|
||||
export default SuspenseWrapper;
|
Loading…
Reference in New Issue