Skip to content

Commit

Permalink
fix: place reply form as sibling to comments (#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlopin committed Jul 3, 2024
1 parent ae34289 commit 6677f6d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
7 changes: 2 additions & 5 deletions frontend/html/posts/show/battle.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,17 @@

{% if comments %}
{% if post.is_commentable and me %}
<reply-container
<reply-form
:reply-to="replyTo"
comment-order="{{ comment_order }}"
avatar-url="{{ me.get_avatar }}"
username="{{ me.full_name }}"
create-comment-url="{% url "create_comment" post.slug %}"
>
></reply-form>
{% endif %}
<div class="post-comments-list">
{% include "comments/list.html" with comments=comments reply_form=reply_form type="battle" %}
</div>
{% if post.is_commentable and me %}
</reply-container>
{% endif %}
{% endif %}

{% if me and me.is_active_membership and post.is_commentable and post.is_visible or me.is_moderator %}
Expand Down
8 changes: 2 additions & 6 deletions frontend/html/posts/show/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,18 @@

{% if comments %}
{% if post.is_commentable and me %}
<reply-container
<reply-form
:reply-to="replyTo"
comment-order="{{ comment_order }}"
avatar-url="{{ me.get_avatar }}"
username="{{ me.full_name }}"
create-comment-url="{% url "create_comment" post.slug %}"
>
></reply-form>
{% endif %}

<div class="post-comments-list">
{% include "comments/list.html" with comments=comments reply_form=reply_form type="normal" muted_user_ids=muted_user_ids %}
</div>

{% if post.is_commentable and me %}
</reply-container>
{% endif %}
{% endif %}

{% if me and me.is_active_membership and post.is_commentable and post.is_visible or me.is_moderator %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<script>
export default {
name: 'ReplyContainer',
name: 'ReplyForm',
props: {
// type { commentId: string, username: string, draftKey?: string }
replyTo: {
Expand Down Expand Up @@ -82,8 +82,8 @@ export default {
updated: function() {
if (this.replyTo !== null && this.getEditor()) {
// move the reply form under the comment
const replyForm = this.$el.querySelector("#comment-reply-form")
const newCommentEl = this.$el.querySelector(`#comment-${this.replyTo.commentId}`)
const replyForm = document.getElementById("comment-reply-form")
const newCommentEl = document.getElementById(`comment-${this.replyTo.commentId}`)
newCommentEl.after(replyForm)
const editor = this.getEditor()
const draftKey = getDraftKey(this.replyTo)
Expand All @@ -110,7 +110,7 @@ export default {
},
methods: {
appendMarkdownTextareaValue: function(value) {
const textarea = this.$el.querySelector("#comment-reply-form textarea")
const textarea = document.querySelector("#comment-reply-form textarea")
textarea.focus(); // on mobile
textarea.value = textarea.value + value;
Expand All @@ -128,7 +128,7 @@ export default {
},
getEditor: function() {
if (!this.editor) {
const textarea = this.$el.querySelector("#comment-reply-form textarea")
const textarea = document.querySelector("#comment-reply-form textarea")
textarea.focus(); // on mobile
if (!textarea.nextElementSibling) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Vue.component("comment-markdown-editor", () => import("./components/CommentMarkd
Vue.component("v-select", vSelect);
Vue.component("tag-select", () => import("./components/TagSelect.vue"));
Vue.component("simple-select", () => import("./components/SimpleSelect.vue"));
Vue.component("reply-container", () => import("./components/ReplyContainer.vue"));
Vue.component("reply-form", () => import("./components/ReplyForm.vue"));

// Since our pages have user-generated content, any fool can insert "{{" on the page and break it.
// We have no other choice but to completely turn off template matching and leave it on only for components.
Expand Down

0 comments on commit 6677f6d

Please sign in to comment.