-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3500 from ever-co/feat/offline-mode-handling
[Feat]: Implement Automatic Offline Page Display
- Loading branch information
Showing
4 changed files
with
57 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use client'; | ||
|
||
import { useNetworkState } from '@uidotdev/usehooks'; | ||
import Offline from '@components/pages/offline'; | ||
import { useTimerView } from '@app/hooks'; | ||
import { usePathname } from 'next/navigation'; | ||
|
||
interface OfflineWrapperProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
/** | ||
* A wrapper component that conditionally renders the Offline component if the user is not online. | ||
* The Offline component is not shown on authentication pages (paths starting with /auth). | ||
* When the user is offline, the Offline component is rendered with the showTimer prop set to | ||
* whether the timer is running or not. | ||
* | ||
* @example | ||
* <OfflineWrapper> | ||
* <MyComponent /> | ||
* </OfflineWrapper> | ||
* @param {React.ReactNode} children - The children components to render when the user is online | ||
* @returns {React.ReactElement} - The Offline component if the user is offline (except on auth pages), or the children components if the user is online | ||
*/ | ||
export default function OfflineWrapper({ children }: OfflineWrapperProps) { | ||
const { online } = useNetworkState(); | ||
const { timerStatus } = useTimerView(); | ||
const pathname = usePathname(); | ||
|
||
const isAuthPage = pathname?.startsWith('/auth'); | ||
|
||
if (!online && !isAuthPage) { | ||
return <Offline showTimer={timerStatus?.running} />; | ||
} | ||
|
||
return <>{children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters