"use client"; import { useSearchParams } from "next/navigation"; import { useEffect, useState } from "react"; import { invoke } from "@tauri-apps/api/core"; import Link from "next/link"; import { HomelabApp, Blog } from "@/types"; export default function WritePage() { const params = useSearchParams(); const blogId = params.get("id") || null; if (!blogId) { return (
No document ID provided.
); } const [blog, setBlog] = useState(null); const [linkedApps, setLinkedApps] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { if (!blogId) return; const fetchBlogAndApps = async () => { try { setLoading(true); const currentBlog = (await invoke("get_blog", { id: blogId })) as | Blog | undefined; if (!currentBlog) { setError("Blog post not found."); return; } setBlog(currentBlog); // 2. Fetch the metadata for any bound/linked apps if they exist if (currentBlog.reference && currentBlog.reference.length > 0) { const apps = (await invoke("get_apps_by_id", { ids: currentBlog.reference, })) as HomelabApp[]; setLinkedApps(apps); } } catch (err) { console.error("Failed to load blog page data:", err); setError("An error occurred while loading the document."); } finally { setLoading(false); } }; fetchBlogAndApps(); }, [blogId]); if (loading) { return (
Loading document...
); } if (error || !blog) { return (

{error || "Something went wrong."}

Go Back Home
); } return (
{/* Top Header Controls */}

{blog.title || "Untitled Document"}

Edit Document
{/* Main Reading Workspace Layout */}
{/* Left Side: Styled Canvas Viewport */}
{/* Using your exact editor style class 'prose max-w-none' to ensure uniform markdown formatting */}
{/* Right Side: Associated Connected Homelab Apps */} {linkedApps.length > 0 && (

Linked Assets

Infrastructure context bound to this document.

{linkedApps.map((app) => (
{app.name}
{app.address}
{app.description && (
{app.description}
)}
))}
)}
); }