import { useTheme, useMediaQuery, Stack, Paper, Typography, Button, Box, Divider, } from "@mui/material"; import { useEffect, Fragment, ReactElement, ReactChildren } from "react"; import { WikiSpace } from "@hyper-hyper-space/wiki-collab"; import WikiSpacePage from "./WikiSpacePage"; import { Outlet, Route, Routes, useNavigate, useOutletContext, useParams, } from "react-router"; import NewPage from "./NewPage"; import WikiSpaceNavigation from "./WikiSpaceNavigation"; import { SpaceContext } from "../SpaceFrame"; import "./WikiSpaceView.css"; import WikiSpaceSettingsPage from "./WikiSpaceSettingsPage"; type WikiNav = { goToPage: (pageName: string) => void; goToAddPage: () => void; goToIndex: () => void; goToPermissionSettings: () => void; }; type WikiContext = { wiki: WikiSpace; nav: WikiNav; spaceContext: SpaceContext; }; function WikiSpaceView(props: { entryPoint: WikiSpace; path?: string }) { const spaceContext = useOutletContext(); const wiki = props.entryPoint; useEffect(() => { wiki.startSync(); return () => { wiki.stopSync(); wiki.title?.dontWatchForChanges(); }; }, [wiki]); const navigate = useNavigate(); const goToPage = (pageName: string) => { navigate( "/space/" + encodeURIComponent(wiki.getLastHash()) + "/contents/" + encodeURIComponent(pageName) ); }; const goToAddPage = () => { navigate("/space/" + encodeURIComponent(wiki.getLastHash()) + "/add-page"); }; const goToIndex = () => { navigate("/space/" + encodeURIComponent(wiki.getLastHash()) + "/index"); }; const goToPermissionSettings = () => { navigate( "/space/" + encodeURIComponent(wiki.getLastHash()) + "/settings/permissions" ); }; const context: WikiContext = { wiki: wiki, nav: { goToPage: goToPage, goToAddPage: goToAddPage, goToIndex: goToIndex, goToPermissionSettings, }, spaceContext: spaceContext, }; const theme = useTheme(); const tablet = useMediaQuery(theme.breakpoints.down("md")); const noNavigation = useMediaQuery(theme.breakpoints.down("md")); const navigationWidth = noNavigation ? "100%" : tablet ? "20%" : "22%"; const contentWidth = noNavigation ? "100%" : tablet ? "80%" : "78%"; const BackToIndexButton = () => ( <> ); const Frame: React.FC<{ title?: string }> = ({ children, title }) => { const { pageName } = useParams(); return (
{noNavigation && } {!noNavigation && }
{title || pageName} {children}
); }; return ( } > Fetching wiki contents... } /> } /> } /> } /> } /> ); } export type { WikiContext }; export default WikiSpaceView;