diff --git a/src/components/nostr/user-menu.tsx b/src/components/nostr/user-menu.tsx index e466e79..91cff8c 100644 --- a/src/components/nostr/user-menu.tsx +++ b/src/components/nostr/user-menu.tsx @@ -1,4 +1,4 @@ -import { User } from "lucide-react"; +import { User, Check, UserPlus } from "lucide-react"; import accounts from "@/services/accounts"; import { ExtensionSigner } from "applesauce-signers"; import { ExtensionAccount } from "applesauce-accounts/accounts"; @@ -6,6 +6,7 @@ import { useProfile } from "@/hooks/useProfile"; import { useObservableMemo } from "applesauce-react/hooks"; import { getDisplayName } from "@/lib/nostr-utils"; import { useGrimoire } from "@/core/state"; +import { useAppShell } from "@/components/layouts/AppShellContext"; import { Button } from "@/components/ui/button"; import { DropdownMenu, @@ -21,6 +22,7 @@ import Nip05 from "./nip05"; import { RelayLink } from "./RelayLink"; import SettingsDialog from "@/components/SettingsDialog"; import { useState } from "react"; +import type { IAccount } from "applesauce-accounts"; function UserAvatar({ pubkey }: { pubkey: string }) { const profile = useProfile(pubkey); @@ -53,10 +55,15 @@ function UserLabel({ pubkey }: { pubkey: string }) { export default function UserMenu() { const account = useObservableMemo(() => accounts.active$, []); + const allAccounts = useObservableMemo(() => accounts.accounts$, []); const { state, addWindow } = useGrimoire(); + const { openCommandLauncher } = useAppShell(); const relays = state.activeAccount?.relays; const [showSettings, setShowSettings] = useState(false); + // Get other accounts (not the active one) + const otherAccounts = allAccounts.filter((acc) => acc.id !== account?.id); + function openProfile() { if (!account?.pubkey) return; addWindow( @@ -78,6 +85,15 @@ export default function UserMenu() { } } + function switchAccount(targetAccount: IAccount) { + accounts.setActive(targetAccount.id); + } + + function addAccount() { + // Open the command launcher (user will type "login" command) + openCommandLauncher(); + } + async function logout() { if (!account) return; accounts.removeAccount(account); @@ -103,15 +119,54 @@ export default function UserMenu() { {account ? ( <> + {/* Active Account */} - +
+ + +
+ {/* Other Accounts */} + {otherAccounts.length > 0 && ( + <> + + + + Switch Account + + {otherAccounts.map((acc) => ( + switchAccount(acc)} + className="cursor-crosshair" + > +
+ + +
+
+ ))} +
+ + )} + + {/* Add Account */} + + + + Add account + + + {/* Relays */} {relays && relays.length > 0 && ( <> @@ -134,15 +189,8 @@ export default function UserMenu() { )} + {/* Logout */} - {/* setShowSettings(true)} - className="cursor-pointer" - > - - Settings - - */} Log out