From 36d97c9ecaec531268c657fd7bc8fab3038f8d11 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Mon, 2 Nov 2020 11:16:46 -0600 Subject: [PATCH] Finalize support for offline/online sync logic --- src/app/service/api.service.ts | 16 ++++++++++++++-- src/app/service/db/Page.ts | 2 -- src/app/service/editor.service.ts | 3 --- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/app/service/api.service.ts b/src/app/service/api.service.ts index 56ecd68..e104355 100644 --- a/src/app/service/api.service.ts +++ b/src/app/service/api.service.ts @@ -202,15 +202,27 @@ export class ApiService { public async syncOfflineData() { const dirtyRecords = await this.db.getDirtyRecords(); - await new Promise(async (res, rej) => { + const uuidMap = await new Promise(async (res, rej) => { this.post('/offline/sync', { dirtyRecords }).subscribe({ next: async result => { console.log('sync result', result); - res(); + res(result.data); }, error: rej, }); }); + + // For now, we're not going to handle this great. + // Rather, we're going to wait until the server supports proper versioning and date-based offline updates. + // In the meantime, just purge everything and reload. + await this.prefetchOfflineData(true); + + const offlineKV = await this.db.getKeyValue('needs_online_sync'); + offlineKV.data = false; + await offlineKV.save(); + + // Pre-fetch menu items + await this.getMenuItems(); } public async prefetchOfflineData(overwriteLocalData = false) { diff --git a/src/app/service/db/Page.ts b/src/app/service/db/Page.ts index d298402..1c257d5 100644 --- a/src/app/service/db/Page.ts +++ b/src/app/service/db/Page.ts @@ -109,7 +109,6 @@ export class Page extends Model implements IPage { } public fillFromRecord(record: any) { - console.log('page fill from record', record); this.UUID = record.UUID; this.Name = record.Name; this.OrgUserId = record.OrgUserId; @@ -117,7 +116,6 @@ export class Page extends Model implements IPage { this.IsVisibleInMenu = record.IsVisibleInMenu; this.ParentId = record.ParentId; this.NodeIds = record.NodeIds; - console.log('setting node ids', this.NodeIds, record.NodeIds); this.CreatedAt = String(record.CreatedAt); this.UpdatedAt = String(record.UpdatedAt); this.Active = record.Active; diff --git a/src/app/service/editor.service.ts b/src/app/service/editor.service.ts index 0310bcc..97aec64 100644 --- a/src/app/service/editor.service.ts +++ b/src/app/service/editor.service.ts @@ -168,7 +168,6 @@ export class EditorService { } async savePage(page: PageRecord): Promise { - console.log('saving page', page); await new Promise(async (res, rej) => { const existingLocalPage = await this.db.pages.where({ UUID: page.UUID }).first() as Page; const saveData = page.toSave(); @@ -381,7 +380,6 @@ export class EditorService { if ( localPage ) { localPage.NodeIds.push(result.data.UUID); - console.log('saving local page data', result.data.UUID); await localPage.save(); } @@ -446,7 +444,6 @@ export class EditorService { baseHost.PageId = this.currentPage.UUID; const host = await this.saveNodeToPage(this.currentPage, baseHost); - console.log('added node to page', host); let placed = false; if ( position === 'before' && positionNodeId ) {