Skip to content

Commit

Permalink
fix currentFile not being FileInfo
Browse files Browse the repository at this point in the history
...when initing it from the url
  • Loading branch information
Ell1ott committed Feb 28, 2024
1 parent 85253be commit 1273735
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lib/api/apiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function updateUserInfo(state: AuthorizerState) {
export const documentStore = writable<DocumentInfo[]>([]);
export const assignmentStore = writable<Assignment[]>([]);

export const currentFile = writable<FileInfo | null>(null);
export const currentFile = writable<FileInfo>(null);

interface userInfo {
name: string;
Expand Down
4 changes: 2 additions & 2 deletions src/routes/workspace/editor/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<Editor>;
const api = new ApiHandler(<Readable<AuthorizerState>>getContext('authorizerContext'));
Expand All @@ -23,7 +23,7 @@
api.getDocument(id || '').then((file) => {
if (!file) return;
file.json().then((fileContent) => {
currentFile.set(fileContent);
currentFile.set(new FileInfo(fileContent));
});
});
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/workspace/editor/Tiptap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/routes/workspace/editor/Toolbar/MoreActions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 1273735

Please sign in to comment.