send notification user method working

This commit is contained in:
isUnknown 2024-10-30 10:56:11 +01:00
parent 14f409abec
commit 9752fffae6
7 changed files with 67 additions and 18 deletions

View file

@ -6,4 +6,31 @@ Uuid: s0lNtRA0Z7ybTCWG
----
Template: document
Template: document
----
Comments:
m2vpa4tb:
page:
uri: >
projects/miss-dior-blooming-bouquet/client-brief
title: Brief client
file:
uuid: file://s0lNtRA0Z7ybTCWG
pageIndex: 1
replies: [ ]
text: test
user:
name: Utilisateur Dior
email: utilisateur@dior.com
uuid: user://HfuumN8s
role: client
date: 2024-10-30T10:54:49+01:00
id: m2vpa4tb
type: comment
isRead: false
position:
x: null
y: null

View file

@ -40,7 +40,7 @@ return [
'comments' => $comments
]);
$user->sendNotification('comments', $newComment->toArray());
$user->sendNotification('comments', $newComment);
return getFileData($newFile);
}

View file

@ -13,6 +13,7 @@ class BaseComment {
protected $date;
protected $id;
protected $type;
protected $isRead;
public function __construct($data) {
$page = $data['page'];
@ -44,6 +45,7 @@ class BaseComment {
$this->date = $date;
$this->id = $id;
$this->type = $type;
$this->isRead = false;
}
public function page() {
@ -78,6 +80,20 @@ class BaseComment {
return $this->type;
}
public function isRead() {
return $this->isRead;
}
public function read() {
$this->isRead = true;
return $this->isRead;
}
public function unread() {
$this->isRead = false;
return $this->isRead;
}
public function toArray() {
return [
'page' => $this->page,
@ -88,6 +104,7 @@ class BaseComment {
'date' => $this->date,
'id' => $this->id,
'type' => $this->type,
'isRead' => $this->isRead
];
}
}

View file

@ -3,5 +3,8 @@
Kirby::plugin('adrienpayet/pdc-notifications', [
'routes' => [
require(__DIR__ . '/routes/mark-as-read.php'),
],
'userMethods' => [
'sendNotification' => require(__DIR__ . '/user-methods/send.php')
]
]);

View file

@ -1,6 +1,6 @@
<?php
return function ($group, $data) {
return function ($group, $item) {
foreach (kirby()->users()->not($this) as $otherUser) {
try {
$notifications = $otherUser->notifications()->isNotEmpty()
@ -10,11 +10,8 @@ return function ($group, $data) {
if (!isset($notifications[$group])) {
$notifications[$group] = [];
}
$data['isRead'] = false;
$notifications[$group][$data['id']] = $data;
$notifications[$group][$item->id()] = $item->toArray();
$otherUser->update([
'notifications' => $notifications

View file

@ -1,8 +1,12 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { ref, computed } from "vue";
export const useUserStore = defineStore("user", () => {
const user = ref(null);
return { user };
const notifications = computed(() => {
return user.value.notifications;
});
return { user, notifications };
});

View file

@ -2,12 +2,15 @@
<main class="wrapper">
<h2 id="tabslist" class="sr-only">Status</h2>
<Tabs :tabs="tabs" @update:currentTab="changeTab" />
<button class="btn | absolute top-0 right-gutter" disabled>
<button
class="btn | absolute top-0 right-gutter"
:disabled="!notifications.length"
>
Marquer tout come lu
</button>
<div
v-if="comments.length === 0"
v-if="notifications.length === 0"
class="flex flex-col justify-center | text-grey-700 | absolute inset-0 -z-1"
>
<svg
@ -108,7 +111,7 @@ import { storeToRefs } from "pinia";
dayjs.locale("fr");
const { page } = storeToRefs(usePageStore());
const user = useUserStore().user;
const { notifications } = storeToRefs(useUserStore());
const currentTab = ref("all");
const tabs = computed(() => {
return [
@ -129,18 +132,16 @@ const tabs = computed(() => {
];
});
const comments = user?.notifications?.comments
? Object.values(user.notifications.comments)
: [];
const notifications = [...comments];
const allNotifications = computed(() => {
return Object.values(notifications.value);
});
function changeTab(newValue) {
currentTab.value = newValue;
}
const isEmpty = computed(() => {
return comments.length === 0;
return notifications.value.length === 0;
});
</script>