saving might work idk
This commit is contained in:
+31
-5
@@ -6,6 +6,13 @@ import { invoke } from "@tauri-apps/api/core";
|
||||
import TextEditor from "@/components/text-editor";
|
||||
import { HomelabApp } from "@/types";
|
||||
|
||||
// Create a type for the Blog returned by your Rust backend
|
||||
interface Blog {
|
||||
id: string;
|
||||
title: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
function WritePageContent() {
|
||||
const searchParams = useSearchParams();
|
||||
const appQuery = searchParams.get("app");
|
||||
@@ -13,6 +20,9 @@ function WritePageContent() {
|
||||
const [initialAppIds, setInitialAppIds] = useState<string[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// Track the document ID to allow updating instead of duplicating
|
||||
const [documentId, setDocumentId] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const checkQueryParam = async () => {
|
||||
if (!appQuery) {
|
||||
@@ -23,7 +33,6 @@ function WritePageContent() {
|
||||
try {
|
||||
const apps = (await invoke("get_app")) as HomelabApp[];
|
||||
|
||||
// Match checking both UUID structure and sanitized string names
|
||||
const matchedApp = apps.find(
|
||||
(app) =>
|
||||
app.id === appQuery ||
|
||||
@@ -46,9 +55,27 @@ function WritePageContent() {
|
||||
checkQueryParam();
|
||||
}, [appQuery]);
|
||||
|
||||
const onSave = (content: string, linkedAppIds: string[]) => {
|
||||
console.log("Document Rich Text: ", content);
|
||||
console.log("Document Bound App IDs: ", linkedAppIds);
|
||||
// Updated onSave signature matching what TextEditor emits
|
||||
const onSave = async (
|
||||
content: string,
|
||||
linkedAppIds: string[],
|
||||
title: string,
|
||||
) => {
|
||||
try {
|
||||
const savedBlog = await invoke<Blog>("save_blog", {
|
||||
id: documentId,
|
||||
title: title || "Untitled Document",
|
||||
content: content,
|
||||
linkedAppIds: linkedAppIds,
|
||||
});
|
||||
|
||||
// Update state with the backend-generated/returned ID
|
||||
if (savedBlog && savedBlog.id) {
|
||||
setDocumentId(savedBlog.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to save document:", error);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
@@ -66,7 +93,6 @@ function WritePageContent() {
|
||||
);
|
||||
}
|
||||
|
||||
// 2. Main Page export wrapped in a Suspense boundary
|
||||
export default function WritePage() {
|
||||
return (
|
||||
<div className="flex flex-col p-2">
|
||||
|
||||
Reference in New Issue
Block a user