feat: add anti-blink timer
This commit is contained in:
parent
083d72fbfa
commit
9689201a8c
@ -1,4 +1,4 @@
|
|||||||
import {createContext, useContext, useState} from "react";
|
import {createContext, useContext, useEffect, useState} from "react";
|
||||||
import './useLoading.css'
|
import './useLoading.css'
|
||||||
import {FallingLines} from "react-loader-spinner";
|
import {FallingLines} from "react-loader-spinner";
|
||||||
|
|
||||||
@ -28,9 +28,22 @@ export function LoadingProvider({children}) {
|
|||||||
|
|
||||||
function LoadingOverLay() {
|
function LoadingOverLay() {
|
||||||
const showOverlay = useLoading()
|
const showOverlay = useLoading()
|
||||||
|
const [realShow, setRealShow] = useState(showOverlay)
|
||||||
|
|
||||||
if (showOverlay) {
|
useEffect(() => {
|
||||||
return <div className="overlayBG" style={{position: showOverlay === 1 ? 'absolute' : 'fixed'}}>
|
if (showOverlay === 0) {
|
||||||
|
setRealShow(showOverlay)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
setRealShow(showOverlay)
|
||||||
|
}, 100)
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}, [showOverlay]);
|
||||||
|
|
||||||
|
if (realShow) {
|
||||||
|
return <div className="overlayBG" style={{position: realShow === 1 ? 'absolute' : 'fixed'}}>
|
||||||
<div className="overlayContent" onClick={(e) => {
|
<div className="overlayContent" onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
}}>
|
}}>
|
||||||
@ -40,4 +53,4 @@ function LoadingOverLay() {
|
|||||||
} else {
|
} else {
|
||||||
return <></>
|
return <></>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user