2022-02-02 13:45:16 +01:00
|
|
|
// @flow
|
|
|
|
// $FlowFixMe
|
|
|
|
import { Global } from '@emotion/react';
|
|
|
|
|
|
|
|
import { Menu, MenuButton, MenuList, MenuItem } from '@reach/menu-button';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import usePersistedState from 'effects/use-persisted-state';
|
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
isPopoutWindow?: boolean,
|
|
|
|
superchatsHidden?: boolean,
|
|
|
|
noSuperchats?: boolean,
|
2022-02-02 13:48:24 +01:00
|
|
|
isMobile?: boolean,
|
2022-02-02 13:45:16 +01:00
|
|
|
hideChat?: () => void,
|
|
|
|
setPopoutWindow?: (any) => void,
|
|
|
|
toggleSuperchats?: () => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function LivestreamMenu(props: Props) {
|
2022-02-02 13:48:24 +01:00
|
|
|
const {
|
|
|
|
isPopoutWindow,
|
|
|
|
superchatsHidden,
|
|
|
|
noSuperchats,
|
|
|
|
isMobile,
|
|
|
|
hideChat,
|
|
|
|
setPopoutWindow,
|
|
|
|
toggleSuperchats,
|
|
|
|
} = props;
|
2022-02-02 13:45:16 +01:00
|
|
|
|
|
|
|
const {
|
|
|
|
location: { pathname },
|
|
|
|
} = useHistory();
|
|
|
|
|
2022-07-05 20:30:54 +02:00
|
|
|
const initialPopoutUnload = React.useRef(false);
|
|
|
|
|
2022-02-02 13:45:16 +01:00
|
|
|
const [showTimestamps, setShowTimestamps] = usePersistedState('live-timestamps', false);
|
|
|
|
|
|
|
|
function handlePopout() {
|
|
|
|
if (setPopoutWindow) {
|
2022-07-05 20:30:54 +02:00
|
|
|
const popoutWindow = window.open('/$/popout' + pathname, 'Popout Chat', 'height=700,width=400');
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
};
|
2022-02-02 13:45:16 +01:00
|
|
|
|
2022-07-05 20:30:54 +02:00
|
|
|
popoutWindow.onunload = handleUnload;
|
2022-02-02 13:45:16 +01:00
|
|
|
|
2022-07-05 20:30:54 +02:00
|
|
|
if (window.focus) popoutWindow.focus();
|
|
|
|
setPopoutWindow(popoutWindow);
|
2022-02-02 13:45:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-02-02 13:48:24 +01:00
|
|
|
<MenuGlobalStyles showTimestamps={showTimestamps} />
|
2022-02-02 13:45:16 +01:00
|
|
|
|
|
|
|
<Menu>
|
|
|
|
<MenuButton className="menu__button">
|
|
|
|
<Icon size={isMobile ? 16 : 18} icon={ICONS.SETTINGS} />
|
|
|
|
</MenuButton>
|
|
|
|
|
|
|
|
<MenuList className="menu__list">
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={() => setShowTimestamps(!showTimestamps)}>
|
|
|
|
<span className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.TIME} />
|
|
|
|
{__('Toggle Timestamps')}
|
|
|
|
</span>
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
{!isMobile ? (
|
|
|
|
<>
|
|
|
|
{/* No need for Hide Chat on mobile with the expand/collapse drawer */}
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={hideChat}>
|
|
|
|
<span className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.EYE} />
|
|
|
|
{__('Hide Chat')}
|
|
|
|
</span>
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
{!isPopoutWindow && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={handlePopout}>
|
|
|
|
<span className="menu__link">
|
|
|
|
<Icon aria-hidden icon={ICONS.EXTERNAL} />
|
|
|
|
{__('Popout Chat')}
|
|
|
|
</span>
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
!noSuperchats && (
|
|
|
|
<MenuItem className="comment__menu-option" onSelect={toggleSuperchats}>
|
|
|
|
<span className="menu__link">
|
|
|
|
<Icon aria-hidden icon={superchatsHidden ? ICONS.EYE : ICONS.DISMISS_ALL} size={18} />
|
2022-02-18 11:55:37 +01:00
|
|
|
{superchatsHidden ? __('Display HyperChats') : __('Dismiss HyperChats')}
|
2022-02-02 13:45:16 +01:00
|
|
|
</span>
|
|
|
|
</MenuItem>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</MenuList>
|
|
|
|
</Menu>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2022-02-02 13:48:24 +01:00
|
|
|
|
|
|
|
type GlobalStylesProps = {
|
|
|
|
showTimestamps?: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
const MenuGlobalStyles = (globalStylesProps: GlobalStylesProps) => {
|
|
|
|
const { showTimestamps } = globalStylesProps;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Global
|
|
|
|
styles={{
|
|
|
|
':root': {
|
|
|
|
'--live-timestamp-opacity': showTimestamps ? '0.5' : '0',
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|