Nachrichten-Plugin 1.0.0: Direktnachrichten, Gruppen, Anhänge, GIFs, Emojis
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
2844452002
55 changed files with 5448 additions and 0 deletions
37
resources/js/header/Unread.vue
Normal file
37
resources/js/header/Unread.vue
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<script setup>
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { MessageCircle } from '@lucide/vue';
|
||||
import { http } from '@inhaus/ui';
|
||||
|
||||
/**
|
||||
* Sprechblase neben der Glocke: Zahl der ungelesenen Nachrichten. Auf der Chat-Seite meldet
|
||||
* der Chat selbst, sonst wird alle 30 Sekunden nachgefragt.
|
||||
*/
|
||||
const props = defineProps({ unread: { type: Number, default: 0 } });
|
||||
const count = ref(props.unread);
|
||||
let timer;
|
||||
|
||||
const update = (event) => (count.value = event.detail);
|
||||
|
||||
async function poll() {
|
||||
if (document.visibilityState === 'visible' && !location.pathname.startsWith('/chat')) {
|
||||
count.value = (await http.get('/chat/api/ungelesen').catch(() => ({ unread: count.value }))).unread;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('inhaus-chat:unread', update);
|
||||
timer = setInterval(poll, 30000);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('inhaus-chat:unread', update);
|
||||
clearInterval(timer);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a href="/chat" class="ih:relative ih:grid ih:size-9 ih:place-items-center ih:rounded-md ih:text-muted-foreground ih:transition-colors ih:hover:bg-accent ih:hover:text-foreground" :aria-label="count ? `Nachrichten, ${count} ungelesen` : 'Nachrichten'" :title="count ? `${count} ungelesene Nachrichten` : 'Nachrichten'">
|
||||
<MessageCircle class="ih:size-5" />
|
||||
<span v-if="count" class="ih:absolute ih:top-0.5 ih:right-0.5 ih:grid ih:h-4 ih:min-w-4 ih:place-items-center ih:rounded-full ih:bg-brand ih:px-1 ih:text-[10px] ih:font-semibold ih:text-brand-foreground ih:tabular-nums" aria-hidden="true">{{ count > 99 ? '99+' : count }}</span>
|
||||
</a>
|
||||
</template>
|
||||
Loading…
Add table
Add a link
Reference in a new issue