change notifications structure from object to array

This commit is contained in:
isUnknown 2024-10-30 12:15:28 +01:00
parent 0d25794b87
commit 20824983a6
8 changed files with 64 additions and 50 deletions

View file

@ -12,23 +12,43 @@ Template: document
Comments:
m2vpa4tb:
-
page:
uri: >
projects/miss-dior-blooming-bouquet/client-brief
title: Brief client
uri: projects/miss-dior-blooming-bouquet
title: Miss Dior Blooming Bouquet
file:
uuid: file://s0lNtRA0Z7ybTCWG
pageIndex: 1
replies: [ ]
text: test
user:
text: Premier commentaire
author:
name: Utilisateur Dior
email: utilisateur@dior.com
uuid: user://HfuumN8s
role: client
date: 2024-10-30T10:54:49+01:00
id: m2vpa4tb
date: 2024-10-30T12:08:36+01:00
id: m2vrx0ls
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
isRead: false
position:

View file

@ -26,7 +26,7 @@ return [
],
'replies' => [],
'text' => $data->text,
'user' => $user,
'author' => $user,
'date' => (string) $data->date,
'id' => $data->id,
'type' => 'comment'
@ -34,13 +34,13 @@ return [
$newComment = new Comment($data);
$comments[$newComment->id()] = $newComment->toArray();
$comments[] = $newComment->toArray();
$newFile = $file->update([
'comments' => $comments
]);
$user->sendNotification('comments', $newComment);
$user->sendNotification($newComment);
return getFileData($newFile);
}

View file

@ -9,7 +9,7 @@ class BaseComment {
protected $position;
protected $replies;
protected $text;
protected $user;
protected $author;
protected $date;
protected $id;
protected $type;
@ -21,7 +21,7 @@ class BaseComment {
$filePageIndex = $data['filePageIndex'];
$replies = $data['replies'] ?? [];
$text = $data['text'];
$user = $data['user'];
$author = $data['author'];
$date = $data['date'];
$id = $data['id'];
$type = $data['type'] ?? 'comment';
@ -36,11 +36,11 @@ class BaseComment {
];
$this->replies = $replies ?? [];
$this->text = $text;
$this->user = [
'name' => (string) $user->name(),
'email' => (string) $user->email(),
'uuid' => (string) $user->uuid(),
'role' => (string) $user->role(),
$this->author = [
'name' => (string) $author->name(),
'email' => (string) $author->email(),
'uuid' => (string) $author->uuid(),
'role' => (string) $author->role(),
];
$this->date = $date;
$this->id = $id;
@ -64,8 +64,8 @@ class BaseComment {
return $this->text;
}
public function user() {
return $this->user;
public function author() {
return $this->author;
}
public function date() {
@ -100,7 +100,7 @@ class BaseComment {
'file' => $this->file,
'replies' => $this->replies,
'text' => $this->text,
'user' => $this->user,
'author' => $this->author,
'date' => $this->date,
'id' => $this->id,
'type' => $this->type,

View file

@ -1,17 +1,13 @@
<?php
return function ($group, $item) {
return function ($item) {
foreach (kirby()->users()->not($this) as $otherUser) {
try {
$notifications = $otherUser->notifications()->isNotEmpty()
? Yaml::decode($otherUser->notifications()->value())
: [];
if (!isset($notifications[$group])) {
$notifications[$group] = [];
}
$notifications[$group][$item->id()] = $item->toArray();
$notifications[] = $item->toArray();
$otherUser->update([
'notifications' => $notifications

View file

@ -2,7 +2,7 @@
<article class="comment | flow" :data-status="setStatus(comment)">
<header>
<p>
<strong>{{ comment.user.name ?? comment.user.email }}</strong>
<strong>{{ comment.author.name ?? comment.author.email }}</strong>
<template v-if="commentIndex">
<span class="comment__id">#{{ commentIndex }}</span>

View file

@ -5,9 +5,9 @@
<template v-if="comments">
<template v-if="!openedComment">
<Comment
v-for="(comment, commentIndex) in Object.values(comments).reverse()"
v-for="(comment, commentIndex) in sortedComments"
:comment="comment"
:commentIndex="commentIndex + 1"
:commentIndex="comments.length - commentIndex"
:key="comment.id"
@click="openedComment = comment"
/>
@ -88,7 +88,7 @@
import dayjs from "dayjs";
import "dayjs/locale/fr";
import uniqid from "uniqid";
import { ref } from "vue";
import { computed, ref } from "vue";
import { useUserStore } from "../../stores/user";
import { usePageStore } from "../../stores/page";
import { useApiStore } from "../../stores/api";
@ -99,7 +99,7 @@ dayjs.locale("fr");
const { currentPageIndex, file, comments } = defineProps({
currentPageIndex: Number,
file: Object,
comments: Object,
comments: Array,
});
const { user } = useUserStore();
@ -111,6 +111,9 @@ const openedComment = ref(null);
const newCommentText = ref("");
const isAddOpen = ref(false);
const emits = defineEmits(["update:file"]);
const sortedComments = computed(() => {
return comments.reverse();
});
// Functions
function handleSubmit(event) {

View file

@ -38,7 +38,7 @@
>
<router-link
v-if="currentTab === 'all' || !notification.isRead"
:to="notification.page.uri + '?fileUuid=' + notification.file.uuid"
:to="notification.page.uri + '?notificationId=' + notification.id"
>
<article
class="notification | bg-white rounded-lg | p-16 | flow"
@ -136,13 +136,7 @@ const tabs = computed(() => {
});
const sortedNotifications = computed(() => {
const allNotifications = [
...Object.values(notifications.value.comments || {}),
...Object.values(notifications.value.content || {}),
...Object.values(notifications.value.meetings || {}),
];
const sortedNotifications = allNotifications.sort((a, b) => {
const sortedNotifications = notifications.value.sort((a, b) => {
dayjs(b.date).diff(dayjs(a.date));
});

View file

@ -179,17 +179,18 @@ const user = useUserStore().user;
const file = ref(null);
const route = useRoute();
// const route = useRoute();
if (route.query.fileUuid) {
page.value.steps.forEach((step) => {
step.files.forEach((item) => {
if (item.uuid === route.query.fileUuid) {
file.value = item;
}
});
});
}
// if (route.query.notificationId) {
// page.value.steps.forEach((step) => {
// const srcNotification = user.notifications;
// step.files.forEach((item) => {
// if (item.uuid === route.query.notificationId) {
// file.value = item;
// }
// });
// });
// }
function setStepStatus(stepName) {
const stepIndex = steps.indexOf(stepName);