From 2bac4ee4a1f22c1915ca68ae7a950e2c7ffef84d Mon Sep 17 00:00:00 2001 From: Sammy Nave Date: Fri, 5 Jan 2024 17:05:15 -0500 Subject: [PATCH] online/offline event works --- src/routes/app/offline-first/sync-db-store.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/routes/app/offline-first/sync-db-store.ts b/src/routes/app/offline-first/sync-db-store.ts index 292f24b..6b03613 100644 --- a/src/routes/app/offline-first/sync-db-store.ts +++ b/src/routes/app/offline-first/sync-db-store.ts @@ -108,20 +108,22 @@ export function db({ databasePromise, wsPromise, serverSiteId, name }) { } }); databasePromise.then(async (database) => { + // NOTE: this is really hard to test locally since you can be offline but still hit the dev server. + // But it works when you are offline then go back online! + + // TODO + // TODO + // TODO + // TODO + // We need more logic to handle when the server is down/unreachable but the client isn't offline. + // TODO + // TODO + // TODO + // TODO + const ws = await wsPromise; globalThis.addEventListener('online', async (event) => { - // Request update ws.send(JSON.stringify({ type: 'connected', siteId: database.siteId })); - - // // Send update - // const result = await database.lastTrackedChangeFor(serverSiteId, 1); - // const trackedVersion = result?.[0]?.[0] ?? 0; - // await pushChangesSince({ - // database, - // ws, - // sinceVersion: trackedVersion, - // serverSiteId - // }); }); });