Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m1s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m33s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m8s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m42s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m37s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m43s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
84 lines
4.3 KiB
Vue
84 lines
4.3 KiB
Vue
<script setup>
|
|
import AppIcon from '@/components/AppIcon.vue';
|
|
import PushToggle from '@/components/PushToggle.vue';
|
|
import { computed, ref } from 'vue';
|
|
import { router, usePage } from '@inertiajs/vue3';
|
|
import { Bell, CheckCheck, FileCheck, LoaderCircle, MessageSquare, Newspaper, Undo2 } from '@lucide/vue';
|
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
|
import { http } from '@/lib/http';
|
|
import { formatRelative } from '@/lib/format';
|
|
|
|
/**
|
|
* Glocke im Header: Benachrichtigungen (z. B. Freigabe angefordert, Beitrag freigegeben).
|
|
*/
|
|
const page = usePage();
|
|
const unread = computed(() => page.props.notifications?.unread ?? 0);
|
|
const items = ref(null);
|
|
const localUnread = ref(null);
|
|
const count = computed(() => localUnread.value ?? unread.value);
|
|
|
|
const icons = { 'file-check': FileCheck, newspaper: Newspaper, undo: Undo2, message: MessageSquare };
|
|
|
|
async function load(open) {
|
|
if (!open) return;
|
|
|
|
items.value = null;
|
|
const data = await http.get('/benachrichtigungen');
|
|
items.value = data.notifications;
|
|
localUnread.value = data.unread;
|
|
}
|
|
|
|
async function markAll() {
|
|
await http.post('/benachrichtigungen/gelesen');
|
|
items.value = items.value.map((item) => ({ ...item, read: true }));
|
|
localUnread.value = 0;
|
|
}
|
|
|
|
function open(item) {
|
|
localUnread.value = null;
|
|
router.visit(`/benachrichtigungen/${item.id}`);
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<Popover @update:open="load">
|
|
<PopoverTrigger
|
|
class="relative grid size-10 place-items-center rounded-md text-foreground/70 hover:bg-accent hover:text-foreground"
|
|
:aria-label="count ? `Benachrichtigungen, ${count} ungelesen` : 'Benachrichtigungen'"
|
|
>
|
|
<Bell class="size-5" />
|
|
<span v-if="count" class="absolute top-1.5 right-1.5 grid h-4 min-w-4 place-items-center rounded-pill bg-brand px-1 text-[10px] leading-none font-semibold text-brand-foreground">
|
|
{{ count > 9 ? '9+' : count }}
|
|
</span>
|
|
</PopoverTrigger>
|
|
<PopoverContent align="end" class="w-[22rem] p-0">
|
|
<div class="flex items-center justify-between border-b px-4 py-3">
|
|
<h2 class="text-sm font-semibold">Benachrichtigungen</h2>
|
|
<button v-if="count" type="button" class="inline-flex items-center gap-1 text-xs font-medium text-brand-text hover:underline" @click="markAll">
|
|
<CheckCheck class="size-3.5" /> Alle gelesen
|
|
</button>
|
|
</div>
|
|
<div class="max-h-[60vh] overflow-y-auto">
|
|
<div v-if="items === null" class="grid place-items-center py-8"><LoaderCircle class="size-5 animate-spin text-muted-foreground" /></div>
|
|
<p v-else-if="!items.length" class="px-4 py-8 text-center text-sm text-muted-foreground">Keine Benachrichtigungen.</p>
|
|
<ul v-else class="divide-y">
|
|
<li v-for="item in items" :key="item.id">
|
|
<button type="button" class="flex w-full gap-3 px-4 py-3 text-left hover:bg-accent/60" @click="open(item)">
|
|
<span class="mt-0.5 grid size-8 shrink-0 place-items-center rounded-full" :class="item.read ? 'bg-muted text-muted-foreground' : 'bg-brand-soft text-brand-text'">
|
|
<component :is="icons[item.icon]" v-if="icons[item.icon]" class="size-4" />
|
|
<AppIcon v-else :name="item.icon || 'bell'" class="size-4" />
|
|
</span>
|
|
<span class="min-w-0 flex-1">
|
|
<span class="block text-sm" :class="item.read ? 'text-foreground/80' : 'font-semibold'">{{ item.title }}</span>
|
|
<span v-if="item.body" class="mt-0.5 line-clamp-2 block text-[13px] text-muted-foreground">{{ item.body }}</span>
|
|
<span class="mt-1 block text-xs text-muted-foreground">{{ formatRelative(item.created_at) }}</span>
|
|
</span>
|
|
<span v-if="!item.read" class="mt-2 size-2 shrink-0 rounded-full bg-brand" aria-label="ungelesen" />
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="border-t px-4 py-2.5"><PushToggle compact /></div>
|
|
</PopoverContent>
|
|
</Popover>
|
|
</template>
|