2024-08-26 17:39:27 +02:00
|
|
|
import { useEffect, useState } from 'react';
|
2025-02-20 21:44:10 +01:00
|
|
|
import { Outlet, Route, Routes, useLocation, useParams } from 'react-router-dom';
|
2025-02-20 22:02:01 +01:00
|
|
|
import { useAccountComment } from '@plebbit/plebbit-react-hooks';
|
2024-12-24 17:15:51 +01:00
|
|
|
import { initSnow, removeSnow } from './lib/snow';
|
2025-06-04 16:37:17 +02:00
|
|
|
import { isAllView, isModView, isSubscriptionsView } from './lib/utils/view-utils';
|
2025-03-05 12:01:48 +01:00
|
|
|
import useReplyModalStore from './stores/use-reply-modal-store';
|
2025-11-06 22:20:46 +01:00
|
|
|
import useCreateBoardModalStore from './stores/use-create-board-modal-store';
|
2025-03-05 12:01:48 +01:00
|
|
|
import useSpecialThemeStore from './stores/use-special-theme-store';
|
2024-05-31 15:16:21 +02:00
|
|
|
import useIsMobile from './hooks/use-is-mobile';
|
2024-08-29 14:18:20 +02:00
|
|
|
import useTheme from './hooks/use-theme';
|
2025-11-07 12:50:58 +01:00
|
|
|
import { useDefaultSubplebbits } from './hooks/use-default-subplebbits';
|
|
|
|
|
import { getSubplebbitAddress } from './lib/utils/route-utils';
|
2024-03-27 15:10:58 +01:00
|
|
|
import styles from './app.module.css';
|
2024-04-25 22:02:55 +02:00
|
|
|
import Board from './views/board';
|
2024-04-12 14:28:06 +02:00
|
|
|
import Catalog from './views/catalog';
|
2024-07-02 13:32:50 +02:00
|
|
|
import FAQ from './views/faq';
|
2024-03-20 13:00:11 +01:00
|
|
|
import Home from './views/home';
|
2024-05-06 21:40:17 +02:00
|
|
|
import NotFound from './views/not-found';
|
2024-04-25 22:02:55 +02:00
|
|
|
import PendingPost from './views/pending-post';
|
2024-06-11 15:49:26 +02:00
|
|
|
import Post from './views/post';
|
2024-04-25 22:02:55 +02:00
|
|
|
import { DesktopBoardButtons, MobileBoardButtons } from './components/board-buttons';
|
2024-05-31 15:16:21 +02:00
|
|
|
import BoardHeader from './components/board-header';
|
2024-04-25 22:02:55 +02:00
|
|
|
import ChallengeModal from './components/challenge-modal';
|
2025-11-06 22:20:46 +01:00
|
|
|
import CreateBoardModal from './components/create-board-modal';
|
2025-03-05 12:01:48 +01:00
|
|
|
import ReplyModal from './components/reply-modal';
|
2024-03-20 13:00:11 +01:00
|
|
|
import PostForm from './components/post-form';
|
2024-05-31 15:16:21 +02:00
|
|
|
import SubplebbitStats from './components/subplebbit-stats';
|
|
|
|
|
import TopBar from './components/topbar';
|
2025-03-05 12:06:27 +01:00
|
|
|
import SettingsModal from './components/settings-modal';
|
2024-02-27 17:58:08 +01:00
|
|
|
|
2024-10-29 17:40:09 +01:00
|
|
|
const BoardLayout = () => {
|
2025-11-07 12:50:58 +01:00
|
|
|
const { accountCommentIndex, boardIdentifier } = useParams();
|
2024-10-29 17:40:09 +01:00
|
|
|
const location = useLocation();
|
|
|
|
|
const isMobile = useIsMobile();
|
|
|
|
|
const isInAllView = isAllView(location.pathname);
|
|
|
|
|
const isInSubscriptionsView = isSubscriptionsView(location.pathname, useParams());
|
2025-06-04 16:37:17 +02:00
|
|
|
const isInModView = isModView(location.pathname);
|
2025-11-07 12:50:58 +01:00
|
|
|
const defaultSubplebbits = useDefaultSubplebbits();
|
|
|
|
|
const subplebbitAddress = boardIdentifier ? getSubplebbitAddress(boardIdentifier, defaultSubplebbits) : undefined;
|
2024-10-29 17:40:09 +01:00
|
|
|
const pendingPost = useAccountComment({ commentIndex: accountCommentIndex ? parseInt(accountCommentIndex) : undefined });
|
2025-11-06 22:20:46 +01:00
|
|
|
const { closeCreateBoardModal } = useCreateBoardModalStore();
|
2024-10-29 17:40:09 +01:00
|
|
|
|
2024-12-24 17:13:12 +01:00
|
|
|
// Christmas theme
|
|
|
|
|
const { isEnabled: isSpecialEnabled } = useSpecialThemeStore();
|
|
|
|
|
useEffect(() => {
|
2024-12-25 17:11:14 +01:00
|
|
|
if (isSpecialEnabled && !isMobile) {
|
2024-12-24 17:13:12 +01:00
|
|
|
initSnow({ flakeCount: 150 });
|
|
|
|
|
}
|
|
|
|
|
return () => {
|
|
|
|
|
removeSnow();
|
|
|
|
|
};
|
2024-12-25 17:11:56 +01:00
|
|
|
}, [isSpecialEnabled, isMobile]);
|
2024-12-24 17:13:12 +01:00
|
|
|
|
2025-11-06 22:20:46 +01:00
|
|
|
// Close create board modal when navigating to a different page
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
closeCreateBoardModal();
|
|
|
|
|
}, [location.pathname, closeCreateBoardModal]);
|
|
|
|
|
|
2024-08-06 22:34:27 +02:00
|
|
|
// 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}`;
|
2024-04-27 12:41:54 +02:00
|
|
|
|
2024-04-23 21:37:03 +02:00
|
|
|
return (
|
2024-05-05 15:55:24 +02:00
|
|
|
<div className={styles.boardLayout}>
|
2024-05-29 21:00:13 +02:00
|
|
|
<TopBar />
|
2025-11-06 22:20:46 +01:00
|
|
|
<CreateBoardModal />
|
2024-05-29 21:00:13 +02:00
|
|
|
<BoardHeader />
|
2024-06-04 10:30:01 +02:00
|
|
|
{isMobile
|
2025-06-04 16:37:17 +02:00
|
|
|
? (subplebbitAddress || isInAllView || isInModView || isInSubscriptionsView || pendingPost?.subplebbitAddress) && (
|
2024-06-04 10:30:01 +02:00
|
|
|
<>
|
2024-09-08 10:41:08 +02:00
|
|
|
<PostForm key={key} />
|
2025-03-06 15:44:26 +01:00
|
|
|
<hr />
|
|
|
|
|
<MobileBoardButtons />
|
2024-06-04 10:30:01 +02:00
|
|
|
</>
|
|
|
|
|
)
|
2025-06-04 16:37:17 +02:00
|
|
|
: (subplebbitAddress || isInAllView || isInModView || isInSubscriptionsView || pendingPost?.subplebbitAddress) && (
|
2024-06-04 10:30:01 +02:00
|
|
|
<>
|
|
|
|
|
<PostForm key={key} />
|
2025-06-04 16:37:17 +02:00
|
|
|
{!(isInAllView || isInSubscriptionsView || isInModView) && <SubplebbitStats />}
|
2024-06-04 10:30:01 +02:00
|
|
|
<DesktopBoardButtons />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2024-04-23 21:37:03 +02:00
|
|
|
<Outlet />
|
2024-05-05 15:55:24 +02:00
|
|
|
</div>
|
2024-04-23 21:37:03 +02:00
|
|
|
);
|
|
|
|
|
};
|
2024-04-27 12:41:54 +02:00
|
|
|
|
2024-06-17 12:17:36 +02:00
|
|
|
const GlobalLayout = () => {
|
2024-08-26 17:39:27 +02:00
|
|
|
const [theme, setTheme] = useState('');
|
|
|
|
|
const [currentTheme] = useTheme();
|
2024-08-26 11:32:40 +02:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-08-26 17:39:27 +02:00
|
|
|
if (currentTheme !== theme) {
|
|
|
|
|
setTheme(currentTheme);
|
|
|
|
|
}
|
|
|
|
|
}, [currentTheme, theme]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (theme) {
|
|
|
|
|
document.body.classList.add(theme);
|
|
|
|
|
return () => {
|
|
|
|
|
document.body.classList.remove(theme);
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-08-26 11:32:40 +02:00
|
|
|
}, [theme]);
|
2024-06-17 12:17:36 +02:00
|
|
|
|
2025-03-05 12:01:48 +01:00
|
|
|
const { activeCid, threadCid, subplebbitAddress, closeModal, showReplyModal, scrollY } = useReplyModalStore();
|
|
|
|
|
|
2025-03-05 12:06:27 +01:00
|
|
|
const location = useLocation();
|
|
|
|
|
const isInSettingsView = location.pathname.endsWith('/settings');
|
|
|
|
|
|
2024-06-17 12:17:36 +02:00
|
|
|
return (
|
2024-04-25 22:02:55 +02:00
|
|
|
<>
|
|
|
|
|
<ChallengeModal />
|
2025-03-05 12:01:48 +01:00
|
|
|
{activeCid && threadCid && subplebbitAddress && (
|
|
|
|
|
<ReplyModal
|
|
|
|
|
closeModal={closeModal}
|
|
|
|
|
parentCid={activeCid}
|
|
|
|
|
postCid={threadCid}
|
|
|
|
|
scrollY={scrollY}
|
|
|
|
|
showReplyModal={showReplyModal}
|
|
|
|
|
subplebbitAddress={subplebbitAddress}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2025-03-05 12:06:27 +01:00
|
|
|
{isInSettingsView && <SettingsModal />}
|
2024-04-25 22:02:55 +02:00
|
|
|
<Outlet />
|
|
|
|
|
</>
|
|
|
|
|
);
|
2024-06-17 12:17:36 +02:00
|
|
|
};
|
2024-03-17 21:47:16 +01:00
|
|
|
|
2025-11-03 22:06:18 +01:00
|
|
|
const App = () => (
|
|
|
|
|
<div className={styles.app}>
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route element={<GlobalLayout />}>
|
|
|
|
|
<Route path='/' element={<Home />} />
|
|
|
|
|
<Route path='/faq' element={<FAQ />} />
|
|
|
|
|
<Route element={<BoardLayout />}>
|
2025-11-07 12:50:58 +01:00
|
|
|
<Route path='/all/:timeFilterName?' element={<Board />} />
|
|
|
|
|
<Route path='/all/:timeFilterName?/settings' element={<Board />} />
|
|
|
|
|
<Route path='/all/description' element={<Post />} />
|
|
|
|
|
<Route path='/all/catalog/:timeFilterName?' element={<Catalog />} />
|
|
|
|
|
<Route path='/all/catalog/:timeFilterName?/settings' element={<Catalog />} />
|
2025-06-07 18:41:16 +02:00
|
|
|
|
2025-11-07 12:50:58 +01:00
|
|
|
<Route path='/subscriptions/:timeFilterName?' element={<Board />} />
|
|
|
|
|
<Route path='/subscriptions/:timeFilterName?/settings' element={<Board />} />
|
|
|
|
|
<Route path='/subscriptions/catalog/:timeFilterName?' element={<Catalog />} />
|
|
|
|
|
<Route path='/subscriptions/catalog/:timeFilterName?/settings' element={<Catalog />} />
|
2024-07-02 13:32:50 +02:00
|
|
|
|
2025-11-07 12:50:58 +01:00
|
|
|
<Route path='/mod/:timeFilterName?' element={<Board />} />
|
|
|
|
|
<Route path='/mod/:timeFilterName?/settings' element={<Board />} />
|
|
|
|
|
<Route path='/mod/catalog/:timeFilterName?' element={<Catalog />} />
|
|
|
|
|
<Route path='/mod/catalog/:timeFilterName?/settings' element={<Catalog />} />
|
2024-04-25 22:02:55 +02:00
|
|
|
|
2025-11-07 12:50:58 +01:00
|
|
|
<Route path='/pending/:accountCommentIndex' element={<PendingPost />} />
|
|
|
|
|
<Route path='/pending/:accountCommentIndex/settings' element={<PendingPost />} />
|
2024-04-25 22:02:55 +02:00
|
|
|
|
2025-11-07 12:50:58 +01:00
|
|
|
<Route path='/:boardIdentifier' element={<Board />} />
|
|
|
|
|
<Route path='/:boardIdentifier/settings' element={<Board />} />
|
|
|
|
|
<Route path='/:boardIdentifier/catalog' element={<Catalog />} />
|
|
|
|
|
<Route path='/:boardIdentifier/catalog/settings' element={<Catalog />} />
|
2024-05-17 17:25:25 +02:00
|
|
|
|
2025-11-07 12:50:58 +01:00
|
|
|
<Route path='/:boardIdentifier/thread/:commentCid' element={<Post />} />
|
|
|
|
|
<Route path='/:boardIdentifier/thread/:commentCid/settings' element={<Post />} />
|
|
|
|
|
<Route path='/:boardIdentifier/description' element={<Post />} />
|
|
|
|
|
<Route path='/:boardIdentifier/description/settings' element={<Post />} />
|
|
|
|
|
<Route path='/:boardIdentifier/rules' element={<Post />} />
|
|
|
|
|
<Route path='/:boardIdentifier/rules/settings' element={<Post />} />
|
2024-03-18 15:04:30 +01:00
|
|
|
</Route>
|
2025-11-03 22:06:18 +01:00
|
|
|
<Route path='/not-found' element={<NotFound />} />
|
2025-11-07 12:50:58 +01:00
|
|
|
<Route path='*' element={<NotFound />} />
|
2025-11-03 22:06:18 +01:00
|
|
|
</Route>
|
|
|
|
|
</Routes>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2024-02-27 17:58:08 +01:00
|
|
|
|
|
|
|
|
export default App;
|