"use client"; import { useEditor, EditorContent } from "@tiptap/react"; import StarterKit from "@tiptap/starter-kit"; import Highlight from "@tiptap/extension-highlight"; import TextAlign from "@tiptap/extension-text-align"; import { Markdown } from "@tiptap/markdown"; import { HomelabApp } from "@/types"; import { invoke } from "@tauri-apps/api/core"; import { useEffect, useState } from "react"; import Menubar from "./menu-bar"; // Added menubar import back interface TextEditorProps { content: string; onSave: (content: string, linkedAppIds: string[]) => void; initialLinkedAppIds?: string[]; } const getApps = async (): Promise => { return (await invoke("get_app")) as HomelabApp[]; }; export default function TextEditor({ content, onSave, initialLinkedAppIds = [], }: TextEditorProps) { const [availableApps, setAvailableApps] = useState([]); const [linkedAppIds, setLinkedAppIds] = useState(initialLinkedAppIds); // 🔄 FIX: Watch for updates to initialLinkedAppIds once fetched from the URL useEffect(() => { if (initialLinkedAppIds.length > 0) { setLinkedAppIds(initialLinkedAppIds); } }, [initialLinkedAppIds]); useEffect(() => { const fetchApps = async () => { const apps = await getApps(); setAvailableApps(apps); }; fetchApps(); }, []); // ... rest of your TextEditor component stays the same const editor = useEditor({ extensions: [ StarterKit.configure({ bulletList: { HTMLAttributes: { class: "list-disc ml-3" } }, orderedList: { HTMLAttributes: { class: "list-decimal ml-3" } }, }), Highlight.configure({ HTMLAttributes: { class: "bg-yellow-200" } }), TextAlign.configure({ types: ["heading", "paragraph"] }), Markdown, ], immediatelyRender: false, content: content || "

Start typing your documentation notes here...

", editorProps: { attributes: { class: "prose max-w-none focus:outline-none min-h-[300px]", }, }, }); const toggleAppLink = (appId: string) => { setLinkedAppIds( (prev) => prev.includes(appId) ? prev.filter((id) => id !== appId) // Unlink if already added : [...prev, appId], // Link if not added ); }; const handleSave = () => { if (!editor) return; const htmlOutput = editor.getHTML(); // Pass both the layout structure and the entire linked app set onSave(htmlOutput, linkedAppIds); }; return (
{/* Top action bar */}
Draft Session
{/* Editor Controls */} {/* Main split-view workspace */}
{/* Left Side: Text Canvas */}
{/* Right Side: Document-Wide Reference Panel */}

Document Assets

Click apps to bind/unbind them to this entire document.

{availableApps.map((app) => { const isLinked = linkedAppIds.includes(app.id); return ( ); })}
); }