read notification on click working
This commit is contained in:
parent
b1e8848fcd
commit
f99e33f80e
5 changed files with 55 additions and 31 deletions
|
|
@ -35,6 +35,7 @@ return [
|
||||||
'uuid' => (string) kirby()->user()->uuid(),
|
'uuid' => (string) kirby()->user()->uuid(),
|
||||||
'role' => (string) kirby()->user()->role(),
|
'role' => (string) kirby()->user()->role(),
|
||||||
],
|
],
|
||||||
|
'id' => Str::uuid(),
|
||||||
'type' => 'content'
|
'type' => 'content'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ load([
|
||||||
Kirby::plugin('adrienpayet/pdc-notifications', [
|
Kirby::plugin('adrienpayet/pdc-notifications', [
|
||||||
'routes' => [
|
'routes' => [
|
||||||
require(__DIR__ . '/routes/readAll.php'),
|
require(__DIR__ . '/routes/readAll.php'),
|
||||||
|
require(__DIR__ . '/routes/read.php')
|
||||||
],
|
],
|
||||||
'userMethods' => [
|
'userMethods' => [
|
||||||
'sendNotification' => require(__DIR__ . '/user-methods/send.php'),
|
'sendNotification' => require(__DIR__ . '/user-methods/send.php'),
|
||||||
|
|
|
||||||
13
public/site/plugins/notifications/routes/read.php
Normal file
13
public/site/plugins/notifications/routes/read.php
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'pattern' => '(:all)read-notification.json',
|
||||||
|
'method' => 'POST',
|
||||||
|
'action' => function () {
|
||||||
|
$json = file_get_contents('php://input');
|
||||||
|
$data = json_decode($json);
|
||||||
|
|
||||||
|
$newNotifications = kirby()->user()->readNotification($data->notificationId);
|
||||||
|
return $newNotifications;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
@ -197,7 +197,7 @@ export const useApiStore = defineStore("api", () => {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/read-comment.json", headers);
|
const response = await fetch("/read-notification.json", headers);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,38 +42,34 @@
|
||||||
class="notification | bg-white rounded-lg | p-16 | flow"
|
class="notification | bg-white rounded-lg | p-16 | flow"
|
||||||
:data-status="notification.isRead ? 'read' : 'unread'"
|
:data-status="notification.isRead ? 'read' : 'unread'"
|
||||||
:data-type="notification.type"
|
:data-type="notification.type"
|
||||||
|
@click="read(notification)"
|
||||||
>
|
>
|
||||||
<router-link
|
<header>
|
||||||
v-if="currentTab === 'all' || !notification.isRead"
|
<p class="flex">
|
||||||
:to="toPath(notification.location.href)"
|
<strong
|
||||||
>
|
class="notification__type | font-medium text-primary"
|
||||||
<header>
|
:data-icon="notification.type"
|
||||||
<p class="flex">
|
>Nouveau
|
||||||
<strong
|
{{
|
||||||
class="notification__type | font-medium text-primary"
|
notification.type === "comment" ? "commentaire" : "contenu"
|
||||||
:data-icon="notification.type"
|
}}</strong
|
||||||
>Nouveau
|
>
|
||||||
{{
|
<span class="notification__client | text-grey-700">{{
|
||||||
notification.type === "comment" ? "commentaire" : "contenu"
|
notification.location.project.title
|
||||||
}}</strong
|
}}</span>
|
||||||
>
|
<time
|
||||||
<span class="notification__client | text-grey-700">{{
|
datetime=""
|
||||||
notification.location.project.title
|
class="notification__date | text-grey-700 | ml-auto"
|
||||||
}}</span>
|
>{{ formatDate(notification) }}</time
|
||||||
<time
|
>
|
||||||
datetime=""
|
|
||||||
class="notification__date | text-grey-700 | ml-auto"
|
|
||||||
>{{ formatDate(notification) }}</time
|
|
||||||
>
|
|
||||||
</p>
|
|
||||||
</header>
|
|
||||||
<p
|
|
||||||
v-if="notification.type"
|
|
||||||
class="notification__body | text-md font-medium | line-clamp"
|
|
||||||
>
|
|
||||||
{{ notification.text }}
|
|
||||||
</p>
|
</p>
|
||||||
</router-link>
|
</header>
|
||||||
|
<p
|
||||||
|
v-if="notification.type"
|
||||||
|
class="notification__body | text-md font-medium | line-clamp"
|
||||||
|
>
|
||||||
|
{{ notification.text }}
|
||||||
|
</p>
|
||||||
</article>
|
</article>
|
||||||
</template>
|
</template>
|
||||||
<!-- <article
|
<!-- <article
|
||||||
|
|
@ -112,6 +108,7 @@ import { useUserStore } from "../stores/user";
|
||||||
import { ref, computed } from "vue";
|
import { ref, computed } from "vue";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { useApiStore } from "../stores/api";
|
import { useApiStore } from "../stores/api";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
|
|
||||||
dayjs.locale("fr");
|
dayjs.locale("fr");
|
||||||
|
|
||||||
|
|
@ -138,6 +135,8 @@ const tabs = computed(() => {
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const sortedNotifications = computed(() => {
|
const sortedNotifications = computed(() => {
|
||||||
return [...notifications.value].sort((a, b) => {
|
return [...notifications.value].sort((a, b) => {
|
||||||
return dayjs(b.date).diff(dayjs(a.date));
|
return dayjs(b.date).diff(dayjs(a.date));
|
||||||
|
|
@ -173,6 +172,15 @@ function readAll() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function read(notification) {
|
||||||
|
if (!notification.isRead) {
|
||||||
|
api.readNotification(notification.id).then((res) => {
|
||||||
|
router.push(toPath(notification.location.href));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
router.push(toPath(notification.location.href));
|
||||||
|
}
|
||||||
|
|
||||||
function toPath(string) {
|
function toPath(string) {
|
||||||
return string.replace(window.location.origin, "");
|
return string.replace(window.location.origin, "");
|
||||||
}
|
}
|
||||||
|
|
@ -198,6 +206,7 @@ main > header [role="tablist"] {
|
||||||
--flow-space: var(--space-12);
|
--flow-space: var(--space-12);
|
||||||
font-size: var(--text-sm);
|
font-size: var(--text-sm);
|
||||||
position: relative;
|
position: relative;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.notification[data-status="unread"]::after {
|
.notification[data-status="unread"]::after {
|
||||||
content: "";
|
content: "";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue