refactor: move from next js to vite and tanstack router

This commit is contained in:
Kacper
2025-12-17 20:11:16 +01:00
parent 9954feafd8
commit 5136c32b68
263 changed files with 11148 additions and 10276 deletions

View File

@@ -0,0 +1,58 @@
import { useState, useCallback } from "react";
import { toast } from "sonner";
import { getElectronAPI } from "@/lib/electron";
interface UseTokenSaveOptions {
provider: string; // e.g., "anthropic_oauth_token", "anthropic", "openai"
onSuccess?: () => void;
}
export function useTokenSave({ provider, onSuccess }: UseTokenSaveOptions) {
const [isSaving, setIsSaving] = useState(false);
const saveToken = useCallback(
async (tokenValue: string) => {
if (!tokenValue.trim()) {
toast.error("Please enter a valid token");
return false;
}
setIsSaving(true);
try {
const api = getElectronAPI();
const setupApi = api.setup;
if (setupApi?.storeApiKey) {
const result = await setupApi.storeApiKey(provider, tokenValue);
console.log(`[Token Save] Store result for ${provider}:`, result);
if (result.success) {
const tokenType = provider.includes("oauth")
? "subscription token"
: "API key";
toast.success(`${tokenType} saved successfully`);
onSuccess?.();
return true;
} else {
toast.error("Failed to save token", { description: result.error });
return false;
}
} else {
// Web mode fallback - just show success
toast.success("Token saved");
onSuccess?.();
return true;
}
} catch (error) {
console.error(`[Token Save] Failed to save ${provider}:`, error);
toast.error("Failed to save token");
return false;
} finally {
setIsSaving(false);
}
},
[provider, onSuccess]
);
return { isSaving, saveToken };
}