Skip to content

Commit

Permalink
Merge pull request #8001 from owncloud/fix-text-editor-error-messages
Browse files Browse the repository at this point in the history
Fix error message display in text editor
  • Loading branch information
JammingBen authored Nov 21, 2022
2 parents 1b489b1 + 19376d5 commit 4efba55
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-text-editor-error-messages
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Display error messages in text editor

Error messages in and when leaving the text editor are now being displayed properly.

https://github.com/owncloud/web/issues/7960
https://github.com/owncloud/web/pull/8001
60 changes: 41 additions & 19 deletions packages/web-app-text-editor/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ import { useTask } from 'vue-concurrency'
import { computed, onMounted, onBeforeUnmount, ref, unref, Ref, watch } from '@vue/composition-api'
import { mapActions } from 'vuex'
import { DavPermission, DavProperty } from 'web-client/src/webdav/constants'
import { useAppDefaults } from 'web-pkg/src/composables'
import { useAppDefaults, useStore, useTranslations } from 'web-pkg/src/composables'
import AppTopBar from 'web-pkg/src/components/AppTopBar.vue'
import { defineComponent } from '@vue/composition-api'
import { Resource } from 'web-client'
import { isProjectSpaceResource } from 'web-client/src/helpers'
export default defineComponent({
name: 'TextEditor',
Expand All @@ -71,8 +72,8 @@ export default defineComponent({
this.hideModal()
next()
},
onConfirm: () => {
this.save()
onConfirm: async () => {
await this.save()
this.hideModal()
next()
}
Expand All @@ -99,6 +100,16 @@ export default defineComponent({
const currentETag = ref()
const isReadOnly = ref(true)
const resource: Ref<Resource> = ref()
const store = useStore()
const { $gettext, $gettextInterpolate } = useTranslations()
const errorPopup = (error) => {
store.dispatch('showMessage', {
title: $gettext('An error occurred'),
desc: error,
status: 'danger'
})
}
const loadFileTask = useTask(function* () {
resource.value = yield getFileInfo(currentFileContext, {
Expand Down Expand Up @@ -127,20 +138,39 @@ export default defineComponent({
} catch (e) {
switch (e.statusCode) {
case 412:
this.errorPopup(
this.$gettext(
errorPopup(
$gettext(
'This file was updated outside this window. Please refresh the page (all changes will be lost).'
)
)
break
case 500:
this.errorPopup(this.$gettext('Error when contacting the server'))
errorPopup($gettext('Error when contacting the server'))
break
case 507:
const space = store.getters['runtime/spaces/spaces'].find(
(space) => space.id === unref(resource).storageId && isProjectSpaceResource(space)
)
if (space) {
errorPopup(
// FIXME: translation
// $gettextInterpolate(
// 'There is not enough quota on "%{spaceName}" to save this file',
// { spaceName: space.name }
// )
$gettext('Error when contacting the server')
)
break
}
// FIXME: translation
// errorPopup($gettext('There is not enough quota to save this file'))
errorPopup($gettext('Error when contacting the server'))
break
case 401:
this.errorPopup(this.$gettext("You're not authorized to save this file"))
errorPopup($gettext("You're not authorized to save this file"))
break
default:
this.errorPopup(e.message || e)
errorPopup(e.message || e)
}
}
}).restartable()
Expand Down Expand Up @@ -196,8 +226,8 @@ export default defineComponent({
document.removeEventListener('keydown', handleSKey, false)
})
const save = function () {
saveFileTask.perform()
const save = async function () {
await saveFileTask.perform()
}
const handleSKey = function (e) {
Expand Down Expand Up @@ -239,15 +269,7 @@ export default defineComponent({
}
},
methods: {
...mapActions(['createModal', 'hideModal', 'showMessage']),
errorPopup(error) {
this.showMessage({
title: this.$gettext('An error occurred'),
desc: error,
status: 'danger'
})
}
...mapActions(['createModal', 'hideModal'])
}
})
</script>
Expand Down

0 comments on commit 4efba55

Please sign in to comment.