Skip to content

Commit 32d8d31

Browse files
fix: add retry and show warning on description saving error
Signed-off-by: Luka Trovic <luka@nextcloud.com>
1 parent 5c21cd2 commit 32d8d31

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

src/components/card/CardSidebar.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ import HomeIcon from 'vue-material-design-icons/Home.vue'
8787
import CommentIcon from 'vue-material-design-icons/Comment.vue'
8888
import ActivityIcon from 'vue-material-design-icons/LightningBolt.vue'
8989
90-
import { showError } from '@nextcloud/dialogs'
90+
import { showError, showWarning } from '@nextcloud/dialogs'
9191
import { getLocale } from '@nextcloud/l10n'
9292
import CardMenuEntries from '../cards/CardMenuEntries.vue'
9393
@@ -139,6 +139,7 @@ export default {
139139
...mapState({
140140
isFullApp: (state) => state.isFullApp,
141141
currentBoard: (state) => state.currentBoard,
142+
hasCardSaveError: (state) => state.hasCardSaveError,
142143
}),
143144
...mapGetters(['canEdit', 'assignables', 'cardActions', 'stackById']),
144145
currentCard() {
@@ -198,6 +199,10 @@ export default {
198199
},
199200
200201
closeSidebar() {
202+
if (this.hasCardSaveError) {
203+
showWarning(t('deck', 'Cannot close unsaved card!'))
204+
return
205+
}
201206
this.$router?.push({ name: 'board' })
202207
this.$emit('close')
203208
},

src/components/card/Description.vue

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ import AttachmentList from './AttachmentList.vue'
7373
import { NcActions, NcActionButton, NcModal } from '@nextcloud/vue'
7474
import { formatFileSize } from '@nextcloud/files'
7575
import { generateUrl } from '@nextcloud/router'
76+
import { showWarning } from '@nextcloud/dialogs'
7677
import PaperclipIcon from 'vue-material-design-icons/Paperclip.vue'
78+
import { mapState } from 'vuex'
7779
7880
const markdownIt = new MarkdownIt({
7981
linkify: true,
@@ -135,6 +137,9 @@ export default {
135137
}
136138
},
137139
computed: {
140+
...mapState({
141+
hasCardSaveError: (state) => state.hasCardSaveError,
142+
}),
138143
mimetypeForAttachment() {
139144
return (mimetype) => {
140145
const url = OC.MimeType.getIconUrl(mimetype)
@@ -285,15 +290,31 @@ export default {
285290
return
286291
}
287292
this.descriptionSaving = true
288-
if (this.card.id !== undefined) {
289-
await this.$store.dispatch('updateCardDesc', { ...this.card, description: this.description })
293+
try {
294+
if (this.card.id !== undefined) {
295+
await this.$store.dispatch('updateCardDesc', { ...this.card, description: this.description })
296+
}
297+
this.$emit('change', this.description)
298+
this.descriptionLastEdit = 0
299+
this.$store.commit('setHasCardSaveError', false)
300+
} catch (e) {
301+
this.$store.commit('setHasCardSaveError', true)
302+
showWarning(t('deck', 'Could not save description'), { timeout: 2500 })
303+
console.error(e)
304+
305+
// Retry of network error
306+
if (['ERR_NETWORK', 'ETIMEDOUT'].includes(e.code)) {
307+
this.setSaveTimeout()
308+
}
309+
} finally {
310+
this.descriptionSaving = false
290311
}
291-
this.$emit('change', this.description)
292-
this.descriptionLastEdit = 0
293-
this.descriptionSaving = false
294312
},
295313
updateDescription() {
296314
this.descriptionLastEdit = Date.now()
315+
this.setSaveTimeout()
316+
},
317+
setSaveTimeout() {
297318
clearTimeout(this.descriptionSaveTimeout)
298319
this.descriptionSaveTimeout = setTimeout(async () => {
299320
await this.saveDescription()

src/store/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default new Vuex.Store({
5050
sidebarShown: false,
5151
currentBoard: null,
5252
currentCard: null,
53+
hasCardSaveError: false,
5354
boards: loadState('deck', 'initialBoards', []),
5455
sharees: [],
5556
assignableUsers: [],
@@ -131,6 +132,9 @@ export default new Vuex.Store({
131132
setFullApp(state, isFullApp) {
132133
Vue.set(state, 'isFullApp', isFullApp)
133134
},
135+
setHasCardSaveError(state, hasCardSaveError) {
136+
Vue.set(state, 'hasCardSaveError', hasCardSaveError)
137+
},
134138
SET_CONFIG(state, { key, value }) {
135139
const [scope, id, configKey] = key.split(':', 3)
136140
let indexExisting = -1

0 commit comments

Comments
 (0)