import { useStore } from 'App/mstore'; import React from 'react'; import { withRouter } from 'react-router-dom'; import { sessions as sessionsRoute, liveSession as liveSessionRoute, withSiteId, } from 'App/routes'; import { BackLink, Link } from 'UI'; import cn from 'classnames'; import SessionMetaList from 'Shared/SessionItem/SessionMetaList'; import Tabs from 'Components/Session/Tabs'; import { PlayerContext } from 'App/components/Session/playerContext'; import { observer } from 'mobx-react-lite'; import { IFRAME } from 'App/constants/storageKeys'; import stl from './playerBlockHeader.module.css'; import UserCard from './EventsBlock/UserCard'; import { useTranslation } from 'react-i18next'; const SESSIONS_ROUTE = sessionsRoute(); function PlayerBlockHeader(props: any) { const { t } = useTranslation(); const [hideBack, setHideBack] = React.useState(false); const { player, store } = React.useContext(PlayerContext); const { uxtestingStore, customFieldStore, projectsStore, sessionStore } = useStore(); const session = sessionStore.current; const { sessionPath } = sessionStore; const siteId = projectsStore.siteId!; const playerState = store?.get?.() || { width: 0, height: 0, showEvents: false, }; const { width = 0, height = 0, showEvents = false } = playerState; const metaList = customFieldStore.list.map((i: any) => i.key); const { fullscreen, closedLive = false, setActiveTab, activeTab, history, } = props; React.useEffect(() => { const iframe = localStorage.getItem(IFRAME) || false; setHideBack(!!iframe && iframe === 'true'); if (metaList.length === 0) customFieldStore.fetchList(); }, []); const backHandler = () => { if ( sessionPath.pathname === history.location.pathname || sessionPath.pathname.includes('/session/') || sessionPath.pathname.includes('/assist/') ) { history.push(withSiteId(SESSIONS_ROUTE, siteId)); } else { history.push( sessionPath ? sessionPath.pathname + sessionPath.search : withSiteId(SESSIONS_ROUTE, siteId), ); } }; const { sessionId, live, metadata } = session; const _metaList = Object.keys(metadata || {}) .filter((i) => metaList.includes(i)) .map((key) => { const value = metadata[key]; return { label: key, value }; }); const TABS = Object.keys(props.tabs).map((tab) => ({ text: props.tabs[tab], key: tab, })); return (
{!hideBack && (
{/* @ts-ignore TODO */}
)}
{live && !hideBack && !uxtestingStore.isUxt() && ( <>
{t('This Session is Now Continuing Live')}
{_metaList.length > 0 &&
} )} {_metaList.length > 0 && (
)}
{ if (activeTab === tab) { setActiveTab(''); player.toggleEvents(); } else { setActiveTab(tab); !showEvents && player.toggleEvents(); } }} border={false} />
); } const PlayerHeaderCont = observer(PlayerBlockHeader); export default withRouter(PlayerHeaderCont);