Skip to content

Commit 1852e11

Browse files
committed
fix: Avoid layout jump with rich workspace
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent a41a212 commit 1852e11

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

src/files.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
import { linkTo } from '@nextcloud/router'
2323
import { loadState } from '@nextcloud/initial-state'
24-
import { registerFileListHeaders } from '@nextcloud/files'
24+
import { registerFileListHeaders, registerDavProperty } from '@nextcloud/files'
2525
import Vue from 'vue'
2626

2727
import { logger } from './helpers/logger.js'
@@ -35,6 +35,9 @@ __webpack_public_path__ = linkTo('text', 'js/') // eslint-disable-line
3535
const workspaceAvailable = loadState('text', 'workspace_available')
3636
const workspaceEnabled = loadState('text', 'workspace_enabled')
3737

38+
registerDavProperty('nc:rich-workspace', { nc: 'http://nextcloud.org/ns' })
39+
registerDavProperty('nc:rich-workspace-file', { nc: 'http://nextcloud.org/ns' })
40+
3841
document.addEventListener('DOMContentLoaded', () => {
3942
if (typeof OCA.Viewer === 'undefined') {
4043
logger.error('Viewer app is not installed')

src/helpers/files.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export const FilesWorkspaceHeader = new Header({
187187

188188
render(el, folder, view) {
189189
addMenuRichWorkspace()
190+
const hasRichWorkspace = !!folder.attributes['rich-workspace-file']
190191

191192
import('vue').then((module) => {
192193
el.id = 'files-workspace-wrapper'
@@ -201,14 +202,19 @@ export const FilesWorkspaceHeader = new Header({
201202
vm = new View({
202203
propsData: {
203204
path: folder.path,
205+
hasRichWorkspace,
206+
content: folder.attributes['rich-workspace'],
204207
},
205208
store,
206209
}).$mount(el)
207210
})
208211
},
209212

210213
updated(folder, view) {
214+
const hasRichWorkspace = !!folder.attributes['rich-workspace-file']
211215
vm.path = folder.path
216+
vm.hasRichWorkspace = hasRichWorkspace
217+
vm.content = folder.attributes['rich-workspace']
212218
},
213219
})
214220

src/views/RichWorkspace.vue

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
<template>
2424
<div v-if="enabled"
25-
v-show="file"
25+
v-show="hasRichWorkspace"
2626
id="rich-workspace"
27-
:class="{'focus': focus, 'dark': darkTheme, 'creatable': canCreate }">
28-
<SkeletonLoading v-if="!loaded || !ready" />
27+
:class="{'focus': focus, 'dark': darkTheme }">
28+
<RichTextReader v-if="!loaded || !ready" :content="content" class="rich-workspace--preview" />
2929
<Editor v-if="file"
3030
v-show="ready"
3131
:key="file.path"
@@ -48,19 +48,23 @@
4848
import axios from '@nextcloud/axios'
4949
import { generateOcsUrl } from '@nextcloud/router'
5050
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
51-
import SkeletonLoading from '../components/SkeletonLoading.vue'
5251
import getEditorInstance from '../components/Editor.singleton.js'
52+
import RichTextReader from '../components/RichTextReader.vue'
5353
5454
const IS_PUBLIC = !!(document.getElementById('isPublic'))
5555
const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2)
5656
5757
export default {
5858
name: 'RichWorkspace',
5959
components: {
60-
SkeletonLoading,
60+
RichTextReader,
6161
Editor: getEditorInstance,
6262
},
6363
props: {
64+
content: {
65+
type: String,
66+
default: '',
67+
},
6468
path: {
6569
type: String,
6670
required: true,
@@ -69,6 +73,10 @@ export default {
6973
type: Boolean,
7074
default: true,
7175
},
76+
hasRichWorkspace: {
77+
type: Boolean,
78+
default: false,
79+
},
7280
},
7381
data() {
7482
return {
@@ -87,9 +95,6 @@ export default {
8795
shareToken() {
8896
return document.getElementById('sharingToken')?.value
8997
},
90-
canCreate() {
91-
return !!(this.folder && (this.folder.permissions & OC.PERMISSION_CREATE))
92-
},
9398
},
9499
watch: {
95100
path() {
@@ -134,9 +139,12 @@ export default {
134139
})
135140
},
136141
getFileInfo(autofocus) {
137-
this.loaded = false
138-
this.autofocus = false
142+
if (!this.hasRichWorkspace) {
143+
return
144+
}
139145
this.ready = false
146+
this.loaded = true
147+
this.autofocus = false
140148
const params = { path: this.path }
141149
if (IS_PUBLIC) {
142150
params.shareToken = this.shareToken
@@ -209,9 +217,11 @@ export default {
209217
transition: max-height 0.5s cubic-bezier(0, 1, 0, 1);
210218
z-index: 61;
211219
position: relative;
212-
&.creatable {
213-
min-height: 100px;
214-
}
220+
min-height: 30vh;
221+
}
222+
223+
.rich-workspace--preview {
224+
margin-top: 44px;
215225
}
216226
217227
/* For subfolders, where there are no Recommendations */

0 commit comments

Comments
 (0)