From b8d7ae3d8b692e4b5d11c1532751cdfe1c37a314 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Fri, 19 Jan 2018 00:29:45 -0800 Subject: [PATCH] tweak offline mode --- routes/_components/Timeline.html | 12 ++++++++---- routes/_utils/serviceWorkerClient.js | 9 ++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/routes/_components/Timeline.html b/routes/_components/Timeline.html index 6b26fa3a..c7c0c2f1 100644 --- a/routes/_components/Timeline.html +++ b/routes/_components/Timeline.html @@ -1,5 +1,5 @@ <:Window bind:online /> -
+
@@ -23,7 +23,6 @@ import { mark, stop } from '../_utils/marks' import { timelines } from '../_static/timelines' - const FETCH_LIMIT = 20 export default { @@ -38,11 +37,13 @@ insertStatusesIntoDatabase(instanceName, this.get('timeline'), statuses) } this.addStatuses(statuses) + this.set({initialized: true}) }, data: () => ({ StatusListItem: StatusListItem, statuses: [], - runningUpdate: false + runningUpdate: false, + initialized: false }), computed: { keyedStatuses: (statuses) => statuses.map(status => ({ @@ -60,10 +61,13 @@ splice: splice, push: push, async onScrollToBottom() { - mark('onScrollToBottom') + if (!this.get('initialized')) { + return + } if (this.get('runningUpdate')) { return } + mark('onScrollToBottom') this.set({ runningUpdate: true }) let lastStatusId = this.get('lastStatusId') let instanceName = this.store.get('currentInstance') diff --git a/routes/_utils/serviceWorkerClient.js b/routes/_utils/serviceWorkerClient.js index 31cb8983..b2b85b1f 100644 --- a/routes/_utils/serviceWorkerClient.js +++ b/routes/_utils/serviceWorkerClient.js @@ -1,16 +1,11 @@ import { toast } from './toast' -import { keyval } from './database/keyval' function onUpdateFound(registration) { const newWorker = registration.installing newWorker.addEventListener('statechange', async () => { - if (!(await keyval.get('serviceworker_installed'))) { - await keyval.set('serviceworker_installed', true) - return - } - if (newWorker.state === 'activated' && navigator.serviceWorker.controller) { - toast.say('App update available. Reload to update.') + if (newWorker.state === 'installed' && navigator.serviceWorker.controller) { + toast.say('Update available. Refresh to update.') } }); }