Fix Livestream Popout Chat not refreshing when closed (#1797)

This commit is contained in:
Rafael Saes 2022-07-05 15:30:54 -03:00 committed by GitHub
parent b0e88ff5d1
commit 1e3585f5cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 6 deletions

View file

@ -34,17 +34,32 @@ export default function LivestreamMenu(props: Props) {
location: { pathname },
} = useHistory();
const initialPopoutUnload = React.useRef(false);
const [showTimestamps, setShowTimestamps] = usePersistedState('live-timestamps', false);
function handlePopout() {
if (setPopoutWindow) {
const newWindow = window.open('/$/popout' + pathname, 'Popout Chat', 'height=700,width=400');
const popoutWindow = window.open('/$/popout' + pathname, 'Popout Chat', 'height=700,width=400');
// Add function to newWindow when closed (either manually or from button component)
newWindow.onbeforeunload = () => setPopoutWindow(undefined);
// Adds function to popoutWindow when unloaded and verify if it was closed
const handleUnload = (e) => {
if (!initialPopoutUnload.current) {
initialPopoutUnload.current = true;
} else {
const timer = setInterval((a, b) => {
if (popoutWindow.closed) {
clearInterval(timer);
setPopoutWindow(undefined);
}
}, 300);
}
};
if (window.focus) newWindow.focus();
setPopoutWindow(newWindow);
popoutWindow.onunload = handleUnload;
if (window.focus) popoutWindow.focus();
setPopoutWindow(popoutWindow);
}
}

View file

@ -266,7 +266,14 @@ export default function LivestreamChatLayout(props: Props) {
actions={
<div className="section__actions">
{openedPopoutWindow && (
<Button button="secondary" label={__('Close Popout')} onClick={() => openedPopoutWindow.close()} />
<Button
button="secondary"
label={__('Close Popout')}
onClick={() => {
openedPopoutWindow.close();
setPopoutWindow(undefined);
}}
/>
)}
{chatHidden && (