From 370054e040bd687ca4e4e1e7302c92257cba1f76 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 21 Jan 2024 21:02:55 +0800 Subject: [PATCH] chore: implement collapsed navigation --- web/src/components/MemoEditor/index.tsx | 4 +- web/src/components/Navigation.tsx | 41 +++++++++++-------- web/src/components/UserBanner.tsx | 54 ++++++++++++------------- web/src/layouts/Root.tsx | 20 +++++++-- 4 files changed, 71 insertions(+), 48 deletions(-) diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx index d91b62b5..6c326b0c 100644 --- a/web/src/components/MemoEditor/index.tsx +++ b/web/src/components/MemoEditor/index.tsx @@ -381,6 +381,8 @@ const MemoEditor = (props: Props) => { onFocus={handleEditorFocus} > + +
e.stopPropagation()}>
@@ -393,8 +395,6 @@ const MemoEditor = (props: Props) => {
- -
e.stopPropagation()}> diff --git a/web/src/components/Navigation.tsx b/web/src/components/Navigation.tsx index 572e2613..df24b057 100644 --- a/web/src/components/Navigation.tsx +++ b/web/src/components/Navigation.tsx @@ -1,3 +1,4 @@ +import { Tooltip } from "@mui/joy"; import classNames from "classnames"; import { useEffect } from "react"; import { NavLink } from "react-router-dom"; @@ -16,10 +17,12 @@ interface NavLinkItem { } interface Props { + collapsed?: boolean; className?: string; } const Navigation = (props: Props) => { + const { collapsed, className } = props; const t = useTranslate(); const user = useCurrentUser(); const inboxStore = useInboxStore(); @@ -45,31 +48,31 @@ const Navigation = (props: Props) => { id: "header-home", path: "/", title: t("common.home"), - icon: , + icon: , }; const timelineNavLink: NavLinkItem = { id: "header-timeline", path: "/timeline", title: t("timeline.title"), - icon: , + icon: , }; const resourcesNavLink: NavLinkItem = { id: "header-resources", path: "/resources", title: t("common.resources"), - icon: , + icon: , }; const exploreNavLink: NavLinkItem = { id: "header-explore", path: "/explore", title: t("common.explore"), - icon: , + icon: , }; const profileNavLink: NavLinkItem = { id: "header-profile", path: user ? `/u/${encodeURIComponent(user.username)}` : "", title: t("common.profile"), - icon: , + icon: , }; const inboxNavLink: NavLinkItem = { id: "header-inbox", @@ -78,7 +81,7 @@ const Navigation = (props: Props) => { icon: ( <>
- + {hasUnreadInbox &&
}
@@ -88,25 +91,25 @@ const Navigation = (props: Props) => { id: "header-archived", path: "/archived", title: t("common.archived"), - icon: , + icon: , }; const settingNavLink: NavLinkItem = { id: "header-setting", path: "/setting", title: t("common.settings"), - icon: , + icon: , }; const signInNavLink: NavLinkItem = { id: "header-auth", path: "/auth", title: t("common.sign-in"), - icon: , + icon: , }; const aboutNavLink: NavLinkItem = { id: "header-about", path: "/about", title: t("common.about"), - icon: , + icon: , }; const navLinks: NavLinkItem[] = user @@ -117,16 +120,17 @@ const Navigation = (props: Props) => {
- +
{navLinks.map((navLink) => ( classNames( - "w-full px-4 pr-5 py-2 rounded-2xl border flex flex-row items-center text-lg text-gray-800 dark:text-gray-300 hover:bg-white hover:border-gray-200 dark:hover:border-zinc-700 dark:hover:bg-zinc-800", + "px-2 py-2 rounded-2xl border flex flex-row items-center text-lg text-gray-800 dark:text-gray-300 hover:bg-white hover:border-gray-200 dark:hover:border-zinc-700 dark:hover:bg-zinc-800", + collapsed ? "" : "w-full px-4", isActive ? "bg-white drop-shadow-sm dark:bg-zinc-800 border-gray-200 dark:border-zinc-700" : "border-transparent" ) } @@ -135,9 +139,14 @@ const Navigation = (props: Props) => { id={navLink.id} unstable_viewTransition > - <> - {navLink.icon} {navLink.title} - + {props.collapsed ? ( + +
{navLink.icon}
+
+ ) : ( + navLink.icon + )} + {!props.collapsed && {navLink.title}}
))}
diff --git a/web/src/components/UserBanner.tsx b/web/src/components/UserBanner.tsx index 82bee04d..44ea3d7e 100644 --- a/web/src/components/UserBanner.tsx +++ b/web/src/components/UserBanner.tsx @@ -1,12 +1,18 @@ +import { Dropdown, Menu, MenuButton, MenuItem } from "@mui/joy"; +import classNames from "classnames"; import * as api from "@/helpers/api"; import useCurrentUser from "@/hooks/useCurrentUser"; import { useGlobalStore } from "@/store/module"; import { useTranslate } from "@/utils/i18n"; import Icon from "./Icon"; import UserAvatar from "./UserAvatar"; -import Dropdown from "./kit/Dropdown"; -const UserBanner = () => { +interface Props { + collapsed?: boolean; +} + +const UserBanner = (props: Props) => { + const { collapsed } = props; const t = useTranslate(); const globalStore = useGlobalStore(); const { systemStatus } = globalStore.state; @@ -20,32 +26,26 @@ const UserBanner = () => { }; return ( -
- - - {title} -
- } - disabled={user == undefined} - actionsClassName="min-w-[128px] max-w-full" - positionClassName="top-full mt-2" - actions={ - <> - {user != undefined && ( - +
+ + +
- } - /> + > + + {!collapsed && {title}} +
+
+ + + + {t("common.sign-out")} + + +
); }; diff --git a/web/src/layouts/Root.tsx b/web/src/layouts/Root.tsx index 6a17bcd0..399d5270 100644 --- a/web/src/layouts/Root.tsx +++ b/web/src/layouts/Root.tsx @@ -1,18 +1,32 @@ +import classNames from "classnames"; import { Suspense } from "react"; import { Outlet } from "react-router-dom"; +import useLocalStorage from "react-use/lib/useLocalStorage"; import Navigation from "@/components/Navigation"; import useResponsiveWidth from "@/hooks/useResponsiveWidth"; import Loading from "@/pages/Loading"; function Root() { const { sm } = useResponsiveWidth(); + const [collapsed, setCollapsed] = useLocalStorage("navigation-collapsed", false); return (
-
+
{sm && ( -
- +
setCollapsed(!collapsed)} + > +
)}