import { observer } from "mobx-react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; import type Share from "~/models/Share"; import Flex from "~/components/Flex"; import Scrollable from "~/components/Scrollable"; import SearchPopover from "~/components/SearchPopover"; import useCurrentUser from "~/hooks/useCurrentUser"; import useStores from "~/hooks/useStores"; import history from "~/utils/history"; import { homePath, sharedModelPath } from "~/utils/routeHelpers"; import { AvatarSize } from "../Avatar"; import { useTeamContext } from "../TeamContext"; import TeamLogo from "../TeamLogo"; import Sidebar from "./Sidebar"; import Section from "./components/Section"; import { SharedCollectionLink } from "./components/SharedCollectionLink"; import { SharedDocumentLink } from "./components/SharedDocumentLink"; import SidebarButton from "./components/SidebarButton"; import { useEffect } from "react"; import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper"; type Props = { share: Share; }; function SharedSidebar({ share }: Props) { const team = useTeamContext(); const user = useCurrentUser({ rejectOnEmpty: false }); const { ui, documents, collections } = useStores(); const { t } = useTranslation(); const teamAvailable = !!team?.name; const rootNode = share.tree; const shareId = share.urlId || share.id; const collection = collections.get(rootNode?.id); const hideRootNode = collection ? ProsemirrorHelper.isEmptyData(collection?.data) : false; useEffect(() => { ui.tocVisible = share.showTOC; }, []); if (!rootNode?.children.length) { return null; } return ( {teamAvailable && ( } disabled={hideRootNode} onClick={ hideRootNode ? undefined : () => history.push(user ? homePath() : sharedModelPath(shareId)) } /> )}
{share.collectionId ? ( ) : ( )}
); } const ScrollContainer = styled(Scrollable)` padding-bottom: 16px; `; const TopSection = styled(Flex)` padding: 8px; flex-shrink: 0; `; const SearchWrapper = styled.div` width: 100%; `; const StyledSearchPopover = styled(SearchPopover)` width: 100%; transition: width 100ms ease-out; margin: 8px 0; `; export default observer(SharedSidebar);