-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement : Offline notification added (#1541)
- Loading branch information
1 parent
7b33e78
commit 5a536cd
Showing
2 changed files
with
55 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use client'; | ||
import Image from 'next/image'; | ||
import { useState, useEffect } from 'react'; | ||
|
||
const OfflineNotification = () => { | ||
const [isOffline, setIsOffline] = useState(false); | ||
const [mounted, setMounted] = useState(false); | ||
|
||
useEffect(() => { | ||
setMounted(true); | ||
setIsOffline(!window.navigator.onLine); | ||
|
||
const handleOnline = () => setIsOffline(false); | ||
const handleOffline = () => setIsOffline(true); | ||
|
||
window.addEventListener('online', handleOnline); | ||
window.addEventListener('offline', handleOffline); | ||
|
||
return () => { | ||
window.removeEventListener('online', handleOnline); | ||
window.removeEventListener('offline', handleOffline); | ||
}; | ||
}, []); | ||
|
||
if (!mounted) return null; | ||
|
||
if (!isOffline) return null; | ||
|
||
return ( | ||
<div className="fixed inset-0 flex flex-col items-center justify-center space-y-4 bg-white dark:bg-[#020817] z-50"> | ||
<div className="flex flex-col items-center space-y-4 p-6 rounded-lg"> | ||
<Image | ||
src="/harkirat.png" | ||
alt="Offline" | ||
width={48} | ||
height={48} | ||
unoptimized | ||
className="mb-2" | ||
/> | ||
<h2 className="text-xl font-semibold text-black dark:text-white"> | ||
You are offline | ||
</h2> | ||
<p className="text-neutral-500 dark:text-neutral-200 text-center"> | ||
Please check your internet connection | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OfflineNotification; |