Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Фиксит сохранение неотправленных ответов #1220

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
},
},
});
Loading