-
-
Notifications
You must be signed in to change notification settings - Fork 135
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 #290 from justinlampley/WIFIFlashingWarning
Warn about unplugging power to soon when flashing via WIFI
- Loading branch information
Showing
2 changed files
with
71 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { FunctionComponent, useEffect, useRef, useState } from 'react'; | ||
|
||
interface ShowAfterTimeoutProps { | ||
timeout: number; | ||
active: boolean; | ||
} | ||
|
||
const ShowAfterTimeout: FunctionComponent<ShowAfterTimeoutProps> = ({ | ||
timeout, | ||
active, | ||
...props | ||
}) => { | ||
const [visible, setVisible] = useState<boolean>(false); | ||
const activeRef = useRef(active); | ||
activeRef.current = active; | ||
const timeoutRef = useRef<number | null>(null); | ||
useEffect(() => { | ||
if (activeRef.current) { | ||
timeoutRef.current = window.setTimeout(() => { | ||
setVisible(true); | ||
}, timeout); | ||
} else { | ||
setVisible(false); | ||
if (timeoutRef.current !== null) { | ||
clearTimeout(timeoutRef.current); | ||
} | ||
} | ||
return () => { | ||
if (timeoutRef.current !== null) { | ||
clearTimeout(timeoutRef.current); | ||
} | ||
}; | ||
}, [active, timeout]); | ||
return <>{visible && props.children}</>; | ||
}; | ||
|
||
export default ShowAfterTimeout; |
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