Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 40 additions & 51 deletions src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { dirname } from 'path'
import { emit } from '@nextcloud/event-bus'
import { getCurrentUser } from '@nextcloud/auth'
import { getSharingToken } from '@nextcloud/sharing/public'
Expand All @@ -17,6 +16,7 @@ import TextSvg from '@mdi/svg/svg/text.svg?raw'

import { openMimetypes } from './mime.js'
import store from '../store/index.js'
import Vue from 'vue'

const FILE_ACTION_IDENTIFIER = 'Edit with text app'

Expand Down Expand Up @@ -111,8 +111,6 @@ const registerFileActionFallback = () => {

}

let newWorkspaceCreated = false

export const addMenuRichWorkspace = () => {
const descriptionFile = t('text', 'Readme') + '.' + loadState('text', 'default_file_extension')
addNewFileMenuEntry({
Expand Down Expand Up @@ -155,17 +153,17 @@ export const addMenuRichWorkspace = () => {

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

if (contentNames.length === 0) {
// We currently have no way to reliably trigger the filelist header rendering
// When starting off in a new empty folder the header will only be rendered on a new PROPFIND
newWorkspaceCreated = file
}
context.attributes['rich-workspace-file'] = fileid
context.attributes['rich-workspace'] = ''

emit('files:node:created', file)
emit('files:node:updated', context)
},
})
}

let vm = null
let FilesHeaderRichWorkspaceView
let FilesHeaderRichWorkspaceInstance

export const FilesWorkspaceHeader = new Header({
id: 'workspace',
Expand All @@ -174,58 +172,49 @@ export const FilesWorkspaceHeader = new Header({
enabled(_, view) {
return ['files', 'favorites', 'public-share'].includes(view.id)
},

async 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
render: async (el, folder) => {
// Import the RichWorkspace component only when needed
if (!FilesHeaderRichWorkspaceView) {
FilesHeaderRichWorkspaceView = (
await import('../views/RichWorkspace.vue')
).default
}
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

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

import('vue').then((module) => {
el.id = 'files-workspace-wrapper'
// If an instance already exists, destroy it before creating a new one
if (FilesHeaderRichWorkspaceInstance) {
FilesHeaderRichWorkspaceInstance.$destroy()
console.debug('Destroying existing FilesHeaderRichWorkspaceInstance')
}

// Todo: remove this hack
const Vue = module.default
Vue.prototype.t = window.t
Vue.prototype.n = window.n
Vue.prototype.OCA = window.OCA
const hasRichWorkspace = !!folder.attributes['rich-workspace-file']
const content = folder.attributes['rich-workspace'] || ''
const path = folder.path || ''

// Create a new instance of the RichWorkspace component
FilesHeaderRichWorkspaceInstance = new Vue({
extends: FilesHeaderRichWorkspaceView,
propsData: {
content,
hasRichWorkspace,
path,
},
store,
}).$mount(el)

const View = Vue.extend(RichWorkspace)
vm = new View({
propsData: {
path,
hasRichWorkspace,
content,
},
store,
}).$mount(el)
})
window.FilesHeaderRichWorkspaceInstance = FilesHeaderRichWorkspaceInstance
},

updated(folder, view) {
newWorkspaceCreated = false

if (!vm) {
console.warn('No vue instance found for FilesWorkspaceHeader')
updated(folder) {
if (!FilesHeaderRichWorkspaceInstance) {
console.error('No vue instance found for FilesWorkspaceHeader')
return
}

// 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
vm.content = folder.attributes['rich-workspace']
FilesHeaderRichWorkspaceInstance.hasRichWorkspace = hasRichWorkspace
FilesHeaderRichWorkspaceInstance.content
= folder.attributes['rich-workspace'] || ''
FilesHeaderRichWorkspaceInstance.path = folder.path || ''
},
})

Expand Down
11 changes: 6 additions & 5 deletions src/views/RichWorkspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
</template>

<script>
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'
import { loadState } from '@nextcloud/initial-state'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import axios from '@nextcloud/axios'

import getEditorInstance from '../components/Editor.singleton.js'
import RichTextReader from '../components/RichTextReader.vue'
import { loadState } from '@nextcloud/initial-state'

const IS_PUBLIC = isPublicShare()
const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2)
Expand Down Expand Up @@ -74,8 +75,8 @@
ready: false,
autofocus: false,
hideMenu: true,
darkTheme: OCA.Accessibility && OCA.Accessibility.theme === 'dark',
enabled: OCA.Text.RichWorkspaceEnabled,
darkTheme: window?.OCA?.Accessibility?.theme === 'dark',
enabled: window?.OCA?.Text?.RichWorkspaceEnabled,

Check warning on line 79 in src/views/RichWorkspace.vue

View check run for this annotation

Codecov / codecov/patch

src/views/RichWorkspace.vue#L78-L79

Added lines #L78 - L79 were not covered by tests
}
},
computed: {
Expand Down
Loading