Skip to content

Commit

Permalink
fix: Add support for custom document in useClickOutside (WPB-14862) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisamir98 authored Dec 5, 2024
1 parent 1c8fef5 commit fd590d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/script/components/calling/FullscreenVideoCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ const FullscreenVideoCall: React.FC<FullscreenVideoCallProps> = ({
const emojiBarRef = useRef(null);
const emojiBarToggleButtonRef = useRef(null);

useClickOutside(emojiBarRef, () => setShowEmojisBar(false), emojiBarToggleButtonRef);

const {blurredVideoStream} = useKoSubscribableChildren(selfParticipant, ['blurredVideoStream']);
const hasBlurredBackground = !!blurredVideoStream;

Expand Down Expand Up @@ -206,11 +204,12 @@ const FullscreenVideoCall: React.FC<FullscreenVideoCallProps> = ({
]);

const {selfUser, roles} = useKoSubscribableChildren(conversation, ['selfUser', 'roles']);
const {emojis, viewMode, isScreenSharingSourceFromDetachedWindow} = useKoSubscribableChildren(callState, [
'emojis',
'viewMode',
'isScreenSharingSourceFromDetachedWindow',
]);
const {emojis, viewMode, detachedWindow, isScreenSharingSourceFromDetachedWindow} = useKoSubscribableChildren(
callState,
['emojis', 'viewMode', 'detachedWindow', 'isScreenSharingSourceFromDetachedWindow'],
);

useClickOutside(emojiBarRef, () => setShowEmojisBar(false), emojiBarToggleButtonRef, detachedWindow?.document);

const [audioOptionsOpen, setAudioOptionsOpen] = useState(false);
const [videoOptionsOpen, setVideoOptionsOpen] = useState(false);
Expand Down
7 changes: 4 additions & 3 deletions src/script/hooks/useClickOutside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const useClickOutside = (
ref: RefObject<Element>,
onClick: (e: MouseEvent) => void,
exclude?: RefObject<Element>,
windowDocument = window.document,
) => {
useEffect(() => {
const handleClick = (event: MouseEvent) => {
Expand All @@ -34,8 +35,8 @@ export const useClickOutside = (
}
}
};
document.addEventListener('click', handleClick);
windowDocument.addEventListener('click', handleClick);

return () => document.removeEventListener('click', handleClick);
}, [onClick]);
return () => windowDocument.removeEventListener('click', handleClick);
}, [exclude, onClick, ref, windowDocument]);
};

0 comments on commit fd590d3

Please sign in to comment.