From 8b22549f5e6bd7d01b879a6d85a4a5c157a10078 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 11 May 2025 22:24:43 +0100 Subject: [PATCH] Expose sync status per file --- frontend/sync-client/src/index.ts | 3 ++- frontend/sync-client/src/sync-client.ts | 21 +++++++++++++------ .../src/types/document-update-status.ts | 4 ++++ .../src/types/network-connection-status.ts | 5 +++++ 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 frontend/sync-client/src/types/document-update-status.ts create mode 100644 frontend/sync-client/src/types/network-connection-status.ts diff --git a/frontend/sync-client/src/index.ts b/frontend/sync-client/src/index.ts index e5760ea..38d11ec 100644 --- a/frontend/sync-client/src/index.ts +++ b/frontend/sync-client/src/index.ts @@ -15,5 +15,6 @@ export type { } from "./file-operations/filesystem-operations"; export type { PersistenceProvider } from "./persistence/persistence"; -export type { NetworkConnectionStatus } from "./sync-client"; +export type { NetworkConnectionStatus } from "./types/network-connection-status"; +export { DocumentUpdateStatus } from "./types/document-update-status"; export { SyncClient } from "./sync-client"; diff --git a/frontend/sync-client/src/sync-client.ts b/frontend/sync-client/src/sync-client.ts index ab1cd76..e64ea6d 100644 --- a/frontend/sync-client/src/sync-client.ts +++ b/frontend/sync-client/src/sync-client.ts @@ -16,12 +16,8 @@ import { ConnectionStatus } from "./services/connection-status"; import { UnrestrictedSyncer } from "./sync-operations/unrestricted-syncer"; import { rateLimit } from "./utils/rate-limit"; import { v4 as uuidv4 } from "uuid"; - -export interface NetworkConnectionStatus { - isSuccessful: boolean; - serverMessage: string; - isWebSocketConnected: boolean; -} +import { NetworkConnectionStatus } from "./types/network-connection-status"; +import { DocumentUpdateStatus } from "./types/document-update-status"; export class SyncClient { private static readonly MINIMUM_SAVE_INTERVAL_MS = 1000; @@ -260,4 +256,17 @@ export class SyncClient { relativePath }); } + + public getDocumentSyncingStatus( + relativePath: RelativePath + ): DocumentUpdateStatus { + const document = + this.database.getLatestDocumentByRelativePath(relativePath); + if (document === undefined) { + return DocumentUpdateStatus.SYNCING; + } + return document.updates.length > 0 + ? DocumentUpdateStatus.SYNCING + : DocumentUpdateStatus.UP_TO_DATE; + } } diff --git a/frontend/sync-client/src/types/document-update-status.ts b/frontend/sync-client/src/types/document-update-status.ts new file mode 100644 index 0000000..7fa1c88 --- /dev/null +++ b/frontend/sync-client/src/types/document-update-status.ts @@ -0,0 +1,4 @@ +export enum DocumentUpdateStatus { + UP_TO_DATE = "UP_TO_DATE", + SYNCING = "SYNCING" +} diff --git a/frontend/sync-client/src/types/network-connection-status.ts b/frontend/sync-client/src/types/network-connection-status.ts new file mode 100644 index 0000000..fb93f5f --- /dev/null +++ b/frontend/sync-client/src/types/network-connection-status.ts @@ -0,0 +1,5 @@ +export interface NetworkConnectionStatus { + isSuccessful: boolean; + serverMessage: string; + isWebSocketConnected: boolean; +}