Skip to content

Commit

Permalink
refactor rename document to be on class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ell1ott committed Feb 28, 2024
1 parent f605170 commit 5d93865
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/lib/api/apiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export class FileInfo {
created_at: string;
updated_at: string;

apiPath: string = '/documents/';

rename(newName: string, api: ApiHandler) {
return api.callApi(this.apiPath + this.id, { name: newName }, 'PUT');
}

constructor(info) {
this.id = info.id;
this.name = info.name;
Expand All @@ -20,6 +26,8 @@ export class FileInfo {
}

export class DocumentInfo extends FileInfo {
apiPath: string = '/documents/';

constructor(info) {
super(info);
}
Expand All @@ -36,6 +44,8 @@ export class Assignment extends FileInfo {
due_date: string;
progress: AssignmentProgress;

apiPath = '/assignments/';

constructor(info) {
super(info);
this.due_date = info.due_date;
Expand Down
4 changes: 0 additions & 4 deletions src/lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ export default class ApiHandler {
);
};

renameDocument = this.debounce((documentId: string, documentName: string) => {
this.callApi('/documents/' + documentId, { name: documentName }, 'PUT');
}, 350);

deleteDocument = (documentId: string) => {
return this.callApi('/documents/' + documentId, {}, 'DELETE');
};
Expand Down
8 changes: 4 additions & 4 deletions src/routes/workspace/editor/Tiptap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@
const title =
transaction.doc.content.content[0].content.content[0]?.text || 'Uden titel';
if (title && title !== currentFileName) {
api.renameDocument(initcurrentFile.id, title);
$currentFile.rename(title, api);
currentFileName = title;
if ($currentFile != null) {
const newState: FileInfo = { ...$currentFile };
newState['name'] = title;
const id = $currentFile.id;
const newState: FileInfo = $currentFile;
newState.name = title;
const id = newState.id;
// Update the value for the specified key
documentStore.update((prev: FileInfo[]): FileInfo[] => {
return prev.map((it) => {
Expand Down

0 comments on commit 5d93865

Please sign in to comment.