Skip to content

Commit

Permalink
fix problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Ell1ott committed Feb 28, 2024
1 parent 85e831a commit f605170
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions src/routes/workspace/editor/Tiptap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import Document from '@tiptap/extension-document';
import Placeholder from '@tiptap/extension-placeholder';
import { Title } from '$lib/editor/extensions/title';
import { activeFile } from '../../store';
import { fileStore, type FileInfo } from '@/api/apiStore';
import { editor } from './editorStore';
import { FileInfo, currentFile, documentStore } from '@/api/apiStore';
let state: AuthorizerState;
Expand All @@ -32,17 +31,17 @@
let provider: HocuspocusProvider;
$: if ($activeFile) initializeTiptap($activeFile);
$: if ($currentFile) initializeTiptap($currentFile);
// this is needed
let activeFileName = '';
$: activeFileName = $activeFile?.name || '';
let currentFileName = '';
$: currentFileName = $currentFile?.name || '';
function initializeTiptap(initActiveFile: FileInfo | null) {
if (!initActiveFile) {
function initializeTiptap(initcurrentFile: FileInfo | null) {
if (!initcurrentFile) {
return;
}
console.log('Initializing tiptap', initActiveFile);
console.log('Initializing tiptap', initcurrentFile);
if ($editor) {
$editor.destroy();
}
Expand All @@ -56,7 +55,7 @@
provider = new HocuspocusProvider({
url: 'wss://akademia-backend.arctix.dev',
token: state.token.access_token,
name: 'document.' + initActiveFile.id,
name: 'document.' + initcurrentFile.id,
onAuthenticationFailed: () => {
$editor.destroy();
provider.destroy();
Expand Down Expand Up @@ -103,16 +102,16 @@
const title =
transaction.doc.content.content[0].content.content[0]?.text || 'Uden titel';
if (title && title !== activeFileName) {
api.renameDocument(initActiveFile.id, title);
if (title && title !== currentFileName) {
api.renameDocument(initcurrentFile.id, title);
activeFileName = title;
if ($activeFile != null) {
const newState: FileInfo = { ...$activeFile };
currentFileName = title;
if ($currentFile != null) {
const newState: FileInfo = { ...$currentFile };
newState['name'] = title;
const id = $activeFile.id;
const id = $currentFile.id;
// Update the value for the specified key
fileStore.update((prev: FileInfo[]): FileInfo[] => {
documentStore.update((prev: FileInfo[]): FileInfo[] => {
return prev.map((it) => {
if (it.id == id) return newState;
return it;
Expand Down Expand Up @@ -155,7 +154,7 @@
}
onMount(() => {
initializeTiptap($activeFile);
initializeTiptap($currentFile);
});
onDestroy(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/workspace/editor/Toolbar/ShareDocument.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { Separator } from '$lib/components/ui/separator';
import { getContext, onMount } from 'svelte';
import type ApiHandler from '@/api';
import type { FileInfo, currentFile } from '@/api/apiStore';
import { type FileInfo, currentFile } from '@/api/apiStore';
const api = getContext('api') as ApiHandler;
Expand Down

0 comments on commit f605170

Please sign in to comment.