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" export function CustomToolbar() { const editor = useEditor() const tools = useTools() const [isReady, setIsReady] = useState(false) const [hasApiKey, setHasApiKey] = useState(false) const { addDialog, removeDialog } = useDialogs() useEffect(() => { if (editor && tools) { setIsReady(true) } }, [editor, tools]) const checkApiKeys = () => { const settings = localStorage.getItem("openai_api_key") try { if (settings) { try { const { keys } = JSON.parse(settings) const hasValidKey = keys && Object.values(keys).some(key => typeof key === 'string' && key.trim() !== '') setHasApiKey(hasValidKey) } catch (e) { 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) }, []) if (!isReady) return null return (
{tools["VideoChat"] && ( )} {tools["ChatBox"] && ( )} {tools["Embed"] && ( )} {tools["SlideShape"] && ( )} {tools["Markdown"] && ( )} {tools["MycrozineTemplate"] && ( )} {tools["Prompt"] && ( )} {tools["Holon"] && ( )}
) }