2018-02-11 07:24:12 +00:00
|
|
|
// @flow
|
2021-01-21 15:22:20 +00:00
|
|
|
import { observer } from "mobx-react";
|
2019-04-06 23:20:27 +00:00
|
|
|
import {
|
|
|
|
EditIcon,
|
2021-08-23 07:37:28 +00:00
|
|
|
SearchIcon,
|
|
|
|
ShapesIcon,
|
2021-07-20 19:19:41 +00:00
|
|
|
HomeIcon,
|
2021-01-21 15:22:20 +00:00
|
|
|
SettingsIcon,
|
2020-06-20 20:59:15 +00:00
|
|
|
} from "outline-icons";
|
2020-08-09 05:53:59 +00:00
|
|
|
import * as React from "react";
|
2021-03-10 02:41:30 +00:00
|
|
|
import { DndProvider } from "react-dnd";
|
|
|
|
import { HTML5Backend } from "react-dnd-html5-backend";
|
2021-01-21 15:22:20 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2020-08-09 05:53:59 +00:00
|
|
|
import styled from "styled-components";
|
2021-02-10 04:13:09 +00:00
|
|
|
import Bubble from "components/Bubble";
|
2020-07-10 05:33:07 +00:00
|
|
|
import Flex from "components/Flex";
|
2020-06-20 20:59:15 +00:00
|
|
|
import Scrollable from "components/Scrollable";
|
2020-08-09 05:53:59 +00:00
|
|
|
import Sidebar from "./Sidebar";
|
2021-07-20 19:19:41 +00:00
|
|
|
import ArchiveLink from "./components/ArchiveLink";
|
2020-06-20 20:59:15 +00:00
|
|
|
import Collections from "./components/Collections";
|
2020-08-09 05:53:59 +00:00
|
|
|
import Section from "./components/Section";
|
2021-10-24 19:30:27 +00:00
|
|
|
import SidebarAction from "./components/SidebarAction";
|
2020-08-09 05:53:59 +00:00
|
|
|
import SidebarLink from "./components/SidebarLink";
|
2021-08-23 07:37:28 +00:00
|
|
|
import Starred from "./components/Starred";
|
2021-02-14 21:18:33 +00:00
|
|
|
import TeamButton from "./components/TeamButton";
|
2021-07-20 19:19:41 +00:00
|
|
|
import TrashLink from "./components/TrashLink";
|
2021-10-24 19:30:27 +00:00
|
|
|
import { inviteUser } from "actions/definitions/users";
|
2021-07-20 19:19:41 +00:00
|
|
|
import useCurrentTeam from "hooks/useCurrentTeam";
|
|
|
|
import useCurrentUser from "hooks/useCurrentUser";
|
2021-01-21 15:22:20 +00:00
|
|
|
import useStores from "hooks/useStores";
|
2020-08-09 05:53:59 +00:00
|
|
|
import AccountMenu from "menus/AccountMenu";
|
2021-10-24 19:30:27 +00:00
|
|
|
import {
|
|
|
|
homePath,
|
|
|
|
searchUrl,
|
|
|
|
draftsPath,
|
|
|
|
templatesPath,
|
|
|
|
settingsPath,
|
|
|
|
} from "utils/routeHelpers";
|
2018-02-11 07:24:12 +00:00
|
|
|
|
2021-01-21 15:22:20 +00:00
|
|
|
function MainSidebar() {
|
|
|
|
const { t } = useTranslation();
|
2021-07-20 19:19:41 +00:00
|
|
|
const { policies, documents } = useStores();
|
|
|
|
const team = useCurrentTeam();
|
|
|
|
const user = useCurrentUser();
|
2019-06-25 05:14:59 +00:00
|
|
|
|
2021-01-21 15:22:20 +00:00
|
|
|
React.useEffect(() => {
|
|
|
|
documents.fetchDrafts();
|
|
|
|
documents.fetchTemplates();
|
|
|
|
}, [documents]);
|
2018-06-23 22:27:16 +00:00
|
|
|
|
2021-03-10 02:41:30 +00:00
|
|
|
const [dndArea, setDndArea] = React.useState();
|
|
|
|
const handleSidebarRef = React.useCallback((node) => setDndArea(node), []);
|
|
|
|
const html5Options = React.useMemo(() => ({ rootElement: dndArea }), [
|
|
|
|
dndArea,
|
|
|
|
]);
|
|
|
|
|
2021-01-21 15:22:20 +00:00
|
|
|
const can = policies.abilities(team.id);
|
2019-01-07 00:25:05 +00:00
|
|
|
|
2021-01-21 15:22:20 +00:00
|
|
|
return (
|
2021-03-10 02:41:30 +00:00
|
|
|
<Sidebar ref={handleSidebarRef}>
|
|
|
|
{dndArea && (
|
|
|
|
<DndProvider backend={HTML5Backend} options={html5Options}>
|
|
|
|
<AccountMenu>
|
|
|
|
{(props) => (
|
|
|
|
<TeamButton
|
|
|
|
{...props}
|
|
|
|
subheading={user.name}
|
|
|
|
teamName={team.name}
|
|
|
|
logoUrl={team.avatarUrl}
|
|
|
|
showDisclosure
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</AccountMenu>
|
|
|
|
<Scrollable flex topShadow>
|
|
|
|
<Section>
|
|
|
|
<SidebarLink
|
2021-10-24 19:30:27 +00:00
|
|
|
to={homePath()}
|
2021-03-10 02:41:30 +00:00
|
|
|
icon={<HomeIcon color="currentColor" />}
|
|
|
|
exact={false}
|
|
|
|
label={t("Home")}
|
|
|
|
/>
|
|
|
|
<SidebarLink
|
|
|
|
to={{
|
2021-10-24 19:30:27 +00:00
|
|
|
pathname: searchUrl(),
|
2021-03-10 02:41:30 +00:00
|
|
|
state: { fromMenu: true },
|
|
|
|
}}
|
|
|
|
icon={<SearchIcon color="currentColor" />}
|
|
|
|
label={t("Search")}
|
|
|
|
exact={false}
|
|
|
|
/>
|
2021-04-12 02:39:17 +00:00
|
|
|
{can.createDocument && (
|
|
|
|
<SidebarLink
|
2021-10-24 19:30:27 +00:00
|
|
|
to={draftsPath()}
|
2021-04-12 02:39:17 +00:00
|
|
|
icon={<EditIcon color="currentColor" />}
|
|
|
|
label={
|
|
|
|
<Drafts align="center">
|
|
|
|
{t("Drafts")}
|
|
|
|
<Bubble count={documents.totalDrafts} />
|
|
|
|
</Drafts>
|
|
|
|
}
|
|
|
|
active={
|
|
|
|
documents.active
|
|
|
|
? !documents.active.publishedAt &&
|
|
|
|
!documents.active.isDeleted &&
|
|
|
|
!documents.active.isTemplate
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
2021-03-10 02:41:30 +00:00
|
|
|
</Section>
|
2021-08-23 07:37:28 +00:00
|
|
|
<Starred />
|
2021-03-10 02:41:30 +00:00
|
|
|
<Section auto>
|
2021-10-24 19:30:27 +00:00
|
|
|
<Collections />
|
2021-03-10 02:41:30 +00:00
|
|
|
</Section>
|
|
|
|
<Section>
|
2021-07-19 16:18:33 +00:00
|
|
|
{can.createDocument && (
|
|
|
|
<>
|
|
|
|
<SidebarLink
|
2021-10-24 19:30:27 +00:00
|
|
|
to={templatesPath()}
|
2021-07-19 16:18:33 +00:00
|
|
|
icon={<ShapesIcon color="currentColor" />}
|
|
|
|
exact={false}
|
|
|
|
label={t("Templates")}
|
|
|
|
active={
|
2021-08-06 17:31:25 +00:00
|
|
|
documents.active
|
|
|
|
? documents.active.isTemplate &&
|
|
|
|
!documents.active.isDeleted &&
|
|
|
|
!documents.active.isArchived
|
|
|
|
: undefined
|
2021-07-19 16:18:33 +00:00
|
|
|
}
|
|
|
|
/>
|
2021-07-20 19:19:41 +00:00
|
|
|
<ArchiveLink documents={documents} />
|
|
|
|
<TrashLink documents={documents} />
|
2021-07-19 16:18:33 +00:00
|
|
|
</>
|
|
|
|
)}
|
2021-03-10 02:41:30 +00:00
|
|
|
<SidebarLink
|
2021-10-24 19:30:27 +00:00
|
|
|
to={settingsPath()}
|
2021-03-10 02:41:30 +00:00
|
|
|
icon={<SettingsIcon color="currentColor" />}
|
|
|
|
exact={false}
|
|
|
|
label={t("Settings")}
|
|
|
|
/>
|
2021-10-24 19:30:27 +00:00
|
|
|
<SidebarAction action={inviteUser} />
|
2021-03-10 02:41:30 +00:00
|
|
|
</Section>
|
|
|
|
</Scrollable>
|
|
|
|
</DndProvider>
|
2021-02-19 07:35:55 +00:00
|
|
|
)}
|
2021-01-21 15:22:20 +00:00
|
|
|
</Sidebar>
|
|
|
|
);
|
2018-02-11 07:24:12 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 06:17:41 +00:00
|
|
|
const Drafts = styled(Flex)`
|
|
|
|
height: 24px;
|
|
|
|
`;
|
|
|
|
|
2021-01-21 15:22:20 +00:00
|
|
|
export default observer(MainSidebar);
|