mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2026-01-15 12:15:02 +00:00
Keep iframe focus callback ref updated
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import { useProcesses } from "contexts/process";
|
||||
import type { Processes } from "contexts/process/types";
|
||||
import { useSession } from "contexts/session";
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
import { ONE_TIME_PASSIVE_EVENT } from "utils/constants";
|
||||
|
||||
const useIFrameFocuser = (): void => {
|
||||
const { processes } = useProcesses();
|
||||
const { setForegroundId } = useSession();
|
||||
const processesRef = useRef<Processes>({});
|
||||
const focusIframeWindow = useCallback((): void => {
|
||||
if (document.activeElement instanceof HTMLIFrameElement) {
|
||||
const [id] =
|
||||
@@ -19,7 +21,7 @@ const useIFrameFocuser = (): void => {
|
||||
"click",
|
||||
({ target }) => {
|
||||
const [focusId = ""] =
|
||||
Object.entries(processes).find(
|
||||
Object.entries(processesRef.current).find(
|
||||
([, { componentWindow }]) =>
|
||||
target instanceof HTMLElement &&
|
||||
componentWindow?.contains(target)
|
||||
@@ -38,6 +40,10 @@ const useIFrameFocuser = (): void => {
|
||||
|
||||
return () => window.removeEventListener("blur", focusIframeWindow);
|
||||
}, [focusIframeWindow]);
|
||||
|
||||
useEffect(() => {
|
||||
processesRef.current = processes;
|
||||
}, [processes]);
|
||||
};
|
||||
|
||||
export default useIFrameFocuser;
|
||||
|
||||
Reference in New Issue
Block a user