()
| 300 | }; |
| 301 | |
| 302 | const BadgeAutoClearing = () => { |
| 303 | const tabId = useAtomValue(atoms.staticTabId); |
| 304 | const documentHasFocus = useAtomValue(atoms.documentHasFocus); |
| 305 | const layoutModel = getLayoutModelForStaticTab(); |
| 306 | const focusedNode = useAtomValue(layoutModel.focusedNode); |
| 307 | const focusedBlockId = focusedNode?.data?.blockId; |
| 308 | const badge = useAtomValue(getBlockBadgeAtom(focusedBlockId)); |
| 309 | const tabTransientBadge = useAtomValue(getBadgeAtom(tabId != null ? `tab:${tabId}` : null)); |
| 310 | const prevFocusedBlockIdRef = useRef<string>(null); |
| 311 | const prevDocHasFocusRef = useRef<boolean>(false); |
| 312 | const prevTabDocHasFocusRef = useRef<boolean>(false); |
| 313 | |
| 314 | useEffect(() => { |
| 315 | if (!focusedBlockId || !badge || !documentHasFocus) { |
| 316 | prevFocusedBlockIdRef.current = focusedBlockId; |
| 317 | prevDocHasFocusRef.current = documentHasFocus; |
| 318 | return; |
| 319 | } |
| 320 | const focusSwitched = |
| 321 | prevFocusedBlockIdRef.current !== focusedBlockId || prevDocHasFocusRef.current !== documentHasFocus; |
| 322 | prevFocusedBlockIdRef.current = focusedBlockId; |
| 323 | prevDocHasFocusRef.current = documentHasFocus; |
| 324 | const delay = focusSwitched ? 500 : 3000; |
| 325 | const timeoutId = setTimeout(() => { |
| 326 | if (!document.hasFocus()) { |
| 327 | return; |
| 328 | } |
| 329 | const currentFocusedNode = globalStore.get(layoutModel.focusedNode); |
| 330 | if (currentFocusedNode?.data?.blockId === focusedBlockId) { |
| 331 | clearBadgesForBlockOnFocus(focusedBlockId); |
| 332 | } |
| 333 | }, delay); |
| 334 | return () => clearTimeout(timeoutId); |
| 335 | }, [focusedBlockId, badge, documentHasFocus]); |
| 336 | |
| 337 | useEffect(() => { |
| 338 | if (!tabId || !tabTransientBadge || !documentHasFocus) { |
| 339 | prevTabDocHasFocusRef.current = documentHasFocus; |
| 340 | return; |
| 341 | } |
| 342 | const focusSwitched = prevTabDocHasFocusRef.current !== documentHasFocus; |
| 343 | prevTabDocHasFocusRef.current = documentHasFocus; |
| 344 | const delay = focusSwitched ? 500 : 3000; |
| 345 | const timeoutId = setTimeout(() => { |
| 346 | if (!document.hasFocus()) { |
| 347 | return; |
| 348 | } |
| 349 | clearBadgesForTabOnFocus(tabId); |
| 350 | }, delay); |
| 351 | return () => clearTimeout(timeoutId); |
| 352 | }, [tabId, tabTransientBadge, documentHasFocus]); |
| 353 | |
| 354 | return null; |
| 355 | }; |
| 356 | |
| 357 | const AppInner = () => { |
| 358 | const prefersReducedMotion = useAtomValue(atoms.prefersReducedMotionAtom); |
nothing calls this directly
no test coverage detected