Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax <max@nextcloud.com>2022-03-07 11:13:59 +0300
committerJulius Härtl <jus@bitgrid.net>2022-03-09 00:54:05 +0300
commit44737f20095f30ef2440f8667a21e21decf9d648 (patch)
tree188b81cf04b0627bf50666bd4a4e9727c341ac67 /src
parentf04d31da3d0ea8b909998f3846f88b96a24fd31c (diff)
refactor: prepare loading content in session creation
Simplify the session creation code a bit: * handle the two ways of initializing a sesson only in SyncService. * use async instead of .then(...) * handle errors in helper function. Signed-off-by: Max <max@nextcloud.com>
Diffstat (limited to 'src')
-rw-r--r--src/components/EditorWrapper.vue21
-rw-r--r--src/services/SyncService.js39
2 files changed, 22 insertions, 38 deletions
diff --git a/src/components/EditorWrapper.vue b/src/components/EditorWrapper.vue
index 65cba4a61..e72f769d8 100644
--- a/src/components/EditorWrapper.vue
+++ b/src/components/EditorWrapper.vue
@@ -463,20 +463,13 @@ export default {
this.readOnly = true
this.tiptap.setOptions({ editable: !this.readOnly })
})
- if (this.initialSession === null) {
- this.syncService.open({
- fileId: this.fileId,
- filePath: this.relativePath,
- }).catch((e) => {
- this.hasConnectionIssue = true
- })
- } else {
- this.syncService.open({
- initialSession: this.initialSession,
- }).catch((e) => {
- this.hasConnectionIssue = true
- })
- }
+ this.syncService.open({
+ fileId: this.fileId,
+ filePath: this.relativePath,
+ initialSession: this.initialSession,
+ }).catch((e) => {
+ this.hasConnectionIssue = true
+ })
this.forceRecreate = false
},
diff --git a/src/services/SyncService.js b/src/services/SyncService.js
index 651a5ee2b..34d10b15e 100644
--- a/src/services/SyncService.js
+++ b/src/services/SyncService.js
@@ -97,37 +97,20 @@ class SyncService {
}
async open({ fileId, filePath, initialSession }) {
- let connectionData = null
- if (typeof initialSession === 'undefined') {
- try {
- const response = await this._openDocument({ fileId, filePath })
- connectionData = response.data
- } catch (error) {
- if (!error.response || error.code === 'ECONNABORTED') {
- this.emit('error', ERROR_TYPE.CONNECTION_FAILED, {})
- } else {
- this.emit('error', ERROR_TYPE.LOAD_ERROR, error.response.status)
- }
- throw error
- }
- } else {
- connectionData = initialSession
- }
-
+ const connectionData = initialSession
+ || await this._openDocument({ fileId, filePath })
this.document = connectionData.document
this.document.readOnly = connectionData.readOnly
this.session = connectionData.session
-
this.emit('opened', {
document: this.document,
session: this.session,
})
- return this._fetchDocument().then(({ data }) => {
- this.emit('loaded', {
- document: this.document,
- session: this.session,
- documentSource: '' + data,
- })
+ const fetched = await this._fetchDocument()
+ this.emit('loaded', {
+ document: this.document,
+ session: this.session,
+ documentSource: '' + fetched.data,
})
}
@@ -143,6 +126,14 @@ class SyncService {
guestName: this.options.guestName,
forceRecreate: this.options.forceRecreate,
})
+ .then(response => response.data, error => {
+ if (!error.response || error.code === 'ECONNABORTED') {
+ this.emit('error', ERROR_TYPE.CONNECTION_FAILED, {})
+ } else {
+ this.emit('error', ERROR_TYPE.LOAD_ERROR, error.response.status)
+ }
+ throw error
+ })
}
_fetchDocument() {