From 6e8fa6d7571be286c085d22a5c95be2ece639f6e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 21 Dec 2024 17:42:48 +0200 Subject: [PATCH] chore(client/ts): port services/file_watcher --- src/public/app/components/app_context.ts | 6 ++++++ .../{file_watcher.js => file_watcher.ts} | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) rename src/public/app/services/{file_watcher.js => file_watcher.ts} (66%) diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts index 36ebb2d17..5303acd08 100644 --- a/src/public/app/components/app_context.ts +++ b/src/public/app/components/app_context.ts @@ -50,6 +50,12 @@ export type TriggerData = { branchIdsToDelete: string[]; callback: (value: ResolveOptions) => void; forceDeleteAllClones: boolean; +} | { + // For "openedFileUpdated" + entityType: string; + entityId: string; + lastModifiedMs: number; + filePath: string; } | PromptDialogOptions // For "showPromptDialog" | ConfirmWithMessageOptions // For "showConfirmDialog" diff --git a/src/public/app/services/file_watcher.js b/src/public/app/services/file_watcher.ts similarity index 66% rename from src/public/app/services/file_watcher.js rename to src/public/app/services/file_watcher.ts index a0db524cc..0f9ec3bb5 100644 --- a/src/public/app/services/file_watcher.js +++ b/src/public/app/services/file_watcher.ts @@ -1,36 +1,45 @@ import ws from "./ws.js"; import appContext from "../components/app_context.js"; -const fileModificationStatus = { +// TODO: Deduplicate +interface Message { + type: string; + entityType: string; + entityId: string; + lastModifiedMs: number; + filePath: string; +} + +const fileModificationStatus: Record> = { notes: {}, attachments: {} }; -function checkType(type) { +function checkType(type: string) { if (type !== 'notes' && type !== 'attachments') { throw new Error(`Unrecognized type '${type}', should be 'notes' or 'attachments'`); } } -function getFileModificationStatus(entityType, entityId) { +function getFileModificationStatus(entityType: string, entityId: string) { checkType(entityType); return fileModificationStatus[entityType][entityId]; } -function fileModificationUploaded(entityType, entityId) { +function fileModificationUploaded(entityType: string, entityId: string) { checkType(entityType); delete fileModificationStatus[entityType][entityId]; } -function ignoreModification(entityType, entityId) { +function ignoreModification(entityType: string, entityId: string) { checkType(entityType); delete fileModificationStatus[entityType][entityId]; } -ws.subscribeToMessages(async message => { +ws.subscribeToMessages(async (message: Message) => { if (message.type !== 'openedFileUpdated') { return; }