import React, { useContext, useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import Link from 'next/link'; import { differenceInSeconds } from "date-fns"; import { useRouter } from 'next/router'; import { Layout, Menu } from 'antd'; import { SettingOutlined, HomeOutlined, LineChartOutlined, CloseCircleOutlined, PlayCircleFilled, MinusSquareFilled, } from '@ant-design/icons'; import classNames from 'classnames'; import { upgradeVersionAvailable } from "../../utils/apis"; import { parseSecondsToDurationString } from '../../utils/format' import OwncastLogo from './logo'; import { ServerStatusContext } from '../../utils/server-status-context'; import adminStyles from '../../styles/styles.module.css'; let performedUpgradeCheck = false; export default function MainLayout(props) { const { children } = props; const context = useContext(ServerStatusContext); const { online, broadcaster, versionNumber } = context || {}; const router = useRouter(); const { route } = router || {}; const { Header, Footer, Content, Sider } = Layout; const { SubMenu } = Menu; const streamDurationString = online ? parseSecondsToDurationString(differenceInSeconds(new Date(), new Date(broadcaster.time))) : ""; const statusIcon = online ? : ; const statusMessage = online ? `Online ${streamDurationString}` : "Offline"; const [upgradeVersion, setUpgradeVersion] = useState(null); const checkForUpgrade = async () => { try { const result = await upgradeVersionAvailable(versionNumber); setUpgradeVersion(result); } catch (error) { console.log("==== error", error); } }; useEffect(() => { if (!performedUpgradeCheck && !context.disableUpgradeChecks) { checkForUpgrade(); console.log('checking') performedUpgradeCheck = true } }); const appClass = classNames({ "owncast-layout": true, [adminStyles.online]: online, }); const upgradeMenuItemStyle = upgradeVersion ? 'block' : 'none'; const upgradeVersionString = upgradeVersion || ''; return ( Owncast Admin }> Home } title="Current stream" > Viewers {online ? ( }> Disconnect Stream... ) : null} } > Server Configuration Video Configuration Storage } title="Utilities" > Hardware Logs Upgrade to v{upgradeVersionString} {statusMessage} {statusIcon} {children} ); } MainLayout.propTypes = { children: PropTypes.element.isRequired, };