import React, { FC, ReactNode, useContext, useEffect, useState } from 'react'; import Link from 'next/link'; import Head from 'next/head'; import { differenceInSeconds } from 'date-fns'; import { useRouter } from 'next/router'; import { Layout, Menu, Alert, Button, Space, Tooltip } from 'antd'; import classNames from 'classnames'; import dynamic from 'next/dynamic'; import { upgradeVersionAvailable } from '../../utils/apis'; import { parseSecondsToDurationString } from '../../utils/format'; import { OwncastLogo } from '../common/OwncastLogo/OwncastLogo'; import { ServerStatusContext } from '../../utils/server-status-context'; import { AlertMessageContext } from '../../utils/alert-message-context'; import { TextFieldWithSubmit } from './TextFieldWithSubmit'; import { TEXTFIELD_PROPS_STREAM_TITLE } from '../../utils/config-constants'; import { ComposeFederatedPost } from './ComposeFederatedPost'; import { UpdateArgs } from '../../types/config-section'; // Lazy loaded components const SettingOutlined = dynamic(() => import('@ant-design/icons/SettingOutlined'), { ssr: false, }); // Lazy loaded components const HomeOutlined = dynamic(() => import('@ant-design/icons/HomeOutlined'), { ssr: false, }); const LineChartOutlined = dynamic(() => import('@ant-design/icons/LineChartOutlined'), { ssr: false, }); const ToolOutlined = dynamic(() => import('@ant-design/icons/ToolOutlined'), { ssr: false, }); const PlayCircleFilled = dynamic(() => import('@ant-design/icons/PlayCircleFilled'), { ssr: false, }); const MinusSquareFilled = dynamic(() => import('@ant-design/icons/MinusSquareFilled'), { ssr: false, }); const QuestionCircleOutlined = dynamic(() => import('@ant-design/icons/QuestionCircleOutlined'), { ssr: false, }); const MessageOutlined = dynamic(() => import('@ant-design/icons/MessageOutlined'), { ssr: false, }); const ExperimentOutlined = dynamic(() => import('@ant-design/icons/ExperimentOutlined'), { ssr: false, }); const EditOutlined = dynamic(() => import('@ant-design/icons/EditOutlined'), { ssr: false, }); export type MainLayoutProps = { children: ReactNode; }; export const MainLayout: FC = ({ children }) => { const context = useContext(ServerStatusContext); const { serverConfig, online, broadcaster, versionNumber } = context || {}; const { instanceDetails, chatDisabled, federation } = serverConfig; const { enabled: federationEnabled } = federation; const [currentStreamTitle, setCurrentStreamTitle] = useState(''); const [postModalDisplayed, setPostModalDisplayed] = useState(false); const alertMessage = useContext(AlertMessageContext); const router = useRouter(); const { route } = router || {}; const { Header, Footer, Content, Sider } = Layout; const [upgradeVersion, setUpgradeVersion] = useState(''); const checkForUpgrade = async () => { try { const result = await upgradeVersionAvailable(versionNumber); setUpgradeVersion(result); } catch (error) { console.log('==== error', error); } }; useEffect(() => { checkForUpgrade(); }, [versionNumber]); useEffect(() => { setCurrentStreamTitle(instanceDetails.streamTitle); }, [instanceDetails]); const handleStreamTitleChanged = ({ value }: UpdateArgs) => { setCurrentStreamTitle(value); }; const handleCreatePostButtonPressed = () => { setPostModalDisplayed(true); }; const appClass = classNames({ 'app-container': true, online, }); const upgradeVersionString = `${upgradeVersion}` || ''; const upgradeMessage = `Upgrade to v${upgradeVersionString}`; const openMenuItems = upgradeVersion ? ['utilities-menu'] : []; const clearAlertMessage = () => { alertMessage.setMessage(null); }; const headerAlertMessage = alertMessage.message ? ( ) : null; // status indicator items const streamDurationString = broadcaster ? parseSecondsToDurationString(differenceInSeconds(new Date(), new Date(broadcaster.time))) : ''; const statusIcon = online ? : ; const statusMessage = online ? `Online ${streamDurationString}` : 'Offline'; const statusIndicator = (
{statusMessage} {statusIcon}
); const integrationsMenu = [ { label: Webhooks, key: 'webhooks', }, { label: Access Tokens, key: 'access-tokens', }, { label: External Actions, key: 'actions', }, ]; const chatMenu = [ { label: Messages, key: 'messages', }, { label: Users, key: 'chat-users', }, { label: Emojis, key: 'emojis', }, ]; const utilitiesMenu = [ { label: Hardware, key: 'hardware-info', }, { label: Stream Health, key: 'stream-health', }, { label: Logs, key: 'logs', }, federationEnabled && { label: Social Actions, key: 'federation-activities', }, ]; const configurationMenu = [ { label: General, key: 'config-public-details', }, { label: Server Setup, key: 'config-server', }, { label: Video, key: 'config-video', }, { label: Chat, key: 'config-chat', }, { label: Social, key: 'config-federation', }, { label: Notifications, key: 'config-notify', }, ]; const menuItems = [ { label: Home, icon: , key: 'home' }, { label: Viewers, icon: , key: 'viewer-info', }, !chatDisabled && { label: Chat & Users, icon: , children: chatMenu, key: 'chat-and-users', }, federationEnabled && { key: 'fediverse-followers', label: Followers, icon: ( fediverse icon ), }, { key: 'configuration', label: 'Configuration', icon: , children: configurationMenu, }, { key: 'utilities', label: 'Utilities', icon: , children: utilitiesMenu, }, { key: 'integrations', label: 'Integrations', icon: , children: integrationsMenu, }, upgradeVersion && { key: 'upgrade', label: {upgradeMessage}, }, { key: 'help', label: Help, icon: , }, ]; return ( Owncast Admin

Owncast Admin

{statusIndicator}
{headerAlertMessage} {children}
setPostModalDisplayed(false)} /> ); };