Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Offline indication #26

Open
satelllte opened this issue Jun 6, 2022 · 0 comments
Open

Offline indication #26

satelllte opened this issue Jun 6, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@satelllte
Copy link
Owner

satelllte commented Jun 6, 2022

Offline detection can be implemented using:

  useEffect(() => {
    // TODO: notify user that the app is available for offline use
    // ...

    // https://developer.chrome.com/docs/workbox/modules/workbox-window/#register-a-service-worker-and-notify-the-user-the-very-first-time-that-service-worker-is-active
    // @ts-ignore
    const wb = window.workbox
    // @ts-ignore
    wb.addEventListener('activated', (event) => {
      if (!event.isUpdate) {
        console.info('WB | activated | event: ', event)
        
        // READY FOR OFFLINE USE   !!!!!!
        // do something with it ....
      }
    })
  }, [])

Workbox docs reference: https://developer.chrome.com/docs/workbox/modules/workbox-window/#register-a-service-worker-and-notify-the-user-the-very-first-time-that-service-worker-is-active

To turn off page reload after getting back online, reloadOnOnline: false can be set in next-pwa config: https://github.com/shadowwalker/next-pwa#available-options

@satelllte satelllte added the enhancement New feature or request label Jun 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
No open projects
Status: Todo
Development

No branches or pull requests

1 participant