feat(frontend): separate profile and chart settings

This commit is contained in:
Jesse_Chen
2026-08-30 14:16:30 +08:00
parent 52477306cc
commit f4fb39e0f3
5 changed files with 40 additions and 46 deletions
@@ -1,22 +1,17 @@
"use client";
import { X } from "lucide-react";
import { memo, useEffect, useState, type MutableRefObject, type ReactNode } from "react";
export type AccountOverlayLibraryControls = Readonly<{
open: boolean;
toggle: () => void;
}>;
import { memo, type MutableRefObject, type ReactNode } from "react";
export type AccountOverlayModel = Readonly<{
title: string;
dialogClass: string;
signingOut: boolean;
close: () => void;
takeOpenLibraryRequest: () => boolean;
overlayRef: MutableRefObject<HTMLElement | null>;
closeButtonRef: MutableRefObject<HTMLButtonElement | null>;
renderProfile: (library: AccountOverlayLibraryControls) => ReactNode;
renderProfile: () => ReactNode;
renderChartLibrary: () => ReactNode;
renderLogout: () => ReactNode;
}>;
@@ -27,17 +22,10 @@ export const AccountDialogOverlay = memo(function AccountDialogOverlay({
modelRef,
}: Readonly<{
open: boolean;
dialog: "profile" | "logout" | null;
dialog: "profile" | "chart-library" | "logout" | null;
openEpoch: number;
modelRef: MutableRefObject<AccountOverlayModel | null>;
}>) {
const [chartLibraryOpen, setChartLibraryOpen] = useState(false);
useEffect(() => {
if (!open) return;
if (modelRef.current?.takeOpenLibraryRequest()) setChartLibraryOpen(true);
}, [dialog, modelRef, open]);
if (!open || dialog === null) return null;
const model = modelRef.current;
if (!model) return null;
@@ -66,10 +54,8 @@ export const AccountDialogOverlay = memo(function AccountDialogOverlay({
<X aria-hidden="true" />
</button>
</header>
{dialog === "profile" && model.renderProfile({
open: chartLibraryOpen,
toggle: () => setChartLibraryOpen((current) => !current),
})}
{dialog === "profile" && model.renderProfile()}
{dialog === "chart-library" && model.renderChartLibrary()}
{dialog === "logout" && model.renderLogout()}
</section>
</div>
+5
View File
@@ -71,6 +71,7 @@ export type AppSidebarProps = {
onSelectChart: (chartId: string) => void;
onAddChart: () => void;
onOpenProfile: () => void;
onOpenChartLibrary: () => void;
onOpenRedeem: () => void;
onOpenLogout: () => void;
};
@@ -92,6 +93,7 @@ export function AppSidebar({
onSelectChart,
onAddChart,
onOpenProfile,
onOpenChartLibrary,
onOpenRedeem,
onOpenLogout,
}: AppSidebarProps) {
@@ -303,6 +305,9 @@ export function AppSidebar({
<Menu.Item className="account-menu-item" onClick={onOpenProfile}>
<UserRound aria-hidden="true" /><span></span><ChevronRight aria-hidden="true" />
</Menu.Item>
<Menu.Item className="account-menu-item" onClick={onOpenChartLibrary}>
<Users aria-hidden="true" /><span></span><ChevronRight aria-hidden="true" />
</Menu.Item>
<Menu.Item className="account-menu-item" onClick={onOpenRedeem}>
<Gift aria-hidden="true" /><span></span><small>{account.credits} </small>
</Menu.Item>