Skip to content

Commit

Permalink
fix: save draft based on the comment id, not on reply id (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlopin authored Jun 27, 2024
1 parent bb7cb42 commit 0979869
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion frontend/html/comments/types/reply.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
{% endif %}

{% if me and me.is_active_membership and comment.post.is_commentable %}
<span class="comment-footer-button" v-on:click="showReplyForm('{{ reply_to.id }}', '{{ comment.author.slug }}')">
<span class="comment-footer-button" v-on:click="showReplyForm('{{ reply_to.id }}', '{{ comment.author.slug }}', '{{ comment.id }}')">
<i class="fas fa-reply"></i>&nbsp;ответить
</span>
{% endif %}
Expand Down
12 changes: 9 additions & 3 deletions frontend/static/js/components/ReplyContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
export default {
name: 'ReplyContainer',
props: {
// type { commentId: string, username: string, draftKey?: string }
replyTo: {
type: Object
},
Expand Down Expand Up @@ -65,7 +66,7 @@ export default {
replyTo: async function(newReplyTo, oldReplyTo) {
this.replyTo = newReplyTo;
if (oldReplyTo) {
this.saveDraft(oldReplyTo.commentId);
this.saveDraft(getDraftKey(oldReplyTo));
}
}
},
Expand All @@ -76,9 +77,10 @@ export default {
const newCommentEl = this.$el.querySelector(`#comment-${this.replyTo.commentId}`)
newCommentEl.after(replyForm)
const editor = this.getEditor()
const draftKey = getDraftKey(this.replyTo)
if (this.replyTo.commentId in this.drafts) {
const text = this.drafts[this.replyTo.commentId]
if (draftKey in this.drafts) {
const text = this.drafts[draftKey]
const textarea = replyForm.querySelector("textarea")
textarea.value = text
editor.setValue(text)
Expand Down Expand Up @@ -139,4 +141,8 @@ export default {
}
}
}
function getDraftKey(replyTo) {
return replyTo?.draftKey || replyTo?.commentId
}
</script>
4 changes: 2 additions & 2 deletions frontend/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ new Vue({
window.scrollBy(0, commentPosition.top);
}
},
showReplyForm(commentId, username) {
this.replyTo = { commentId, username }
showReplyForm(commentId, username, draftKey) {
this.replyTo = { commentId, username, draftKey }
},
},
});

0 comments on commit 0979869

Please sign in to comment.