diff options
author | 2023-03-01 21:46:23 +0100 | |
---|---|---|
committer | 2023-03-01 22:00:29 +0100 | |
commit | 53ce079dff8e91a4c8879dcf18e945b7e842eb47 (patch) | |
tree | cf4c5723f6f83ed1a6a61fa8444d4dae9491c72f /src/components/ReloadPrompt.tsx | |
parent | a7713462501fe44db45aa2283433d7ce9d2fec72 (diff) | |
download | it-tools-53ce079dff8e91a4c8879dcf18e945b7e842eb47.tar.gz it-tools-53ce079dff8e91a4c8879dcf18e945b7e842eb47.tar.zst it-tools-53ce079dff8e91a4c8879dcf18e945b7e842eb47.zip |
refactor(pwa): prompt for pwa update
Diffstat (limited to 'src/components/ReloadPrompt.tsx')
-rw-r--r-- | src/components/ReloadPrompt.tsx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/components/ReloadPrompt.tsx b/src/components/ReloadPrompt.tsx new file mode 100644 index 0000000..9b36ea8 --- /dev/null +++ b/src/components/ReloadPrompt.tsx @@ -0,0 +1,32 @@ +import { useRegisterSW } from 'virtual:pwa-register/vue'; +import { NButton, useNotification } from 'naive-ui'; +import { h, type Component } from 'vue'; +import { whenever } from '@vueuse/core'; + +export default function () { + const notification = useNotification(); + + const { needRefresh, updateServiceWorker } = useRegisterSW(); + + whenever( + needRefresh, + () => { + notification.create({ + title: 'A new version is out!', + content: 'Reload the page to refresh the cache and get the newest version of it-tools', + closable: true, + onClose: () => { + needRefresh.value = false; + return true; + }, + action: () => + h( + NButton as Component, + { onClick: updateServiceWorker, type: 'primary', secondary: true }, + { default: () => 'Reload' }, + ), + }); + }, + { immediate: true }, + ); +} |