import { useEffect, useState } from 'react'; import { Outlet, Route, Routes, useLocation, useParams } from 'react-router-dom'; import { useAccountComment } from '@plebbit/plebbit-react-hooks'; import { isAllView, isSubscriptionsView } from './lib/utils/view-utils'; import useIsMobile from './hooks/use-is-mobile'; import useTheme from './hooks/use-theme'; import { timeFilterNames } from './hooks/use-time-filter'; import styles from './app.module.css'; import Board from './views/board'; import Catalog from './views/catalog'; import FAQ from './views/faq'; import Home from './views/home'; import NotFound from './views/not-found'; import PendingPost from './views/pending-post'; import Post from './views/post'; import { DesktopBoardButtons, MobileBoardButtons } from './components/board-buttons'; import BoardHeader from './components/board-header'; import ChallengeModal from './components/challenge-modal'; import PostForm from './components/post-form'; import SubplebbitStats from './components/subplebbit-stats'; import TopBar from './components/topbar'; const BoardLayout = () => { const { accountCommentIndex, subplebbitAddress, timeFilterName } = useParams(); const location = useLocation(); const isMobile = useIsMobile(); const isInAllView = isAllView(location.pathname, useParams()); const isInSubscriptionsView = isSubscriptionsView(location.pathname, useParams()); const pendingPost = useAccountComment({ commentIndex: accountCommentIndex ? parseInt(accountCommentIndex) : undefined }); const isValidAccountCommentIndex = !accountCommentIndex || (!isNaN(Number(accountCommentIndex)) && Number(accountCommentIndex) >= 0); if (!isValidAccountCommentIndex || (timeFilterName && !timeFilterNames.includes(timeFilterName))) { return ; } // force rerender of post form when navigating between pages, except when opening settings modal in current view const key = location.pathname.endsWith('/settings') ? `${subplebbitAddress}-${location.pathname.replace(/\/settings$/, '')}` : `${subplebbitAddress}-${location.pathname}`; return (
{isMobile ? (subplebbitAddress || isInAllView || isInSubscriptionsView || pendingPost?.subplebbitAddress) && ( <> ) : (subplebbitAddress || isInAllView || isInSubscriptionsView || pendingPost?.subplebbitAddress) && ( <> {!(isInAllView || isInSubscriptionsView) && } )}
); }; const GlobalLayout = () => { const [theme, setTheme] = useState(''); const [currentTheme] = useTheme(); useEffect(() => { if (currentTheme !== theme) { setTheme(currentTheme); } }, [currentTheme, theme]); useEffect(() => { if (theme) { document.body.classList.add(theme); return () => { document.body.classList.remove(theme); }; } }, [theme]); return ( <> ); }; const App = () => { return (
}> } /> } /> } /> }> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } />
); }; export default App;