feat: Add '+' button to create new doc in sidebar (#2864)

This commit is contained in:
Tom Moor
2021-12-18 11:14:17 -08:00
committed by GitHub
parent 80b2ba886a
commit 791be77867
2 changed files with 22 additions and 2 deletions

View File

@@ -1,17 +1,21 @@
import { observer } from "mobx-react";
import { PlusIcon } from "outline-icons";
import * as React from "react";
import { useDrag, useDrop } from "react-dnd";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
import styled from "styled-components";
import { MAX_TITLE_LENGTH } from "@shared/constants";
import { sortNavigationNodes } from "@shared/utils/collections";
import Collection from "~/models/Collection";
import Document from "~/models/Document";
import Fade from "~/components/Fade";
import NudeButton from "~/components/NudeButton";
import useBoolean from "~/hooks/useBoolean";
import useStores from "~/hooks/useStores";
import DocumentMenu from "~/menus/DocumentMenu";
import { NavigationNode } from "~/types";
import { newDocumentPath } from "~/utils/routeHelpers";
import Disclosure from "./Disclosure";
import DropCursor from "./DropCursor";
import DropToImport from "./DropToImport";
@@ -255,6 +259,8 @@ function DocumentLink(
(activeDocument?.id === node.id ? activeDocument.title : node.title) ||
t("Untitled");
const can = policies.abilities(node.id);
return (
<>
<Relative onDragLeave={resetHoverExpanding}>
@@ -302,8 +308,22 @@ function DocumentLink(
isDraft={isDraft}
ref={ref}
menu={
document && !isMoving && !isEditing ? (
document &&
!isMoving &&
!isEditing &&
!isDraggingAnyDocument ? (
<Fade>
{can.createChildDocument && (
<NudeButton
aria-label={t("New nested document")}
as={Link}
to={newDocumentPath(document.collectionId, {
parentDocumentId: document.id,
})}
>
<PlusIcon />
</NudeButton>
)}
<DocumentMenu
document={document}
onOpen={handleMenuOpen}

View File

@@ -127,6 +127,7 @@
"Collections could not be loaded, please reload the app": "Collections could not be loaded, please reload the app",
"Collections": "Collections",
"Untitled": "Untitled",
"New nested document": "New nested document",
"Document not supported try Markdown, Plain text, HTML, or Word": "Document not supported try Markdown, Plain text, HTML, or Word",
"Starred documents could not be loaded": "Starred documents could not be loaded",
"Starred": "Starred",
@@ -235,7 +236,6 @@
"Choose a collection": "Choose a collection",
"Unpin": "Unpin",
"Pin to collection": "Pin to collection",
"New nested document": "New nested document",
"Unpublish": "Unpublish",
"Permanently delete": "Permanently delete",
"Move": "Move",