owncast/web/pages/components/main-layout.tsx

138 lines
4.2 KiB
TypeScript
Raw Normal View History

import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import Link from 'next/link';
2020-11-03 02:23:32 +01:00
import { differenceInSeconds } from "date-fns";
import { useRouter } from 'next/router';
import { Layout, Menu } from 'antd';
import {
SettingOutlined,
HomeOutlined,
LineChartOutlined,
CloseCircleOutlined,
PlayCircleFilled,
2020-10-23 02:16:28 +02:00
MinusSquareFilled,
} from '@ant-design/icons';
2020-10-23 02:16:28 +02:00
import classNames from 'classnames';
2020-11-03 02:23:32 +01:00
import {parseSecondsToDurationString} from '../../utils/format'
import OwncastLogo from './logo';
2020-11-01 08:01:37 +01:00
import { BroadcastStatusContext } from '../../utils/broadcast-status-context';
import adminStyles from '../../styles/styles.module.css';
export default function MainLayout(props) {
const { children } = props;
const context = useContext(BroadcastStatusContext);
const { broadcastActive } = context || {};
const router = useRouter();
const { route } = router || {};
const { Header, Footer, Content, Sider } = Layout;
const { SubMenu } = Menu;
2020-11-03 02:23:32 +01:00
const streamDurationString = broadcastActive ?
parseSecondsToDurationString(differenceInSeconds(new Date(), new Date(context.broadcaster.time))) : ""
2020-10-23 02:16:28 +02:00
const statusIcon = broadcastActive ?
<PlayCircleFilled /> : <MinusSquareFilled />;
2020-11-03 02:23:32 +01:00
const statusMessage = broadcastActive
? `Online ${ streamDurationString}`
: "Offline";
const appClass = classNames({
'owncast-layout': true,
[adminStyles.online]: broadcastActive,
})
return (
<Layout className={appClass}>
<Sider
width={240}
style={{
2020-10-29 18:16:13 +01:00
overflow: "auto",
height: "100vh",
}}
>
<Menu
theme="dark"
defaultSelectedKeys={[route.substring(1)]}
2020-10-29 18:16:13 +01:00
defaultOpenKeys={["current-stream-menu", "utilities-menu"]}
mode="inline"
>
<h1 className={adminStyles.owncastTitleContainer}>
<span className={adminStyles.logoContainer}>
<OwncastLogo />
</span>
<span className={adminStyles.owncastTitle}>Owncast Admin</span>
</h1>
<Menu.Item key="home" icon={<HomeOutlined />}>
2020-10-23 02:16:28 +02:00
<Link href="/">Home</Link>
</Menu.Item>
2020-10-29 18:16:13 +01:00
<SubMenu
key="current-stream-menu"
icon={<LineChartOutlined />}
2020-11-01 03:29:06 +01:00
title="Current stream"
2020-10-29 18:16:13 +01:00
>
<Menu.Item key="viewer-info">
<Link href="/viewer-info">Viewers</Link>
</Menu.Item>
2020-10-29 18:16:13 +01:00
{broadcastActive ? (
<Menu.Item key="disconnect-stream" icon={<CloseCircleOutlined />}>
<Link href="/disconnect-stream">Disconnect Stream...</Link>
</Menu.Item>
2020-10-29 18:16:13 +01:00
) : null}
</SubMenu>
2020-10-29 18:16:13 +01:00
<SubMenu
2020-11-01 03:29:06 +01:00
key="configuration"
title="Configuration"
2020-10-29 18:16:13 +01:00
icon={<SettingOutlined />}
>
<Menu.Item key="update-server-config">
2020-10-26 05:39:25 +01:00
<Link href="/update-server-config">Server Configuration</Link>
</Menu.Item>
2020-10-29 18:16:13 +01:00
<Menu.Item key="video-config">
<Link href="/video-config">Video Configuration</Link>
</Menu.Item>
<Menu.Item key="storage">
<Link href="/storage">Storage</Link>
</Menu.Item>
2020-11-01 03:29:06 +01:00
</SubMenu>
<SubMenu
key="utilities-menu"
icon={<SettingOutlined />}
title="Utilities"
>
<Menu.Item key="hardware-info">
<Link href="/hardware-info">Hardware</Link>
</Menu.Item>
2020-10-30 02:01:38 +01:00
<Menu.Item key="logs">
<Link href="/logs">Logs</Link>
</Menu.Item>
</SubMenu>
</Menu>
</Sider>
<Layout>
<Header className={adminStyles.header}>
<div className={adminStyles.statusIndicatorContainer}>
2020-10-29 18:16:13 +01:00
<span className={adminStyles.statusLabel}>{statusMessage}</span>
<span className={adminStyles.statusIcon}>{statusIcon}</span>
</div>
</Header>
2020-10-29 18:16:13 +01:00
<Content className={adminStyles.contentMain}>{children}</Content>
<Footer style={{ textAlign: "center" }}>
<a href="https://owncast.online/">About Owncast</a>
</Footer>
</Layout>
</Layout>
);
}
MainLayout.propTypes = {
children: PropTypes.element.isRequired,
};