| 13 | import { isPollingDisabled } from "~/util"; |
| 14 | |
| 15 | export const useTrackFocus = () => { |
| 16 | const setValue = useSetAtom(isFocusedState); |
| 17 | |
| 18 | const handleBlur = React.useCallback(() => { |
| 19 | setValue(false); |
| 20 | }, [setValue]); |
| 21 | const handleFocus = React.useCallback(() => { |
| 22 | setValue(true); |
| 23 | }, [setValue]); |
| 24 | |
| 25 | React.useEffect(() => { |
| 26 | window.addEventListener("blur", handleBlur); |
| 27 | window.addEventListener("focus", handleFocus); |
| 28 | }); |
| 29 | }; |
| 30 | |
| 31 | export const isFocusedState = atom<boolean>(document.hasFocus()); |
| 32 | |