chore: remove unused LoginHandler and LogoutHandler components

This commit is contained in:
Claude
2026-01-05 16:21:05 +00:00
parent 80aa5c9adb
commit f45acd3518
2 changed files with 0 additions and 190 deletions

View File

@@ -1,95 +0,0 @@
import { useEffect } from "react";
import { toast } from "sonner";
import { Check, X, Info } from "lucide-react";
import type { ReadOnlyAccount } from "@/lib/account-types";
import accountManager from "@/services/accounts";
interface LoginHandlerProps {
action: "add-account" | "error" | "open-dialog";
account?: ReadOnlyAccount;
message?: string;
}
/**
* LoginHandler - Executes login command actions
*
* This component handles the result of the /login command:
* - add-account: Adds account to AccountManager and sets as active
* - error: Shows error toast
* - open-dialog: Shows info about opening login dialog (UI coming soon)
*/
export default function LoginHandler({
action,
account,
message,
}: LoginHandlerProps) {
useEffect(() => {
const handleAction = async () => {
switch (action) {
case "add-account":
if (!account) {
toast.error("Failed to add account", {
description: "No account provided",
icon: <X className="h-4 w-4" />,
});
return;
}
try {
// Add account to manager
accountManager.addAccount(account);
// Set as active account
accountManager.setActive(account.id);
// Show success toast
toast.success("Account added successfully", {
description: `Logged in as ${account.pubkey.slice(0, 8)}...${account.pubkey.slice(-8)}`,
icon: <Check className="h-4 w-4" />,
});
} catch (error) {
toast.error("Failed to add account", {
description:
error instanceof Error ? error.message : "Unknown error",
icon: <X className="h-4 w-4" />,
});
}
break;
case "error":
toast.error("Login failed", {
description: message || "Unknown error occurred",
icon: <X className="h-4 w-4" />,
});
break;
case "open-dialog":
toast.info("Login dialog", {
description:
"Login dialog UI coming soon. For now, use: login <npub|nip-05|hex|nprofile>",
icon: <Info className="h-4 w-4" />,
duration: 5000,
});
break;
default:
toast.error("Unknown action", {
description: `Unhandled action: ${action}`,
icon: <X className="h-4 w-4" />,
});
}
};
handleAction();
}, [action, account, message]);
// This component doesn't render anything visible - it just executes the action
return (
<div className="flex items-center justify-center h-full w-full p-8">
<div className="text-center text-muted-foreground space-y-2">
<p className="text-sm">Processing login...</p>
<p className="text-xs">This window can be closed.</p>
</div>
</div>
);
}

View File

@@ -1,95 +0,0 @@
import { useEffect } from "react";
import { toast } from "sonner";
import { LogOut } from "lucide-react";
import accountManager from "@/services/accounts";
import { useObservableMemo } from "applesauce-react/hooks";
interface LogoutHandlerProps {
action: "logout" | "logout-all";
all: boolean;
}
/**
* LogoutHandler - Executes logout command actions
*
* This component handles the result of the /logout command:
* - logout: Removes the active account
* - logout-all: Removes all accounts
*/
export default function LogoutHandler({ action, all }: LogoutHandlerProps) {
const activeAccount = useObservableMemo(() => accountManager.active$, []);
const allAccounts = useObservableMemo(() => accountManager.accounts$, []);
useEffect(() => {
const handleLogout = () => {
if (action === "logout-all" || all) {
// Remove all accounts
if (allAccounts.length === 0) {
toast.info("No accounts to remove", {
icon: <LogOut className="h-4 w-4" />,
});
return;
}
const confirmLogoutAll = window.confirm(
`Remove all ${allAccounts.length} account(s)? This cannot be undone.`,
);
if (!confirmLogoutAll) {
toast.info("Logout cancelled", {
icon: <LogOut className="h-4 w-4" />,
});
return;
}
// Remove all accounts
allAccounts.forEach((account) => {
accountManager.removeAccount(account);
});
toast.success("All accounts removed", {
description: `Removed ${allAccounts.length} account(s)`,
icon: <LogOut className="h-4 w-4" />,
});
} else {
// Remove only active account
if (!activeAccount) {
toast.info("No active account to remove", {
description: "You are not logged in",
icon: <LogOut className="h-4 w-4" />,
});
return;
}
// If there are other accounts, switch to the first one before removing current
const otherAccounts = allAccounts.filter(
(acc) => acc.id !== activeAccount.id,
);
if (otherAccounts.length > 0) {
accountManager.setActive(otherAccounts[0].id);
}
// Remove the account
accountManager.removeAccount(activeAccount);
toast.success("Logged out", {
description: `Removed ${activeAccount.pubkey.slice(0, 8)}...${activeAccount.pubkey.slice(-8)}`,
icon: <LogOut className="h-4 w-4" />,
});
}
};
handleLogout();
}, [action, all, activeAccount, allAccounts]);
// This component doesn't render anything visible - it just executes the action
return (
<div className="flex items-center justify-center h-full w-full p-8">
<div className="text-center text-muted-foreground space-y-2">
<LogOut className="size-8 mx-auto mb-4 opacity-20" />
<p className="text-sm">Processing logout...</p>
<p className="text-xs">This window can be closed.</p>
</div>
</div>
);
}