From fa6a94a3eb3a71a3a34db5fb9a658b0874a08918 Mon Sep 17 00:00:00 2001 From: Luka Trovic Date: Thu, 15 Dec 2022 15:29:48 +0100 Subject: [PATCH] fix: comments Signed-off-by: Luka Trovic --- cypress/e2e/workspace.spec.js | 1 - cypress/support/commands.js | 3 +-- src/helpers/files.js | 25 +++++++++++++------------ src/views/RichWorkspace.vue | 8 +------- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/cypress/e2e/workspace.spec.js b/cypress/e2e/workspace.spec.js index 56c9da787c9..eb9d08ab531 100644 --- a/cypress/e2e/workspace.spec.js +++ b/cypress/e2e/workspace.spec.js @@ -72,7 +72,6 @@ describe('Workspace', function() { cy.get('.files-controls').within(() => { cy.get('.button.new').click() cy.get('.newFileMenu a.menuitem[data-action="rich-workspace-init"]').click() - cy.get('.newFileMenu a.menuitem input.icon-confirm[type="submit"]').click() cy.wait('@addDescription') }) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 099e72618bc..66824e57ee7 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -311,7 +311,7 @@ Cypress.Commands.add('getActionEntry', { prevSubject: 'optional' }, (subject, na }) Cypress.Commands.add('getActionSubEntry', (name) => { - return cy.get('div[popoverbaseclass=action-item__popper]').getActionEntry(name) + return cy.get('div[data-text-el="menubar"]').getActionEntry(name) }) Cypress.Commands.add('getContent', { prevSubject: 'optional' }, (subject) => { @@ -378,7 +378,6 @@ Cypress.Commands.add('createDescription', () => { cy.get('.files-controls').within(() => { cy.get('.button.new').click() cy.get('.newFileMenu a.menuitem[data-action="rich-workspace-init"]').click() - cy.get('.newFileMenu a.menuitem input.icon-confirm[type="submit"]').click() }) cy.wait('@addDescription') }) diff --git a/src/helpers/files.js b/src/helpers/files.js index f569b319fb2..f8b3304aea7 100644 --- a/src/helpers/files.js +++ b/src/helpers/files.js @@ -21,7 +21,7 @@ */ import { loadState } from '@nextcloud/initial-state' -import { subscribe } from '@nextcloud/event-bus' +import { emit, subscribe } from '@nextcloud/event-bus' import { openMimetypes } from './mime.js' import { getSharingToken } from './token.js' import RichWorkspace from '../views/RichWorkspace.vue' @@ -142,6 +142,7 @@ const registerFileActionFallback = () => { const newRichWorkspaceFileMenuPlugin = { attach(menu) { const fileList = menu.fileList + const descriptionFile = t('text', 'Readme') + '.' + loadState('text', 'default_file_extension') // only attach to main file list, public view is not supported yet if (fileList.id !== 'files' && fileList.id !== 'files.public') { return @@ -151,18 +152,15 @@ const newRichWorkspaceFileMenuPlugin = { menu.addMenuEntry({ id: 'rich-workspace-init', displayName: t('text', 'Add description'), - templateName: t('text', 'Readme') + '.' + loadState('text', 'default_file_extension'), - iconClass: 'icon-filetype-text', + templateName: descriptionFile, + iconClass: 'icon-rename', fileType: 'file', + useInput: descriptionFile, actionHandler() { return window.FileList - .createFile('Readme.md', { scrollTo: false, animate: false }) - .then(() => { - menu.removeMenuEntry('rich-workspace-init') - }) + .createFile(descriptionFile, { scrollTo: false, animate: false }) }, shouldShow() { - const descriptionFile = 'Readme.md' if (fileList.findFile(descriptionFile)) return false return true }, @@ -197,7 +195,7 @@ const FilesWorkspacePlugin = { addMenuRichWorkspace() import('vue').then((module) => { const Vue = module.default - const descriptionFile = 'Readme.md' + const descriptionFile = t('text', 'Readme') + '.' + loadState('text', 'default_file_extension') this.el.id = 'files-workspace-wrapper' Vue.prototype.t = window.t Vue.prototype.n = window.n @@ -205,8 +203,7 @@ const FilesWorkspacePlugin = { const View = Vue.extend(RichWorkspace) const vm = new View({ propsData: { - path: fileList.getCurrentDirectory(), - hasDescriptionFile: !!fileList.findFile(descriptionFile) + path: fileList.getCurrentDirectory() }, store, }).$mount(this.el) @@ -222,7 +219,11 @@ const FilesWorkspacePlugin = { vm.path = data.dir.toString() }) fileList.$table.on('DOMSubtreeModified', () => { - vm.hasDescriptionFile = !!fileList.findFile(descriptionFile) + if (fileList.findFile(descriptionFile)) { + emit('Text::showRichWorkspace') + } else { + emit('Text::hideRichWorkspace') + } }) }) }, diff --git a/src/views/RichWorkspace.vue b/src/views/RichWorkspace.vue index 5e8908749b2..d2b8d8adfc8 100644 --- a/src/views/RichWorkspace.vue +++ b/src/views/RichWorkspace.vue @@ -58,10 +58,6 @@ export default { type: String, required: true, }, - hasDescriptionFile: { - type: Boolean, - required: false, - }, active: { type: Boolean, default: true, @@ -96,9 +92,6 @@ export default { if (!newValue) { document.querySelector('#rich-workspace .text-editor__main').scrollTo(0, 0) } - }, - hasDescriptionFile() { - this.getFileInfo() } }, mounted() { @@ -148,6 +141,7 @@ export default { this.file = data.file this.editing = true this.loaded = true + this.autofocus = true return true }) .catch((error) => {