diff --git a/web/src/components/Settings/SectionMenuItem.tsx b/web/src/components/Settings/SectionMenuItem.tsx new file mode 100644 index 00000000..da2c6b2b --- /dev/null +++ b/web/src/components/Settings/SectionMenuItem.tsx @@ -0,0 +1,24 @@ +import { LucideIcon } from "lucide-react"; +import React from "react"; + +interface SettingMenuItemProps { + text: string; + icon: LucideIcon; + isSelected: boolean; + onClick: () => void; +} + +const SectionMenuItem: React.FC = ({ text, icon: IconComponent, isSelected, onClick }) => { + return ( + + {text} + + ); +}; + +export default SectionMenuItem; diff --git a/web/src/pages/Setting.tsx b/web/src/pages/Setting.tsx index b05c542a..c59bd7e7 100644 --- a/web/src/pages/Setting.tsx +++ b/web/src/pages/Setting.tsx @@ -1,11 +1,13 @@ import { Option, Select } from "@mui/joy"; -import { useState } from "react"; +import { LucideIcon } from "lucide-react"; +import { useCallback, useMemo, useState } from "react"; import Icon from "@/components/Icon"; import MobileHeader from "@/components/MobileHeader"; import MemberSection from "@/components/Settings/MemberSection"; import MyAccountSection from "@/components/Settings/MyAccountSection"; import PreferencesSection from "@/components/Settings/PreferencesSection"; import SSOSection from "@/components/Settings/SSOSection"; +import SectionMenuItem from "@/components/Settings/SectionMenuItem"; import StorageSection from "@/components/Settings/StorageSection"; import SystemSection from "@/components/Settings/SystemSection"; import useCurrentUser from "@/hooks/useCurrentUser"; @@ -19,6 +21,18 @@ interface State { selectedSection: SettingSection; } +const BASIC_SECTIONS: SettingSection[] = ["my-account", "preference"]; +const ADMIN_SECTIONS: SettingSection[] = ["member", "system", "storage", "sso"]; + +const SECTION_ICON_MAP: Record = { + "my-account": Icon.User, + preference: Icon.Cog, + member: Icon.Users, + system: Icon.Settings2, + storage: Icon.Database, + sso: Icon.Key, +}; + const Setting = () => { const t = useTranslate(); const user = useCurrentUser(); @@ -26,21 +40,22 @@ const Setting = () => { const [state, setState] = useState({ selectedSection: "my-account", }); - const isHost = user.role === User_Role.HOST; - const handleSectionSelectorItemClick = (settingSection: SettingSection) => { - setState({ - selectedSection: settingSection, - }); - }; + const isHost = user.role === User_Role.HOST; - const getSettingSectionList = () => { - let settingList: SettingSection[] = ["my-account", "preference"]; + const settingsSectionList = useMemo(() => { + let settingList = [...BASIC_SECTIONS]; if (isHost) { - settingList = settingList.concat(["member", "system", "storage", "sso"]); + settingList = settingList.concat(ADMIN_SECTIONS); } return settingList; - }; + }, [isHost]); + + const handleSectionSelectorItemClick = useCallback((settingSection: SettingSection) => { + setState({ + selectedSection: settingSection, + }); + }, []); return (
@@ -48,61 +63,31 @@ const Setting = () => {
- {t("common.basic")} + {t("common.basic")}
- handleSectionSelectorItemClick("my-account")} - > - {t("setting.my-account")} - - handleSectionSelectorItemClick("preference")} - > - {t("setting.preference")} - + {BASIC_SECTIONS.map((item) => ( + handleSectionSelectorItemClick(item)} + /> + ))}
{isHost ? ( <> - {t("common.admin")} + {t("common.admin")}
- handleSectionSelectorItemClick("member")} - className={`w-auto px-3 leading-8 flex flex-row justify-start items-center cursor-pointer rounded-lg hover:opacity-80 ${ - state.selectedSection === "member" ? "bg-zinc-100 shadow dark:bg-zinc-900" : "" - }`} - > - {t("setting.member")} - - handleSectionSelectorItemClick("system")} - className={`w-auto px-3 leading-8 flex flex-row justify-start items-center cursor-pointer rounded-lg hover:opacity-80 ${ - state.selectedSection === "system" ? "bg-zinc-100 shadow dark:bg-zinc-900" : "" - }`} - > - {t("setting.system")} - - handleSectionSelectorItemClick("storage")} - className={`w-auto px-3 leading-8 flex flex-row justify-start items-center cursor-pointer rounded-lg hover:opacity-80 ${ - state.selectedSection === "storage" ? "bg-zinc-100 shadow dark:bg-zinc-900" : "" - }`} - > - {t("setting.storage")} - - handleSectionSelectorItemClick("sso")} - className={`w-auto px-3 leading-8 flex flex-row justify-start items-center cursor-pointer rounded-lg hover:opacity-80 ${ - state.selectedSection === "sso" ? "bg-zinc-100 shadow dark:bg-zinc-900" : "" - }`} - > - {t("setting.sso")} - + {ADMIN_SECTIONS.map((item) => ( + handleSectionSelectorItemClick(item)} + /> + ))} Version: v{globalStore.state.systemStatus.profile.version}
@@ -111,7 +96,7 @@ const Setting = () => {