Skip to content

Commit 0ce8e13

Browse files
skjnldsvbackportbot[bot]
authored andcommitted
fix(files): workspace implementation
Signed-off-by: skjnldsv <[email protected]> [skip ci]
1 parent 0c52449 commit 0ce8e13

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

src/helpers/files.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { dirname } from 'path'
76
import { emit } from '@nextcloud/event-bus'
87
import { getCurrentUser } from '@nextcloud/auth'
98
import { getSharingToken } from '@nextcloud/sharing/public'
@@ -111,8 +110,6 @@ const registerFileActionFallback = () => {
111110

112111
}
113112

114-
let newWorkspaceCreated = false
115-
116113
export const addMenuRichWorkspace = () => {
117114
const descriptionFile = t('text', 'Readme') + '.' + loadState('text', 'default_file_extension')
118115
addNewFileMenuEntry({
@@ -155,17 +152,17 @@ export const addMenuRichWorkspace = () => {
155152

156153
showSuccess(t('text', 'Created "{name}"', { name: descriptionFile }))
157154

158-
if (contentNames.length === 0) {
159-
// We currently have no way to reliably trigger the filelist header rendering
160-
// When starting off in a new empty folder the header will only be rendered on a new PROPFIND
161-
newWorkspaceCreated = file
162-
}
155+
context.attributes['rich-workspace-file'] = fileid
156+
context.attributes['rich-workspace'] = ''
157+
163158
emit('files:node:created', file)
159+
emit('files:node:updated', context)
164160
},
165161
})
166162
}
167163

168-
let vm = null
164+
let FilesHeaderRichWorkspaceView
165+
let FilesHeaderRichWorkspaceInstance
169166

170167
export const FilesWorkspaceHeader = new Header({
171168
id: 'workspace',
@@ -174,23 +171,34 @@ export const FilesWorkspaceHeader = new Header({
174171
enabled(_, view) {
175172
return ['files', 'favorites', 'public-share'].includes(view.id)
176173
},
177-
178-
async render(el, folder, view) {
179-
if (vm) {
180-
// Enforce destroying of the old rendering and rerender as the FilesListHeader calls render on every folder change
181-
vm.$destroy()
182-
vm = null
174+
render: async (el, folder) => {
175+
// Import the RichWorkspace component only when needed
176+
if (!FilesHeaderRichWorkspaceView) {
177+
FilesHeaderRichWorkspaceView = (
178+
await import('../views/RichWorkspace.vue')
179+
).default
183180
}
184181
const hasRichWorkspace = !!folder.attributes['rich-workspace-file'] || !!newWorkspaceCreated
185182
const path = newWorkspaceCreated ? dirname(newWorkspaceCreated.path) : folder.path
186183
const content = newWorkspaceCreated ? '' : folder.attributes['rich-workspace']
187184

188-
newWorkspaceCreated = false
185+
// If an instance already exists, destroy it before creating a new one
186+
if (FilesHeaderRichWorkspaceInstance) {
187+
FilesHeaderRichWorkspaceInstance.$destroy()
188+
console.debug('Destroying existing FilesHeaderRichWorkspaceInstance')
189+
}
189190

190191
const { default: RichWorkspace } = await import('./../views/RichWorkspace.vue')
191192

192-
import('vue').then((module) => {
193-
el.id = 'files-workspace-wrapper'
193+
// Create a new instance of the RichWorkspace component
194+
FilesHeaderRichWorkspaceInstance = new Vue({
195+
extends: FilesHeaderRichWorkspaceView,
196+
propsData: {
197+
content,
198+
hasRichWorkspace,
199+
path,
200+
},
201+
}).$mount(el)
194202

195203
// Todo: remove this hack
196204
const Vue = module.default
@@ -210,22 +218,17 @@ export const FilesWorkspaceHeader = new Header({
210218
})
211219
},
212220

213-
updated(folder, view) {
214-
newWorkspaceCreated = false
215-
216-
if (!vm) {
217-
console.warn('No vue instance found for FilesWorkspaceHeader')
221+
updated(folder) {
222+
if (!FilesHeaderRichWorkspaceInstance) {
223+
console.error('No vue instance found for FilesWorkspaceHeader')
218224
return
219225
}
220226

221-
// Currently there is not much use in updating the vue instance props since render is called on every folder change
222-
// removing the rendered element from the DOM
223-
// This is only relevant if switching to a folder that has no content as then the render function is not called
224-
225227
const hasRichWorkspace = !!folder.attributes['rich-workspace-file']
226-
vm.path = folder.path
227-
vm.hasRichWorkspace = hasRichWorkspace
228-
vm.content = folder.attributes['rich-workspace']
228+
FilesHeaderRichWorkspaceInstance.hasRichWorkspace = hasRichWorkspace
229+
FilesHeaderRichWorkspaceInstance.content =
230+
folder.attributes['rich-workspace'] || ''
231+
FilesHeaderRichWorkspaceInstance.path = folder.path || ''
229232
},
230233
})
231234

src/views/RichWorkspace.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
</template>
2727

2828
<script>
29-
import axios from '@nextcloud/axios'
3029
import { generateOcsUrl } from '@nextcloud/router'
31-
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
3230
import { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'
31+
import { loadState } from '@nextcloud/initial-state'
32+
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
33+
import axios from '@nextcloud/axios'
34+
3335
import getEditorInstance from '../components/Editor.singleton.js'
3436
import RichTextReader from '../components/RichTextReader.vue'
35-
import { loadState } from '@nextcloud/initial-state'
3637
3738
const IS_PUBLIC = isPublicShare()
3839
const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2)
@@ -74,8 +75,8 @@ export default {
7475
ready: false,
7576
autofocus: false,
7677
hideMenu: true,
77-
darkTheme: OCA.Accessibility && OCA.Accessibility.theme === 'dark',
78-
enabled: OCA.Text.RichWorkspaceEnabled,
78+
darkTheme: window?.OCA?.Accessibility?.theme === 'dark',
79+
enabled: window?.OCA?.Text?.RichWorkspaceEnabled,
7980
}
8081
},
8182
computed: {

0 commit comments

Comments
 (0)