fix replies sorting
This commit is contained in:
parent
20824983a6
commit
78e2f8f956
3 changed files with 66 additions and 41 deletions
|
|
@ -19,36 +19,53 @@ Comments:
|
||||||
file:
|
file:
|
||||||
uuid: file://s0lNtRA0Z7ybTCWG
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
pageIndex: 1
|
pageIndex: 1
|
||||||
replies: [ ]
|
replies:
|
||||||
text: Premier commentaire
|
-
|
||||||
|
page:
|
||||||
|
uri: projects/miss-dior-blooming-bouquet
|
||||||
|
title: Miss Dior Blooming Bouquet
|
||||||
|
file:
|
||||||
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
|
pageIndex: 1
|
||||||
|
replies: [ ]
|
||||||
|
text: Test de réponse
|
||||||
|
author:
|
||||||
|
name: Adrien Payet
|
||||||
|
email: adrien.payet@outlook.com
|
||||||
|
uuid: user://WWjXgPWk
|
||||||
|
role: admin
|
||||||
|
date: 2024-10-30T12:26:44+01:00
|
||||||
|
id: m2vskcko
|
||||||
|
type: comment
|
||||||
|
isRead: false
|
||||||
|
parentId: m2vsk6jn
|
||||||
|
-
|
||||||
|
page:
|
||||||
|
uri: projects/miss-dior-blooming-bouquet
|
||||||
|
title: Miss Dior Blooming Bouquet
|
||||||
|
file:
|
||||||
|
uuid: file://s0lNtRA0Z7ybTCWG
|
||||||
|
pageIndex: 1
|
||||||
|
replies: [ ]
|
||||||
|
text: deuxième réponse
|
||||||
|
author:
|
||||||
|
name: Adrien Payet
|
||||||
|
email: adrien.payet@outlook.com
|
||||||
|
uuid: user://WWjXgPWk
|
||||||
|
role: admin
|
||||||
|
date: 2024-10-30T12:27:42+01:00
|
||||||
|
id: m2vslkxg
|
||||||
|
type: comment
|
||||||
|
isRead: false
|
||||||
|
parentId: m2vsk6jn
|
||||||
|
text: Un premier commentaire
|
||||||
author:
|
author:
|
||||||
name: Utilisateur Dior
|
name: Adrien Payet
|
||||||
email: utilisateur@dior.com
|
email: adrien.payet@outlook.com
|
||||||
uuid: user://HfuumN8s
|
uuid: user://WWjXgPWk
|
||||||
role: client
|
role: admin
|
||||||
date: 2024-10-30T12:08:36+01:00
|
date: 2024-10-30T12:26:37+01:00
|
||||||
id: m2vrx0ls
|
id: m2vsk6jn
|
||||||
type: comment
|
|
||||||
isRead: false
|
|
||||||
position:
|
|
||||||
x: null
|
|
||||||
y: null
|
|
||||||
-
|
|
||||||
page:
|
|
||||||
uri: projects/miss-dior-blooming-bouquet
|
|
||||||
title: Miss Dior Blooming Bouquet
|
|
||||||
file:
|
|
||||||
uuid: file://s0lNtRA0Z7ybTCWG
|
|
||||||
pageIndex: 1
|
|
||||||
replies: [ ]
|
|
||||||
text: Deuxième commentaire
|
|
||||||
author:
|
|
||||||
name: Utilisateur Dior
|
|
||||||
email: utilisateur@dior.com
|
|
||||||
uuid: user://HfuumN8s
|
|
||||||
role: client
|
|
||||||
date: 2024-10-30T12:08:41+01:00
|
|
||||||
id: m2vrx4zz
|
|
||||||
type: comment
|
type: comment
|
||||||
isRead: false
|
isRead: false
|
||||||
position:
|
position:
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ return [
|
||||||
'file' => $file,
|
'file' => $file,
|
||||||
'filePageIndex' => $data->filePageIndex,
|
'filePageIndex' => $data->filePageIndex,
|
||||||
'text' => $data->text,
|
'text' => $data->text,
|
||||||
'user' => $user,
|
'author' => $user,
|
||||||
'date' => (string) $data->date,
|
'date' => (string) $data->date,
|
||||||
'id' => $data->id,
|
'id' => $data->id,
|
||||||
'type' => 'comment'
|
'type' => 'comment'
|
||||||
|
|
@ -30,13 +30,17 @@ return [
|
||||||
|
|
||||||
$newReply = new Reply($data);
|
$newReply = new Reply($data);
|
||||||
|
|
||||||
$comments[$newReply->parentId()]['replies'][$newReply->id()] = $newReply->toArray();
|
foreach ($comments as &$comment) {
|
||||||
|
if ($comment['id'] === $newReply->parentId()) {
|
||||||
|
$comment['replies'][] = $newReply->toArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$newFile = $file->update([
|
$newFile = $file->update([
|
||||||
'comments' => $comments
|
'comments' => $comments
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user->sendNotification('comments', $newReply->toArray());
|
$user->sendNotification($newReply);
|
||||||
|
|
||||||
return getFileData($newFile);
|
return getFileData($newFile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,11 @@
|
||||||
<span>Retour à la liste</span>
|
<span>Retour à la liste</span>
|
||||||
</button>
|
</button>
|
||||||
<Comment :comment="openedComment" data-opened="true" />
|
<Comment :comment="openedComment" data-opened="true" />
|
||||||
<div
|
<div v-if="sortedReplies.length > 0" class="replies">
|
||||||
v-if="Object.values(openedComment.replies).length > 0"
|
|
||||||
class="replies"
|
|
||||||
>
|
|
||||||
<Comment
|
<Comment
|
||||||
v-for="(reply, commentIndex) in Object.values(
|
v-for="(reply, commentIndex) in sortedReplies"
|
||||||
openedComment.replies
|
|
||||||
).reverse()"
|
|
||||||
:comment="reply"
|
:comment="reply"
|
||||||
:commentIndex="commentIndex + 1"
|
:commentIndex="sortedReplies.length - commentIndex"
|
||||||
:key="reply.id"
|
:key="reply.id"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -114,6 +109,13 @@ const emits = defineEmits(["update:file"]);
|
||||||
const sortedComments = computed(() => {
|
const sortedComments = computed(() => {
|
||||||
return comments.reverse();
|
return comments.reverse();
|
||||||
});
|
});
|
||||||
|
const sortedReplies = computed(() => {
|
||||||
|
const sortedReplies =
|
||||||
|
openedComment.value && openedComment.value.replies
|
||||||
|
? openedComment.value.replies.slice().reverse()
|
||||||
|
: [];
|
||||||
|
return sortedReplies;
|
||||||
|
});
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
function handleSubmit(event) {
|
function handleSubmit(event) {
|
||||||
|
|
@ -140,7 +142,9 @@ async function replyComment(newComment) {
|
||||||
const newFile = await api.replyComment(newComment);
|
const newFile = await api.replyComment(newComment);
|
||||||
newCommentText.value = "";
|
newCommentText.value = "";
|
||||||
isAddOpen.value = false;
|
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);
|
emits("update:file", newFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue