From 0627e0f5513b371e3d06d082594463eac5fcfddc Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Sun, 24 Jan 2021 21:39:47 +0100 Subject: [PATCH] Replace document bar with sidebar (#937) Signed-off-by: Tilman Vatteroth --- CHANGELOG.md | 1 + cypress/integration/export.spec.ts | 4 +- cypress/integration/import.spec.ts | 12 +-- cypress/integration/toolbar.spec.ts | 2 +- public/locales/en.json | 12 +-- .../hidden-input-menu-entry.tsx | 59 ----------- .../common/user-avatar/user-avatar.tsx | 2 +- src/components/editor/app-bar/app-bar.tsx | 2 +- .../buttons/pin-to-history-button.tsx | 18 ---- .../buttons/share-link-button.tsx | 59 ----------- .../connection-indicator.tsx | 32 ------ .../connection-indicator/user-line.scss | 11 -- .../editor/document-bar/document-bar.tsx | 43 -------- ...nfo-button.tsx => document-info-modal.tsx} | 32 +++--- .../editor/document-bar/menus/editor-menu.tsx | 40 ------- .../editor/document-bar/menus/export-menu.tsx | 71 ------------- .../document-bar/menus/export/markdown.tsx | 27 ----- .../editor/document-bar/menus/import-menu.tsx | 73 ------------- .../permissions/permission-button.tsx | 20 ---- .../permissions/permission-modal.tsx | 6 +- .../revisions/revision-button.tsx | 20 ---- .../document-bar/revisions/revision-modal.tsx | 11 +- .../editor/document-bar/share/share-modal.tsx | 53 ++++++++++ .../document-render-pane.tsx | 36 ++++--- .../editor/editor-pane/editor-pane.tsx | 4 +- .../editor/editor-pane/tool-bar/tool-bar.tsx | 23 +--- .../tool-bar/upload-image-button.tsx | 46 ++++++++ src/components/editor/editor.tsx | 65 ++++++------ .../sidebar/delete-note-sidebar-entry.tsx | 38 +++++++ .../sidebar/document-info-sidebar-entry.tsx | 25 +++++ .../sidebar/export-markdown-sidebar-entry.tsx | 28 +++++ .../sidebar/export-menu-sidebar-menu.tsx | 64 +++++++++++ .../sidebar/import-markdown-sidebar-entry.tsx | 53 ++++++++++ .../sidebar/import-menu-sidebar-menu.tsx | 50 +++++++++ .../sidebar/permissions-sidebar-entry.tsx | 25 +++++ .../editor/sidebar/pin-note-sidebar-entry.tsx | 23 ++++ .../editor/sidebar/revision-sidebar-entry.tsx | 24 +++++ .../editor/sidebar/share-sidebar-entry.tsx | 25 +++++ .../editor/sidebar/sidebar-button.tsx | 29 +++++ .../editor/sidebar/sidebar-menu.tsx | 18 ++++ src/components/editor/sidebar/sidebar.tsx | 55 ++++++++++ .../editor/sidebar/style/colors.scss | 49 +++++++++ .../editor/sidebar/style/layout.scss | 100 ++++++++++++++++++ .../editor/sidebar/style/theme.scss | 21 ++++ src/components/editor/sidebar/types.ts | 43 ++++++++ .../editor/sidebar/upload-input.tsx | 44 ++++++++ .../active-indicator.scss | 0 .../active-indicator.tsx | 0 .../online-counter.scss | 42 ++++++++ .../users-online-sidebar-menu/user-line.scss | 30 ++++++ .../users-online-sidebar-menu}/user-line.tsx | 20 ++-- .../users-online-sidebar-menu.tsx | 53 ++++++++++ .../table-of-contents/table-of-contents.scss | 24 +++-- .../hooks/use-post-toc-ast-on-change.ts | 4 +- 54 files changed, 1067 insertions(+), 604 deletions(-) delete mode 100644 src/components/common/hidden-input-menu-entry/hidden-input-menu-entry.tsx delete mode 100644 src/components/editor/document-bar/buttons/pin-to-history-button.tsx delete mode 100644 src/components/editor/document-bar/buttons/share-link-button.tsx delete mode 100644 src/components/editor/document-bar/connection-indicator/connection-indicator.tsx delete mode 100644 src/components/editor/document-bar/connection-indicator/user-line.scss delete mode 100644 src/components/editor/document-bar/document-bar.tsx rename src/components/editor/document-bar/document-info/{document-info-button.tsx => document-info-modal.tsx} (71%) delete mode 100644 src/components/editor/document-bar/menus/editor-menu.tsx delete mode 100644 src/components/editor/document-bar/menus/export-menu.tsx delete mode 100644 src/components/editor/document-bar/menus/export/markdown.tsx delete mode 100644 src/components/editor/document-bar/menus/import-menu.tsx delete mode 100644 src/components/editor/document-bar/permissions/permission-button.tsx delete mode 100644 src/components/editor/document-bar/revisions/revision-button.tsx create mode 100644 src/components/editor/document-bar/share/share-modal.tsx create mode 100644 src/components/editor/editor-pane/tool-bar/upload-image-button.tsx create mode 100644 src/components/editor/sidebar/delete-note-sidebar-entry.tsx create mode 100644 src/components/editor/sidebar/document-info-sidebar-entry.tsx create mode 100644 src/components/editor/sidebar/export-markdown-sidebar-entry.tsx create mode 100644 src/components/editor/sidebar/export-menu-sidebar-menu.tsx create mode 100644 src/components/editor/sidebar/import-markdown-sidebar-entry.tsx create mode 100644 src/components/editor/sidebar/import-menu-sidebar-menu.tsx create mode 100644 src/components/editor/sidebar/permissions-sidebar-entry.tsx create mode 100644 src/components/editor/sidebar/pin-note-sidebar-entry.tsx create mode 100644 src/components/editor/sidebar/revision-sidebar-entry.tsx create mode 100644 src/components/editor/sidebar/share-sidebar-entry.tsx create mode 100644 src/components/editor/sidebar/sidebar-button.tsx create mode 100644 src/components/editor/sidebar/sidebar-menu.tsx create mode 100644 src/components/editor/sidebar/sidebar.tsx create mode 100644 src/components/editor/sidebar/style/colors.scss create mode 100644 src/components/editor/sidebar/style/layout.scss create mode 100644 src/components/editor/sidebar/style/theme.scss create mode 100644 src/components/editor/sidebar/types.ts create mode 100644 src/components/editor/sidebar/upload-input.tsx rename src/components/editor/{document-bar/connection-indicator => sidebar/users-online-sidebar-menu}/active-indicator.scss (100%) rename src/components/editor/{document-bar/connection-indicator => sidebar/users-online-sidebar-menu}/active-indicator.tsx (100%) create mode 100644 src/components/editor/sidebar/users-online-sidebar-menu/online-counter.scss create mode 100644 src/components/editor/sidebar/users-online-sidebar-menu/user-line.scss rename src/components/editor/{document-bar/connection-indicator => sidebar/users-online-sidebar-menu}/user-line.tsx (60%) create mode 100644 src/components/editor/sidebar/users-online-sidebar-menu/users-online-sidebar-menu.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index c49f6a082..72992e671 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ SPDX-License-Identifier: CC-BY-SA-4.0 - A toggle in the editor preferences for turning ligatures on and off. - Easier possibility to share notes via native share-buttons on supported devices. - Surround selected text with a link via shortcut (ctrl+k or cmd+k). +- A sidebar for menu options - Improved security by wrapping the markdown rendering into an iframe ### Changed diff --git a/cypress/integration/export.spec.ts b/cypress/integration/export.spec.ts index b69e7ef36..6260e2708 100644 --- a/cypress/integration/export.spec.ts +++ b/cypress/integration/export.spec.ts @@ -14,9 +14,9 @@ describe('Export', () => { }) it('Markdown', () => { - cy.get('#editor-menu-export') + cy.get('[data-cy="menu-export"]') .click() - cy.get('a.dropdown-item > i.fa-file-text') + cy.get('[data-cy="menu-export-markdown"]') .click() cy.get('a[download]') .then((anchor) => ( diff --git a/cypress/integration/import.spec.ts b/cypress/integration/import.spec.ts index bac29cebd..f7d5964c5 100644 --- a/cypress/integration/import.spec.ts +++ b/cypress/integration/import.spec.ts @@ -10,11 +10,11 @@ describe('Import markdown file', () => { }) it('import on blank note', () => { - cy.get('button#editor-menu-import') + cy.get('[data-cy="menu-import"]') .click() - cy.get('.import-md-file') + cy.get('[data-cy="menu-import-markdown"]') .click() - cy.get('div[aria-labelledby="editor-menu-import"] > input[type=file]') + cy.get('[data-cy="menu-import-markdown-input"]') .attachFile({ filePath: 'import.md', mimeType: 'text/markdown' }) cy.get('.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span') .should('have.text', '# Some short import test file') @@ -25,11 +25,11 @@ describe('Import markdown file', () => { it('import on note with content', () => { cy.codemirrorFill('test\nabc') - cy.get('button#editor-menu-import') + cy.get('[data-cy="menu-import"]') .click() - cy.get('.import-md-file') + cy.get('[data-cy="menu-import-markdown"]') .click() - cy.get('div[aria-labelledby="editor-menu-import"] > input[type=file]') + cy.get('[data-cy="menu-import-markdown-input"]') .attachFile({ filePath: 'import.md', mimeType: 'text/markdown' }) cy.get('.CodeMirror-code > div:nth-of-type(1) > .CodeMirror-line > span > span') .should('have.text', 'test') diff --git a/cypress/integration/toolbar.spec.ts b/cypress/integration/toolbar.spec.ts index 1166ae71b..3ad8aaf19 100644 --- a/cypress/integration/toolbar.spec.ts +++ b/cypress/integration/toolbar.spec.ts @@ -104,7 +104,7 @@ describe('Toolbar Buttons', () => { .click() cy.get('.CodeMirror-activeline > .CodeMirror-line > span') .should('have.text', `# ${testText}`) - cy.get('.btn-toolbar [data-cy="format-heading"]') + cy.get('.fa-header') .click() cy.get('.CodeMirror-activeline > .CodeMirror-line > span') .should('have.text', `## ${testText}`) diff --git a/public/locales/en.json b/public/locales/en.json index 23c748d7a..6e490a021 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -224,6 +224,9 @@ "highlightedText": "Highlight" } }, + "onlineStatus": { + "online": "Online" + }, "error": { "locked": { "title": "This note is locked", @@ -260,6 +263,7 @@ "switchToLight": "Switch to Light Mode" }, "appBar": { + "new": "New", "syncScroll": { "disable": "Disable sync scroll", "enable": "Enable sync scroll" @@ -299,16 +303,11 @@ "menu": "Menu", "import": "Import", "export": "Export", - "new": "New", - "shareLink": "Share link", "extra": "Extra", - "revision": "Revision", "slideMode": "Slide Mode", "download": "Download", "help": "Help", "deleteNote": "Delete note", - "permissions": "Permissions", - "documentInfo": "Document info", "pinNoteToHistory": "Pin note to history", "pinnedToHistory": "Pinned to history" }, @@ -328,7 +327,8 @@ }, "export": { "rawHtml": "Raw HTML", - "pdf": "PDF export is unavailable." + "pdf": "PDF export is unavailable.", + "markdown-file": "Markdown file" }, "import": { "clipboard": "Clipboard", diff --git a/src/components/common/hidden-input-menu-entry/hidden-input-menu-entry.tsx b/src/components/common/hidden-input-menu-entry/hidden-input-menu-entry.tsx deleted file mode 100644 index 5fd65f5d9..000000000 --- a/src/components/common/hidden-input-menu-entry/hidden-input-menu-entry.tsx +++ /dev/null @@ -1,59 +0,0 @@ -/* -SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) - -SPDX-License-Identifier: AGPL-3.0-only -*/ - -import React, { Fragment, useCallback, useRef } from 'react' -import { Button, Dropdown } from 'react-bootstrap' -import { Trans, useTranslation } from 'react-i18next' -import { ForkAwesomeIcon } from '../fork-awesome/fork-awesome-icon' -import { IconName } from '../fork-awesome/types' - -export interface HiddenInputMenuEntryProps { - type: 'dropdown' | 'button' - acceptedFiles: string - i18nKey: string - icon: IconName - onLoad: (file: File) => Promise -} - -export const HiddenInputMenuEntry: React.FC = ({ type, acceptedFiles, i18nKey, icon, onLoad }) => { - const { t } = useTranslation() - - const fileInputReference = useRef(null) - const onClick = useCallback(() => { - const fileInput = fileInputReference.current - if (!fileInput) { - return - } - fileInput.addEventListener('change', () => { - if (!fileInput.files || fileInput.files.length < 1) { - return - } - const file = fileInput.files[0] - onLoad(file).then(() => { - fileInput.value = '' - }).catch((error) => { - console.error(error) - }) - }) - fileInput.click() - }, [onLoad]) - - return ( - - - { - type === 'dropdown' - ? - - - - : - } - - ) -} diff --git a/src/components/common/user-avatar/user-avatar.tsx b/src/components/common/user-avatar/user-avatar.tsx index c50325604..28a11b703 100644 --- a/src/components/common/user-avatar/user-avatar.tsx +++ b/src/components/common/user-avatar/user-avatar.tsx @@ -29,7 +29,7 @@ const UserAvatar: React.FC = ({ name, photo, size, additionalCl title={name} /> - {name} + {name} ) diff --git a/src/components/editor/app-bar/app-bar.tsx b/src/components/editor/app-bar/app-bar.tsx index 9a39f9b24..eeb0b62e8 100644 --- a/src/components/editor/app-bar/app-bar.tsx +++ b/src/components/editor/app-bar/app-bar.tsx @@ -56,7 +56,7 @@ export const AppBar: React.FC = ({ mode }) => {