2022-05-26 08:52:27 +03:00
|
|
|
/* eslint-disable react/no-danger */
|
2022-07-08 10:10:18 +03:00
|
|
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
2022-05-30 07:52:38 +03:00
|
|
|
import { Layout, Tabs, Spin } from 'antd';
|
2022-06-27 09:01:52 +03:00
|
|
|
import { useEffect, useState } from 'react';
|
2022-07-03 13:36:30 +03:00
|
|
|
import cn from 'classnames';
|
2022-06-27 09:01:52 +03:00
|
|
|
import { LOCAL_STORAGE_KEYS, getLocalStorage, setLocalStorage } from '../../../utils/localStorage';
|
|
|
|
|
2022-05-04 00:17:05 +03:00
|
|
|
import {
|
|
|
|
clientConfigStateAtom,
|
|
|
|
chatMessagesAtom,
|
2022-06-25 07:30:54 +03:00
|
|
|
chatDisplayNameAtom,
|
|
|
|
chatUserIdAtom,
|
2022-05-26 06:38:40 +03:00
|
|
|
isChatVisibleSelector,
|
|
|
|
appStateAtom,
|
|
|
|
isOnlineSelector,
|
2022-07-03 13:36:30 +03:00
|
|
|
isMobileAtom,
|
2022-07-13 00:10:59 +03:00
|
|
|
serverStatusState,
|
2022-05-04 00:17:05 +03:00
|
|
|
} from '../../stores/ClientConfigStore';
|
2022-04-28 19:54:33 +03:00
|
|
|
import { ClientConfig } from '../../../interfaces/client-config.model';
|
2022-07-11 02:42:35 +03:00
|
|
|
import CustomPageContent from '../CustomPageContent/CustomPageContent';
|
2022-04-29 00:36:05 +03:00
|
|
|
import OwncastPlayer from '../../video/OwncastPlayer';
|
2022-07-12 04:29:58 +03:00
|
|
|
import FollowerCollection from '../Followers/FollowersCollection';
|
2022-05-04 00:55:13 +03:00
|
|
|
import s from './Content.module.scss';
|
|
|
|
import Sidebar from '../Sidebar';
|
|
|
|
import Footer from '../Footer';
|
2022-05-04 10:55:44 +03:00
|
|
|
import ChatContainer from '../../chat/ChatContainer';
|
|
|
|
import { ChatMessage } from '../../../interfaces/chat-message.model';
|
2022-07-10 09:56:31 +03:00
|
|
|
// import ChatTextField from '../../chat/ChatTextField/ChatTextField';
|
2022-05-08 02:13:06 +03:00
|
|
|
import ActionButtonRow from '../../action-buttons/ActionButtonRow';
|
|
|
|
import ActionButton from '../../action-buttons/ActionButton';
|
2022-05-17 07:44:09 +03:00
|
|
|
import NotifyReminderPopup from '../NotifyReminderPopup/NotifyReminderPopup';
|
2022-05-26 06:38:40 +03:00
|
|
|
import OfflineBanner from '../OfflineBanner/OfflineBanner';
|
|
|
|
import { AppStateOptions } from '../../stores/application-state';
|
2022-05-30 07:52:38 +03:00
|
|
|
import FollowButton from '../../action-buttons/FollowButton';
|
|
|
|
import NotifyButton from '../../action-buttons/NotifyButton';
|
2022-06-27 09:01:52 +03:00
|
|
|
import Modal from '../Modal/Modal';
|
|
|
|
import BrowserNotifyModal from '../../modals/BrowserNotify/BrowserNotifyModal';
|
2022-07-08 23:20:22 +03:00
|
|
|
import StreamInfo from '../../common/StreamInfo';
|
2022-07-13 00:10:59 +03:00
|
|
|
import { ServerStatus } from '../../../interfaces/server-status.model';
|
|
|
|
import { StatusBar } from '..';
|
2022-04-29 00:36:05 +03:00
|
|
|
|
|
|
|
const { TabPane } = Tabs;
|
2022-04-28 19:54:33 +03:00
|
|
|
const { Content } = Layout;
|
|
|
|
|
2022-05-08 10:39:58 +03:00
|
|
|
export default function ContentComponent() {
|
2022-05-26 06:38:40 +03:00
|
|
|
const appState = useRecoilValue<AppStateOptions>(appStateAtom);
|
2022-05-03 03:45:22 +03:00
|
|
|
const clientConfig = useRecoilValue<ClientConfig>(clientConfigStateAtom);
|
2022-05-26 06:38:40 +03:00
|
|
|
const isChatVisible = useRecoilValue<boolean>(isChatVisibleSelector);
|
2022-07-08 10:10:18 +03:00
|
|
|
const [isMobile, setIsMobile] = useRecoilState<boolean | undefined>(isMobileAtom);
|
2022-05-04 10:55:44 +03:00
|
|
|
const messages = useRecoilValue<ChatMessage[]>(chatMessagesAtom);
|
2022-05-26 06:38:40 +03:00
|
|
|
const online = useRecoilValue<boolean>(isOnlineSelector);
|
2022-06-25 07:30:54 +03:00
|
|
|
const chatDisplayName = useRecoilValue<string>(chatDisplayNameAtom);
|
|
|
|
const chatUserId = useRecoilValue<string>(chatUserIdAtom);
|
2022-07-13 00:10:59 +03:00
|
|
|
const { viewerCount, lastConnectTime, lastDisconnectTime } =
|
|
|
|
useRecoilValue<ServerStatus>(serverStatusState);
|
2022-07-13 03:40:10 +03:00
|
|
|
const { extraPageContent, version, name, externalActions } = clientConfig;
|
2022-06-27 09:01:52 +03:00
|
|
|
const [showNotifyReminder, setShowNotifyReminder] = useState(false);
|
|
|
|
const [showNotifyPopup, setShowNotifyPopup] = useState(false);
|
2022-04-28 19:54:33 +03:00
|
|
|
|
2022-05-08 02:13:06 +03:00
|
|
|
const externalActionButtons = externalActions.map(action => (
|
|
|
|
<ActionButton key={action.url} action={action} />
|
|
|
|
));
|
|
|
|
|
2022-06-27 09:01:52 +03:00
|
|
|
const incrementVisitCounter = () => {
|
|
|
|
let visits = parseInt(getLocalStorage(LOCAL_STORAGE_KEYS.userVisitCount), 10);
|
|
|
|
if (Number.isNaN(visits)) {
|
|
|
|
visits = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setLocalStorage(LOCAL_STORAGE_KEYS.userVisitCount, visits + 1);
|
|
|
|
|
|
|
|
if (visits > 2 && !getLocalStorage(LOCAL_STORAGE_KEYS.hasDisplayedNotificationModal)) {
|
|
|
|
setShowNotifyReminder(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const disableNotifyReminderPopup = () => {
|
|
|
|
setShowNotifyPopup(false);
|
|
|
|
setShowNotifyReminder(false);
|
|
|
|
setLocalStorage(LOCAL_STORAGE_KEYS.hasDisplayedNotificationModal, true);
|
|
|
|
};
|
|
|
|
|
2022-07-03 13:36:30 +03:00
|
|
|
const checkIfMobile = () => {
|
|
|
|
const w = window.innerWidth;
|
|
|
|
if (isMobile === undefined) {
|
|
|
|
if (w <= 768) setIsMobile(true);
|
|
|
|
else setIsMobile(false);
|
|
|
|
}
|
|
|
|
if (!isMobile && w <= 768) setIsMobile(true);
|
|
|
|
if (isMobile && w > 768) setIsMobile(false);
|
|
|
|
};
|
|
|
|
|
2022-06-27 09:01:52 +03:00
|
|
|
useEffect(() => {
|
|
|
|
incrementVisitCounter();
|
2022-07-03 13:36:30 +03:00
|
|
|
checkIfMobile();
|
|
|
|
window.addEventListener('resize', checkIfMobile);
|
2022-06-27 09:01:52 +03:00
|
|
|
}, []);
|
|
|
|
|
2022-07-03 13:36:30 +03:00
|
|
|
const rootClassName = cn(s.root, {
|
|
|
|
[s.mobile]: isMobile,
|
|
|
|
});
|
|
|
|
|
2022-04-28 19:54:33 +03:00
|
|
|
return (
|
2022-07-03 13:36:30 +03:00
|
|
|
<Content className={rootClassName}>
|
2022-07-08 10:10:18 +03:00
|
|
|
<div className={s.leftContent}>
|
|
|
|
<Spin className={s.loadingSpinner} size="large" spinning={appState.appLoading} />
|
|
|
|
<div className={s.topHalf}>
|
|
|
|
{online && <OwncastPlayer source="/hls/stream.m3u8" online={online} />}
|
|
|
|
{!online && (
|
|
|
|
<OfflineBanner
|
|
|
|
name={name}
|
|
|
|
text="Stream is offline text goes here. Will create a new form to set it in the Admin."
|
|
|
|
/>
|
|
|
|
)}
|
2022-07-13 00:10:59 +03:00
|
|
|
<StatusBar
|
|
|
|
online={online}
|
|
|
|
lastConnectTime={lastConnectTime}
|
|
|
|
lastDisconnectTime={lastDisconnectTime}
|
|
|
|
viewerCount={viewerCount}
|
|
|
|
/>
|
2022-07-08 10:10:18 +03:00
|
|
|
<div className={s.buttonsLogoTitleSection}>
|
|
|
|
<ActionButtonRow>
|
|
|
|
{externalActionButtons}
|
|
|
|
<FollowButton size="small" />
|
|
|
|
<NotifyReminderPopup
|
|
|
|
visible={showNotifyReminder}
|
|
|
|
notificationClicked={() => setShowNotifyPopup(true)}
|
|
|
|
notificationClosed={() => disableNotifyReminderPopup()}
|
|
|
|
>
|
|
|
|
<NotifyButton onClick={() => setShowNotifyPopup(true)} />
|
|
|
|
</NotifyReminderPopup>
|
|
|
|
</ActionButtonRow>
|
|
|
|
|
|
|
|
<Modal
|
|
|
|
title="Notify"
|
|
|
|
visible={showNotifyPopup}
|
|
|
|
afterClose={() => disableNotifyReminderPopup()}
|
|
|
|
handleCancel={() => disableNotifyReminderPopup()}
|
2022-05-18 02:07:56 +03:00
|
|
|
>
|
2022-07-08 10:10:18 +03:00
|
|
|
<BrowserNotifyModal />
|
|
|
|
</Modal>
|
2022-05-18 02:07:56 +03:00
|
|
|
</div>
|
2022-07-08 23:20:22 +03:00
|
|
|
<StreamInfo isMobile={isMobile} />
|
2022-07-08 10:10:18 +03:00
|
|
|
</div>
|
|
|
|
<div className={s.lowerHalf}>
|
2022-07-10 09:56:31 +03:00
|
|
|
<Tabs defaultActiveKey="0" style={{ height: '100%' }}>
|
2022-07-08 10:10:18 +03:00
|
|
|
{isChatVisible && isMobile && (
|
2022-07-11 02:42:35 +03:00
|
|
|
<TabPane tab="Chat" key="0" style={{ height: '100%' }}>
|
2022-07-08 23:20:22 +03:00
|
|
|
<div style={{ position: 'relative', height: '100%' }}>
|
2022-07-08 10:10:18 +03:00
|
|
|
<div className={s.mobileChat}>
|
|
|
|
<ChatContainer
|
|
|
|
messages={messages}
|
2022-07-10 09:56:31 +03:00
|
|
|
// loading={appState.chatLoading}
|
2022-07-08 10:10:18 +03:00
|
|
|
usernameToHighlight={chatDisplayName}
|
|
|
|
chatUserId={chatUserId}
|
|
|
|
isModerator={false}
|
|
|
|
isMobile={isMobile}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</TabPane>
|
|
|
|
)}
|
|
|
|
<TabPane tab="About" key="2" className={s.pageContentSection}>
|
2022-05-04 00:55:13 +03:00
|
|
|
<CustomPageContent content={extraPageContent} />
|
|
|
|
</TabPane>
|
2022-07-08 10:10:18 +03:00
|
|
|
<TabPane tab="Followers" key="3" className={s.pageContentSection}>
|
2022-07-12 07:06:57 +03:00
|
|
|
<FollowerCollection />
|
2022-05-04 00:55:13 +03:00
|
|
|
</TabPane>
|
|
|
|
</Tabs>
|
2022-07-08 23:20:22 +03:00
|
|
|
{!isMobile && <Footer version={version} />}
|
2022-05-04 00:55:13 +03:00
|
|
|
</div>
|
2022-05-04 10:55:44 +03:00
|
|
|
</div>
|
2022-07-03 13:36:30 +03:00
|
|
|
{isChatVisible && !isMobile && <Sidebar />}
|
2022-04-28 19:54:33 +03:00
|
|
|
</Content>
|
|
|
|
);
|
|
|
|
}
|