Fix Livestream Popout Chat not refreshing when closed (#1797)
This commit is contained in:
parent
b0e88ff5d1
commit
1e3585f5cc
2 changed files with 28 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 && (
|
||||
|
|
Loading…
Reference in a new issue