mirror of
https://github.com/johndoe6345789/low-code-react-app-b.git
synced 2026-04-24 21:54:56 +00:00
Merge pull request #69 from johndoe6345789/codex/manage-online/offline-status-timing
Fix PWAStatusBar offline/online timing and timeout cleanup
This commit is contained in:
@@ -1,20 +1,35 @@
|
||||
import { usePWA } from '@/hooks/use-pwa'
|
||||
import { WifiSlash, WifiHigh } from '@phosphor-icons/react'
|
||||
import { motion, AnimatePresence } from 'framer-motion'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
|
||||
export function PWAStatusBar() {
|
||||
const { isOnline } = usePWA()
|
||||
const [showOffline, setShowOffline] = useState(false)
|
||||
const hideTimerRef = useRef<number | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOnline) {
|
||||
if (hideTimerRef.current) {
|
||||
clearTimeout(hideTimerRef.current)
|
||||
hideTimerRef.current = null
|
||||
}
|
||||
setShowOffline(true)
|
||||
} else if (showOffline) {
|
||||
const timer = setTimeout(() => {
|
||||
return
|
||||
}
|
||||
|
||||
if (showOffline) {
|
||||
hideTimerRef.current = window.setTimeout(() => {
|
||||
setShowOffline(false)
|
||||
hideTimerRef.current = null
|
||||
}, 3000)
|
||||
return () => clearTimeout(timer)
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (hideTimerRef.current) {
|
||||
clearTimeout(hideTimerRef.current)
|
||||
hideTimerRef.current = null
|
||||
}
|
||||
}
|
||||
}, [isOnline, showOffline])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user