import { TldrawUiMenuItem } from "tldraw" import { DefaultToolbar, DefaultToolbarContent } from "tldraw" import { useTools } from "tldraw" import { useEditor } from "tldraw" import { useState, useEffect } from "react" import { useDialogs } from "tldraw" import { SettingsDialog } from "./SettingsDialog" import { useAuth } from "../context/AuthContext" import LoginButton from "../components/auth/LoginButton" import StarBoardButton from "../components/StarBoardButton" export function CustomToolbar() { const editor = useEditor() const tools = useTools() const [isReady, setIsReady] = useState(false) const [hasApiKey, setHasApiKey] = useState(false) const { addDialog, removeDialog } = useDialogs() const { session, setSession, clearSession } = useAuth() const [showProfilePopup, setShowProfilePopup] = useState(false) useEffect(() => { if (editor && tools) { setIsReady(true) } }, [editor, tools]) const checkApiKeys = () => { const settings = localStorage.getItem("openai_api_key") try { if (settings) { try { const parsed = JSON.parse(settings) if (parsed.keys) { // New format with multiple providers const hasValidKey = Object.values(parsed.keys).some(key => typeof key === 'string' && key.trim() !== '' ) setHasApiKey(hasValidKey) } else { // Old format - single string const hasValidKey = typeof settings === 'string' && settings.trim() !== '' setHasApiKey(hasValidKey) } } catch (e) { // Fallback to old format const hasValidKey = typeof settings === 'string' && settings.trim() !== '' setHasApiKey(hasValidKey) } } else { setHasApiKey(false) } } catch (e) { setHasApiKey(false) } } // Initial check useEffect(() => { checkApiKeys() }, []) // Periodic check useEffect(() => { const interval = setInterval(checkApiKeys, 5000) return () => clearInterval(interval) }, []) const handleLogout = () => { // Clear the session clearSession() // Close the popup setShowProfilePopup(false) } const openApiKeysDialog = () => { addDialog({ id: "api-keys", component: ({ onClose }: { onClose: () => void }) => ( { onClose() removeDialog("api-keys") checkApiKeys() // Refresh API key status }} /> ), }) } if (!isReady) return null return (
{session.authed && (
{showProfilePopup && (
Hello, {session.username}!
{/* API Key Status */}
AI API Keys {hasApiKey ? "✅ Configured" : "❌ Not configured"}

{hasApiKey ? "Your AI models are ready to use" : "Configure API keys to use AI features" }

{ e.currentTarget.style.backgroundColor = "#2563EB" }} onMouseLeave={(e) => { e.currentTarget.style.backgroundColor = "#3B82F6" }} > My Dashboard {!session.backupCreated && (
Remember to back up your encryption keys to prevent data loss!
)}
)}
)}
{tools["VideoChat"] && ( )} {tools["ChatBox"] && ( )} {tools["Embed"] && ( )} {tools["SlideShape"] && ( )} {tools["Markdown"] && ( )} {tools["MycrozineTemplate"] && ( )} {tools["Prompt"] && ( )} {tools["SharedPiano"] && ( )}
) }