Skip to content

Commit

Permalink
Merge pull request #5021 from nextcloud/bugfix/5018
Browse files Browse the repository at this point in the history
Rich workspace polishing
  • Loading branch information
juliushaertl authored Nov 23, 2023
2 parents e0ebe8e + d50cf6e commit 6e9b1fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,17 @@ export const FilesWorkspaceHeader = new Header({
},

render(el, folder, view) {
if (vm) {
// Enforce destroying of the old rendering and rerender as the FilesListHeader calls render on every folder change
vm.$destroy()
vm = null
}
const hasRichWorkspace = !!folder.attributes['rich-workspace-file'] || !!newWorkspaceCreated
const path = newWorkspaceCreated ? dirname(newWorkspaceCreated.path) : folder.path
const content = newWorkspaceCreated ? '' : folder.attributes['rich-workspace']

newWorkspaceCreated = false

import('vue').then((module) => {
el.id = 'files-workspace-wrapper'

Expand All @@ -239,6 +246,11 @@ export const FilesWorkspaceHeader = new Header({

updated(folder, view) {
newWorkspaceCreated = false

// Currently there is not much use in updating the vue instance props since render is called on every folder change
// removing the rendered element from the DOM
// This is only relevant if switching to a folder that has no content as then the render function is not called

const hasRichWorkspace = !!folder.attributes['rich-workspace-file']
vm.path = folder.path
vm.hasRichWorkspace = hasRichWorkspace
Expand Down
24 changes: 18 additions & 6 deletions src/views/RichWorkspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->

<template>
<div v-if="enabled && file !== null"
<div v-if="enabled && localHasRichWorkspace"
id="rich-workspace"
:class="{'focus': focus, 'dark': darkTheme }">
<RichTextReader v-if="!loaded || !ready" :content="content" class="rich-workspace--preview" />
Expand Down Expand Up @@ -80,6 +80,8 @@ export default {
},
data() {
return {
// Keep track of a local copy of the hasRichWorkspace state as it might change after intitial rendering (e.g. when adding/removing the readme)
localHasRichWorkspace: false,
focus: false,
folder: null,
file: null,
Expand All @@ -105,8 +107,12 @@ export default {
document.querySelector('#rich-workspace .text-editor__main').scrollTo(0, 0)
}
},
hasRichWorkspace(value) {
this.localHasRichWorkspace = value
},
},
mounted() {
this.localHasRichWorkspace = this.hasRichWorkspace
if (this.enabled && this.hasRichWorkspace) {
this.getFileInfo()
}
Expand Down Expand Up @@ -137,6 +143,7 @@ export default {
this.unlistenKeydownEvents()
},
reset() {
this.localHasRichWorkspace = false
this.file = null
this.focus = false
this.$nextTick(() => {
Expand Down Expand Up @@ -164,6 +171,7 @@ export default {
this.editing = true
this.loaded = true
this.autofocus = autofocus || false
this.localHasRichWorkspace = true
return true
})
.catch((error) => {
Expand Down Expand Up @@ -212,19 +220,20 @@ export default {
},
onFileCreated(node) {
if (SUPPORTED_STATIC_FILENAMES.includes(node.basename)) {
this.showRichWorkspace()
this.localHasRichWorkspace = true
this.getFileInfo(true)
}
},
onFileDeleted(node) {
if (node.path === this.file.path) {
this.hideRichWorkspace()
this.localHasRichWorkspace = false
}
},
onFileRenamed(node) {
if (SUPPORTED_STATIC_FILENAMES.includes(node.basename)) {
this.showRichWorkspace()
this.localHasRichWorkspace = true
} else if (node.fileid === this.file?.id && node.path !== this.file?.path) {
this.hideRichWorkspace()
this.localHasRichWorkspace = false
}
},
},
Expand All @@ -241,11 +250,14 @@ export default {
transition: max-height 0.5s cubic-bezier(0, 1, 0, 1);
z-index: 61;
position: relative;
min-height: 30vh;
}
.rich-workspace--preview {
margin-top: 44px;
&:deep(div[contenteditable='false']) {
margin: 0;
}
}
/* For subfolders, where there are no Recommendations */
Expand Down

0 comments on commit 6e9b1fd

Please sign in to comment.