From f830536a2d278c9ab8f713bca53845b1dcdba84f Mon Sep 17 00:00:00 2001 From: Anssi Juvonen Date: Wed, 11 Sep 2024 15:27:42 +0300 Subject: [PATCH] Add notification of new content --- src/App.vue | 12 ++++++++++++ src/i18n/en.json | 3 ++- src/i18n/fi.json | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/App.vue b/src/App.vue index 164ba2f..9c0a720 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,11 +3,14 @@ import {watchEffect} from 'vue'; import {storeToRefs} from 'pinia'; import {useI18n} from 'vue-i18n'; import {RouterView, useRoute} from 'vue-router'; +import {useRegisterSW} from 'virtual:pwa-register/vue'; import {useActivityStore} from '@/stores/activityStore'; import {useAppStateStore} from '@/stores/appStateStore'; import NavBar from '@/components/NavBar.vue'; import ToastContainer from '@/components/ToastContainer.vue'; +const {addToastMessage} = useAppStateStore(); + const {t, locale} = useI18n(); const route = useRoute(); @@ -15,6 +18,15 @@ const route = useRoute(); const {allVeggies} = storeToRefs(useActivityStore()); const {settings} = storeToRefs(useAppStateStore()); +const {updateServiceWorker} = useRegisterSW({ + immediate: true, + async onNeedRefresh() { + addToastMessage(t('general.updateReady')); + await updateServiceWorker(); + window.location.reload(); + }, +}); + watchEffect(() => { locale.value = settings.value.locale; }); diff --git a/src/i18n/en.json b/src/i18n/en.json index c238143..abcc667 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -106,7 +106,8 @@ "clickToAdd": "Add {0}", "clickToRemove": "Remove {0}", "close": "Close", - "start": "Start" + "start": "Start", + "updateReady": "The app has been updated with latest content." }, "home": { "info": "Learn more", diff --git a/src/i18n/fi.json b/src/i18n/fi.json index db0b2dc..5e6e6e6 100644 --- a/src/i18n/fi.json +++ b/src/i18n/fi.json @@ -106,7 +106,8 @@ "clickToAdd": "Lisää {0}", "clickToRemove": "Poista {0}", "close": "Sulje", - "start": "Aloita" + "start": "Aloita", + "updateReady": "Sovellus on päivitetty uuteen versioon." }, "home": { "info": "Lue lisää",