Skip to content

Commit

Permalink
online/offline event works
Browse files Browse the repository at this point in the history
  • Loading branch information
sammynave committed Jan 5, 2024
1 parent 670b963 commit 2bac4ee
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/routes/app/offline-first/sync-db-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
// });
});
});

Expand Down

0 comments on commit 2bac4ee

Please sign in to comment.