fix replies sorting
This commit is contained in:
parent
20824983a6
commit
78e2f8f956
3 changed files with 66 additions and 41 deletions
|
|
@ -24,16 +24,11 @@
|
|||
<span>Retour à la liste</span>
|
||||
</button>
|
||||
<Comment :comment="openedComment" data-opened="true" />
|
||||
<div
|
||||
v-if="Object.values(openedComment.replies).length > 0"
|
||||
class="replies"
|
||||
>
|
||||
<div v-if="sortedReplies.length > 0" class="replies">
|
||||
<Comment
|
||||
v-for="(reply, commentIndex) in Object.values(
|
||||
openedComment.replies
|
||||
).reverse()"
|
||||
v-for="(reply, commentIndex) in sortedReplies"
|
||||
:comment="reply"
|
||||
:commentIndex="commentIndex + 1"
|
||||
:commentIndex="sortedReplies.length - commentIndex"
|
||||
:key="reply.id"
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -114,6 +109,13 @@ const emits = defineEmits(["update:file"]);
|
|||
const sortedComments = computed(() => {
|
||||
return comments.reverse();
|
||||
});
|
||||
const sortedReplies = computed(() => {
|
||||
const sortedReplies =
|
||||
openedComment.value && openedComment.value.replies
|
||||
? openedComment.value.replies.slice().reverse()
|
||||
: [];
|
||||
return sortedReplies;
|
||||
});
|
||||
|
||||
// Functions
|
||||
function handleSubmit(event) {
|
||||
|
|
@ -140,7 +142,9 @@ async function replyComment(newComment) {
|
|||
const newFile = await api.replyComment(newComment);
|
||||
newCommentText.value = "";
|
||||
isAddOpen.value = false;
|
||||
openedComment.value = newFile.comments[openedComment.value.id];
|
||||
openedComment.value = newFile.comments.find(
|
||||
(item) => item.id === openedComment.value.id
|
||||
);
|
||||
emits("update:file", newFile);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue