Skip to content

Commit

Permalink
refactor: extract logic into computed
Browse files Browse the repository at this point in the history
Also rename `initialLoading` in `EditorWrapper` to `contentLoaded`.
This flag is set during the `initialLoading` state change.
It does indicates that the loading happened
Use the past tense to indicate that.

The editor wrapper is now loading in different steps.
The menus will load after the content.
So `content` seems more fitting then `initial`.
  • Loading branch information
max-nextcloud committed Mar 8, 2022
1 parent a875a72 commit 337c2da
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 30 deletions.
4 changes: 2 additions & 2 deletions js/editor-rich.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor-rich.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/files-modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/files-modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions src/components/EditorWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
{{ t('text', 'File could not be loaded. Please check your internet connection.') }} <a class="button primary" @click="reconnect">{{ t('text', 'Reconnect') }}</a>
</p>
</div>
<div v-if="displayed" id="editor-wrapper" :class="{'has-conflicts': hasSyncCollission, 'icon-loading': !initialLoading && !hasConnectionIssue, 'richEditor': isRichEditor, 'show-color-annotations': showAuthorAnnotations}">
<div v-if="displayed" id="editor-wrapper" :class="{'has-conflicts': hasSyncCollission, 'icon-loading': !contentLoaded && !hasConnectionIssue, 'richEditor': isRichEditor, 'show-color-annotations': showAuthorAnnotations}">
<div v-if="tiptap" id="editor">
<MenuBar v-if="initialLoading && !syncError && !readOnly"
<MenuBar v-if="renderMenus"
ref="menubar"
:editor="tiptap"
:sync-service="syncService"
Expand All @@ -58,11 +58,11 @@
</MenuBar>
<div v-if="!menubarLoaded" class="menubar placeholder" />
<div ref="contentWrapper" class="content-wrapper">
<MenuBubble v-if="initialLoading && !readOnly && isRichEditor"
<MenuBubble v-if="renderMenus"
:editor="tiptap"
:content-wrapper="contentWrapper"
:file-path="relativePath" />
<EditorContent v-show="initialLoading"
<EditorContent v-show="contentLoaded"
class="editor__content"
:editor="tiptap" />
</div>
Expand Down Expand Up @@ -172,7 +172,7 @@ export default {
idle: false,
dirty: false,
initialLoading: false,
contentLoaded: false,
lastSavedString: '',
syncError: null,
hasConnectionIssue: false,
Expand Down Expand Up @@ -245,6 +245,12 @@ export default {
displayed() {
return this.currentSession && this.active
},
renderMenus() {
return this.contentLoaded
&& this.isRichEditor
&& !this.syncError
&& !this.readOnly
},
},
watch: {
lastSavedStatus() {
Expand Down Expand Up @@ -419,7 +425,7 @@ export default {
.on('error', (error, data) => {
this.tiptap.setOptions({ editable: false })
if (error === ERROR_TYPE.SAVE_COLLISSION && (!this.syncError || this.syncError.type !== ERROR_TYPE.SAVE_COLLISSION)) {
this.initialLoading = true
this.contentLoaded = true
this.syncError = {
type: error,
data,
Expand All @@ -439,8 +445,8 @@ export default {
this.$emit('ready')
})
.on('stateChange', (state) => {
if (state.initialLoading && !this.initialLoading) {
this.initialLoading = true
if (state.initialLoading && !this.contentLoaded) {
this.contentLoaded = true
if (this.autofocus && !this.readOnly) {
this.tiptap.commands.focus()
}
Expand Down Expand Up @@ -485,7 +491,7 @@ export default {
},
reconnect() {
this.initialLoading = false
this.contentLoaded = false
this.hasConnectionIssue = false
if (this.syncService) {
this.syncService.close().then(() => {
Expand Down

0 comments on commit 337c2da

Please sign in to comment.