From 4b692edd7d6da22afd3c4ece196f4bb200d050af Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 4 Mar 2022 15:09:50 +0100 Subject: [PATCH] accompanying course comment: autosave the comment --- .../AccompanyingCourse/components/Comment.vue | 53 ++++++++++--------- .../vuejs/AccompanyingCourse/js/i18n.js | 2 +- .../vuejs/AccompanyingCourse/store/index.js | 2 - 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue index fde1319d7..ffb848bcb 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue @@ -24,7 +24,7 @@
{{ $t('comment.created_by', [ pinnedComment.creator.text, - $d(pinnedComment.createdAt.datetime, 'long') + $d(pinnedComment.updatedAt.datetime, 'long') ]) }}
@@ -82,29 +82,34 @@ export default { }, methods: { onContentChange() { - console.log('content changed'); - console.log(this.pinnedComment) - if (this.pinnedComment) { - let body = this.formData; - Object.assign(body, {id: this.pinnedComment.id}) - this.$store.dispatch('updatePinnedComment', body) - .catch(({name, violations}) => { - if (name === 'ValidationException' || name === 'AccessException') { - violations.forEach((violation) => this.$toast.open({message: violation})); - } else { - this.$toast.open({message: 'An error occurred'}) - } - }); - } else { - this.$store.dispatch('addPinnedComment', this.formData) - .catch(({name, violations}) => { - if (name === 'ValidationException' || name === 'AccessException') { - violations.forEach((violation) => this.$toast.open({message: violation})); - } else { - this.$toast.open({message: 'An error occurred'}) - } - }); - } + let lastRecordedContent = this.formData.content; + setTimeout(() => { + if (lastRecordedContent === this.formData.content) { + if (this.pinnedComment) { + let body = this.formData; + Object.assign(body, {id: this.pinnedComment.id}); + + this.$store.dispatch('updatePinnedComment', body) + .catch(({name, violations}) => { + if (name === 'ValidationException' || name === 'AccessException') { + violations.forEach((violation) => this.$toast.open({message: violation})); + } else { + this.$toast.open({message: 'An error occurred'}) + } + }); + } else { + this.$store.dispatch('addPinnedComment', this.formData) + .catch(({name, violations}) => { + if (name === 'ValidationException' || name === 'AccessException') { + violations.forEach((violation) => this.$toast.open({message: violation})); + } else { + this.$toast.open({message: 'An error occurred'}) + } + }); + } + lastRecordedContent = null; + } + }, 3000); }, removeComment() { this.$store.dispatch('removePinnedComment', {id: this.pinnedComment.id}) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js index 5f0321c70..f1e2de958 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js @@ -122,7 +122,7 @@ const appMessages = { title: "Observations", label: "Ajout d'une note", content: "Rédigez une première note…", - created_by: "créé par {0}, le {1}" + created_by: "créé par {0}, mis à jour le {1}" }, confirm: { title: "Confirmation", diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index 5b196df10..bfb6412ff 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -370,12 +370,10 @@ let initPromise = (root) => Promise.all([getScopesPromise(root), accompanyingCou }) }, updatePinnedComment({ commit }, payload) { - console.log(payload) const url = `/api/1.0/person/accompanying-period/comment/${payload.id}.json`; return makeFetch('PATCH', url, payload) .then((response) => { - console.log(response) commit('addPinnedComment', response); }) .catch((error) => {