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-09-07 10:00:28 +03:00
|
|
|
import { FC, useEffect, useState } from 'react';
|
2022-09-10 22:08:22 +03:00
|
|
|
import classNames from 'classnames';
|
2022-10-04 07:06:46 +03:00
|
|
|
import dynamic from 'next/dynamic';
|
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,
|
2022-09-10 22:08:22 +03:00
|
|
|
chatMessagesAtom,
|
|
|
|
chatDisplayNameAtom,
|
|
|
|
chatUserIdAtom,
|
2022-09-11 06:03:58 +03:00
|
|
|
isChatAvailableSelector,
|
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-09-07 10:00:28 +03:00
|
|
|
import { CustomPageContent } from '../CustomPageContent/CustomPageContent';
|
|
|
|
import { OwncastPlayer } from '../../video/OwncastPlayer/OwncastPlayer';
|
|
|
|
import styles from './Content.module.scss';
|
|
|
|
import { Sidebar } from '../Sidebar/Sidebar';
|
|
|
|
import { Footer } from '../Footer/Footer';
|
2022-09-10 09:23:24 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
import { ActionButtonRow } from '../../action-buttons/ActionButtonRow/ActionButtonRow';
|
|
|
|
import { ActionButton } from '../../action-buttons/ActionButton/ActionButton';
|
|
|
|
import { OfflineBanner } from '../OfflineBanner/OfflineBanner';
|
2022-05-26 06:38:40 +03:00
|
|
|
import { AppStateOptions } from '../../stores/application-state';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FollowButton } from '../../action-buttons/FollowButton';
|
|
|
|
import { NotifyButton } from '../../action-buttons/NotifyButton';
|
|
|
|
import { ContentHeader } from '../../common/ContentHeader/ContentHeader';
|
2022-07-13 00:10:59 +03:00
|
|
|
import { ServerStatus } from '../../../interfaces/server-status.model';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { Statusbar } from '../Statusbar/Statusbar';
|
2022-09-10 22:08:22 +03:00
|
|
|
import { ChatMessage } from '../../../interfaces/chat-message.model';
|
2022-04-29 00:36:05 +03:00
|
|
|
|
|
|
|
const { TabPane } = Tabs;
|
2022-09-07 10:00:28 +03:00
|
|
|
const { Content: AntContent } = Layout;
|
2022-04-28 19:54:33 +03:00
|
|
|
|
2022-10-04 07:06:46 +03:00
|
|
|
// Lazy loaded components
|
|
|
|
|
|
|
|
const Modal = dynamic(() => import('../Modal/Modal').then(mod => mod.Modal));
|
|
|
|
|
|
|
|
const BrowserNotifyModal = dynamic(() =>
|
|
|
|
import('../../modals/BrowserNotifyModal/BrowserNotifyModal').then(mod => mod.BrowserNotifyModal),
|
|
|
|
);
|
|
|
|
|
|
|
|
const NotifyReminderPopup = dynamic(() =>
|
|
|
|
import('../NotifyReminderPopup/NotifyReminderPopup').then(mod => mod.NotifyReminderPopup),
|
|
|
|
);
|
|
|
|
|
|
|
|
const FollowerCollection = dynamic(() =>
|
|
|
|
import('../followers/FollowerCollection/FollowerCollection').then(mod => mod.FollowerCollection),
|
|
|
|
);
|
|
|
|
|
|
|
|
// We only need to load the chat container here if we're in mobile or narrow
|
|
|
|
// windows, so lazy loading it makes sense.
|
|
|
|
const ChatContainer = dynamic(() =>
|
|
|
|
import('../../chat/ChatContainer/ChatContainer').then(mod => mod.ChatContainer),
|
|
|
|
);
|
|
|
|
|
2022-09-10 22:08:22 +03:00
|
|
|
const DesktopContent = ({ name, streamTitle, summary, tags, socialHandles, extraPageContent }) => (
|
|
|
|
<>
|
|
|
|
<div className={styles.lowerHalf}>
|
|
|
|
<ContentHeader
|
|
|
|
name={name}
|
|
|
|
title={streamTitle}
|
|
|
|
summary={summary}
|
|
|
|
tags={tags}
|
|
|
|
links={socialHandles}
|
|
|
|
logo="/logo"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={styles.lowerSection}>
|
|
|
|
<Tabs defaultActiveKey="0">
|
|
|
|
<TabPane tab="About" key="2">
|
|
|
|
<CustomPageContent content={extraPageContent} />
|
|
|
|
</TabPane>
|
|
|
|
<TabPane tab="Followers" key="3">
|
|
|
|
<FollowerCollection />
|
|
|
|
</TabPane>
|
|
|
|
</Tabs>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
const MobileContent = ({
|
|
|
|
name,
|
|
|
|
streamTitle,
|
|
|
|
summary,
|
|
|
|
tags,
|
|
|
|
socialHandles,
|
|
|
|
extraPageContent,
|
|
|
|
messages,
|
|
|
|
chatDisplayName,
|
|
|
|
chatUserId,
|
2022-09-11 06:03:58 +03:00
|
|
|
showChat,
|
2022-09-10 22:08:22 +03:00
|
|
|
}) => (
|
|
|
|
<div className={classNames(styles.lowerSectionMobile)}>
|
|
|
|
<Tabs defaultActiveKey="0">
|
2022-09-11 06:03:58 +03:00
|
|
|
{showChat && (
|
|
|
|
<TabPane tab="Chat" key="1">
|
|
|
|
<ChatContainer
|
|
|
|
messages={messages}
|
|
|
|
usernameToHighlight={chatDisplayName}
|
|
|
|
chatUserId={chatUserId}
|
|
|
|
isModerator={false}
|
|
|
|
height="40vh"
|
|
|
|
/>
|
|
|
|
</TabPane>
|
|
|
|
)}
|
2022-09-10 22:08:22 +03:00
|
|
|
<TabPane tab="About" key="2">
|
|
|
|
<ContentHeader
|
|
|
|
name={name}
|
|
|
|
title={streamTitle}
|
|
|
|
summary={summary}
|
|
|
|
tags={tags}
|
|
|
|
links={socialHandles}
|
|
|
|
logo="/logo"
|
|
|
|
/>
|
|
|
|
<CustomPageContent content={extraPageContent} />
|
|
|
|
</TabPane>
|
|
|
|
<TabPane tab="Followers" key="3">
|
|
|
|
<FollowerCollection />
|
|
|
|
</TabPane>
|
|
|
|
</Tabs>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export const Content: FC = () => {
|
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-09-11 06:03:58 +03:00
|
|
|
const isChatAvailable = useRecoilValue<boolean>(isChatAvailableSelector);
|
|
|
|
|
2022-07-08 10:10:18 +03:00
|
|
|
const [isMobile, setIsMobile] = useRecoilState<boolean | undefined>(isMobileAtom);
|
2022-09-10 22:08:22 +03:00
|
|
|
const messages = useRecoilValue<ChatMessage[]>(chatMessagesAtom);
|
2022-05-26 06:38:40 +03:00
|
|
|
const online = useRecoilValue<boolean>(isOnlineSelector);
|
2022-09-10 22:08:22 +03:00
|
|
|
const chatDisplayName = useRecoilValue<string>(chatDisplayNameAtom);
|
|
|
|
const chatUserId = useRecoilValue<string>(chatUserIdAtom);
|
2022-08-17 03:49:21 +03:00
|
|
|
const { viewerCount, lastConnectTime, lastDisconnectTime, streamTitle } =
|
2022-07-13 00:10:59 +03:00
|
|
|
useRecoilValue<ServerStatus>(serverStatusState);
|
2022-08-17 03:49:21 +03:00
|
|
|
const {
|
|
|
|
extraPageContent,
|
|
|
|
version,
|
|
|
|
name,
|
|
|
|
summary,
|
|
|
|
socialHandles,
|
|
|
|
tags,
|
|
|
|
externalActions,
|
|
|
|
offlineMessage,
|
2022-09-11 06:03:58 +03:00
|
|
|
chatDisabled,
|
2022-10-09 01:05:52 +03:00
|
|
|
federation,
|
|
|
|
notifications,
|
2022-08-17 03:49:21 +03:00
|
|
|
} = clientConfig;
|
2022-06-27 09:01:52 +03:00
|
|
|
const [showNotifyReminder, setShowNotifyReminder] = useState(false);
|
|
|
|
const [showNotifyPopup, setShowNotifyPopup] = useState(false);
|
2022-10-09 01:05:52 +03:00
|
|
|
const { account: fediverseAccount } = federation;
|
|
|
|
const { browser: browserNotifications } = notifications;
|
|
|
|
const { enabled: browserNotificationsEnabled } = browserNotifications;
|
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-09-11 06:03:58 +03:00
|
|
|
const showChat = !chatDisabled && isChatAvailable && isChatVisible;
|
2022-09-11 04:08:51 +03:00
|
|
|
|
2022-04-28 19:54:33 +03:00
|
|
|
return (
|
2022-08-30 09:33:30 +03:00
|
|
|
<div>
|
2022-09-11 04:08:51 +03:00
|
|
|
<Spin className={styles.loadingSpinner} size="large" spinning={appState.appLoading}>
|
|
|
|
<AntContent className={styles.root}>
|
|
|
|
<div className={styles.leftContent}>
|
|
|
|
<div className={styles.topSection}>
|
|
|
|
{online && <OwncastPlayer source="/hls/stream.m3u8" online={online} />}
|
|
|
|
{!online && !appState.appLoading && (
|
2022-10-09 01:05:52 +03:00
|
|
|
<OfflineBanner
|
|
|
|
streamName={name}
|
|
|
|
customText={offlineMessage}
|
|
|
|
notificationsEnabled={browserNotificationsEnabled}
|
|
|
|
fediverseAccount={fediverseAccount}
|
|
|
|
lastLive={lastDisconnectTime}
|
|
|
|
onNotifyClick={() => setShowNotifyPopup(true)}
|
|
|
|
/>
|
2022-09-11 04:08:51 +03:00
|
|
|
)}
|
|
|
|
<Statusbar
|
|
|
|
online={online}
|
|
|
|
lastConnectTime={lastConnectTime}
|
|
|
|
lastDisconnectTime={lastDisconnectTime}
|
|
|
|
viewerCount={viewerCount}
|
2022-08-30 09:33:30 +03:00
|
|
|
/>
|
2022-09-11 04:08:51 +03:00
|
|
|
</div>
|
|
|
|
<div className={styles.midSection}>
|
|
|
|
<div className={styles.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-08-30 09:33:30 +03:00
|
|
|
>
|
2022-09-11 04:08:51 +03:00
|
|
|
<BrowserNotifyModal />
|
|
|
|
</Modal>
|
|
|
|
</div>
|
2022-08-30 09:33:30 +03:00
|
|
|
</div>
|
2022-09-11 04:08:51 +03:00
|
|
|
{isMobile && isChatVisible ? (
|
|
|
|
<MobileContent
|
|
|
|
name={name}
|
|
|
|
streamTitle={streamTitle}
|
|
|
|
summary={summary}
|
|
|
|
tags={tags}
|
|
|
|
socialHandles={socialHandles}
|
|
|
|
extraPageContent={extraPageContent}
|
|
|
|
messages={messages}
|
|
|
|
chatDisplayName={chatDisplayName}
|
|
|
|
chatUserId={chatUserId}
|
2022-09-11 06:03:58 +03:00
|
|
|
showChat={showChat}
|
2022-09-11 04:08:51 +03:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<DesktopContent
|
|
|
|
name={name}
|
|
|
|
streamTitle={streamTitle}
|
|
|
|
summary={summary}
|
|
|
|
tags={tags}
|
|
|
|
socialHandles={socialHandles}
|
|
|
|
extraPageContent={extraPageContent}
|
|
|
|
/>
|
|
|
|
)}
|
2022-08-30 09:33:30 +03:00
|
|
|
</div>
|
2022-09-11 06:03:58 +03:00
|
|
|
{showChat && !isMobile && <Sidebar />}
|
2022-09-11 04:08:51 +03:00
|
|
|
</AntContent>
|
2022-09-11 06:03:58 +03:00
|
|
|
{(!isMobile || !showChat) && <Footer version={version} />}
|
2022-09-11 04:08:51 +03:00
|
|
|
</Spin>
|
2022-08-30 09:33:30 +03:00
|
|
|
</div>
|
2022-04-28 19:54:33 +03:00
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|
|
|
|
export default Content;
|