diff --git a/src/lib/api/apiStore.ts b/src/lib/api/apiStore.ts index 6cb8c87b..a28dfd7d 100644 --- a/src/lib/api/apiStore.ts +++ b/src/lib/api/apiStore.ts @@ -90,7 +90,7 @@ export function updateUserInfo(state: AuthorizerState) { export const documentStore = writable([]); export const assignmentStore = writable([]); -export const currentFile = writable(null); +export const currentFile = writable(null); interface userInfo { name: string; diff --git a/src/routes/workspace/editor/+page.svelte b/src/routes/workspace/editor/+page.svelte index e4f368e1..634628dc 100644 --- a/src/routes/workspace/editor/+page.svelte +++ b/src/routes/workspace/editor/+page.svelte @@ -8,7 +8,7 @@ import type { AuthorizerState } from 'akademia-authorizer-svelte/types'; import type { Editor } from 'svelte-tiptap'; import { goto } from '$app/navigation'; - import { currentFile } from '@/api/apiStore'; + import { currentFile, FileInfo } from '@/api/apiStore'; let editor: Readable; const api = new ApiHandler(>getContext('authorizerContext')); @@ -23,7 +23,7 @@ api.getDocument(id || '').then((file) => { if (!file) return; file.json().then((fileContent) => { - currentFile.set(fileContent); + currentFile.set(new FileInfo(fileContent)); }); }); diff --git a/src/routes/workspace/editor/Tiptap.svelte b/src/routes/workspace/editor/Tiptap.svelte index 5ff995cc..86da8afa 100644 --- a/src/routes/workspace/editor/Tiptap.svelte +++ b/src/routes/workspace/editor/Tiptap.svelte @@ -100,10 +100,10 @@ // console.log('too', transaction); if (!transaction.isGeneric) return; - const title = + const title: string = transaction.doc.content.content[0].content.content[0]?.text || 'Uden titel'; if (title && title !== currentFileName) { - $currentFile.rename(title, api); + $currentFile instanceof FileInfo && $currentFile.rename(title, api); currentFileName = title; if ($currentFile != null) { diff --git a/src/routes/workspace/editor/Toolbar/MoreActions.svelte b/src/routes/workspace/editor/Toolbar/MoreActions.svelte index 815fdd2b..a0df2ee8 100644 --- a/src/routes/workspace/editor/Toolbar/MoreActions.svelte +++ b/src/routes/workspace/editor/Toolbar/MoreActions.svelte @@ -5,15 +5,15 @@ import { MoreHorizontal, Trash2, LogOut, Download, Printer } from 'lucide-svelte'; import { getContext } from 'svelte'; import type ApiHandler from '@/api'; - import { currentFile, documentStore } from '@/api/apiStore'; + import { FileInfo, currentFile, documentStore } from '@/api/apiStore'; import { printUsingWindow } from '@/utils/printer'; let isDeleteOpen = false; const api = getContext('api') as ApiHandler; function deleteActiveFile() { - const id = $currentFile?.id; - if (!id) return; - api.deleteDocument(id).then((response) => { + console.log($currentFile); + if (!($currentFile instanceof FileInfo)) return; + $currentFile.delete(api).then((response) => { if (!response || response.status !== 200) return; console.log(response); documentStore.update((prev) => prev.filter((it) => it !== $currentFile));