inhaus-plugin-chat/resources/js/components/ConversationList.vue
Friederich Loheide 2844452002 Nachrichten-Plugin 1.0.0: Direktnachrichten, Gruppen, Anhänge, GIFs, Emojis
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 16:34:53 +00:00

64 lines
4.1 KiB
Vue

<script setup>
import { computed, ref } from 'vue';
import { BellOff, MessageSquarePlus, Search, UsersRound } from '@lucide/vue';
import { Button } from '@inhaus/ui';
import ChatAvatar from './ChatAvatar.vue';
import { listTime } from '../lib/format';
const props = defineProps({
conversations: { type: Array, required: true },
activeId: { type: Number, default: null },
canCreateGroups: { type: Boolean, default: false },
});
const emit = defineEmits(['open', 'new-chat', 'new-group']);
const query = ref('');
const filtered = computed(() => {
const q = query.value.trim().toLowerCase();
return q ? props.conversations.filter((c) => [c.name, ...c.members.map((m) => m.name)].join(' ').toLowerCase().includes(q)) : props.conversations;
});
</script>
<template>
<div class="ih:flex ih:h-full ih:min-h-0 ih:flex-col">
<div class="ih:flex ih:items-center ih:gap-2 ih:border-b ih:p-3">
<h1 class="ih:flex-1 ih:text-lg ih:font-semibold ih:tracking-tight">Nachrichten</h1>
<Button v-if="canCreateGroups" variant="ghost" size="icon" title="Neue Gruppe" aria-label="Neue Gruppe" @click="emit('new-group')"><UsersRound /></Button>
<Button size="icon" title="Neue Nachricht" aria-label="Neue Nachricht" @click="emit('new-chat')"><MessageSquarePlus /></Button>
</div>
<div class="ih:border-b ih:p-3">
<div class="ih:relative">
<Search class="ih:pointer-events-none ih:absolute ih:top-1/2 ih:left-2.5 ih:size-4 ih:-translate-y-1/2 ih:text-muted-foreground" />
<input v-model="query" type="search" placeholder="Gespräche durchsuchen" aria-label="Gespräche durchsuchen" class="ih:h-9 ih:w-full ih:rounded-md ih:bg-muted ih:pr-3 ih:pl-8 ih:text-sm ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none" />
</div>
</div>
<ul class="ih:min-h-0 ih:flex-1 ih:overflow-y-auto" aria-label="Gespräche">
<li v-for="c in filtered" :key="c.id">
<button
type="button"
class="ih:flex ih:w-full ih:items-center ih:gap-3 ih:px-3 ih:py-2.5 ih:text-left ih:transition-colors"
:class="c.id === activeId ? 'ih:bg-brand-soft' : 'ih:hover:bg-accent/60'"
:aria-current="c.id === activeId ? 'true' : undefined"
@click="emit('open', c.id)"
>
<ChatAvatar :conversation="c" size="ih:size-11" />
<span class="ih:min-w-0 ih:flex-1">
<span class="ih:flex ih:items-baseline ih:gap-2">
<span class="ih:min-w-0 ih:flex-1 ih:truncate ih:text-sm" :class="c.unread ? 'ih:font-semibold' : 'ih:font-medium'">{{ c.name }}</span>
<span class="ih:shrink-0 ih:text-[11px] ih:text-muted-foreground ih:tabular-nums">{{ listTime(c.last_message_at) }}</span>
</span>
<span class="ih:flex ih:items-center ih:gap-2">
<span class="ih:min-w-0 ih:flex-1 ih:truncate ih:text-[13px]" :class="c.unread ? 'ih:text-foreground' : 'ih:text-muted-foreground'">{{ c.preview ?? (c.type === 'group' ? `${c.members.length} Mitglieder` : 'Noch keine Nachrichten') }}</span>
<BellOff v-if="c.muted" class="ih:size-3.5 ih:shrink-0 ih:text-muted-foreground" aria-label="Stummgeschaltet" />
<span v-if="c.unread" class="ih:grid ih:h-5 ih:min-w-5 ih:shrink-0 ih:place-items-center ih:rounded-full ih:bg-brand ih:px-1.5 ih:text-[11px] ih:font-semibold ih:text-brand-foreground ih:tabular-nums" :aria-label="`${c.unread} ungelesen`">{{ c.unread > 99 ? '99+' : c.unread }}</span>
</span>
</span>
</button>
</li>
<li v-if="!filtered.length" class="ih:p-6 ih:text-center ih:text-sm ih:text-muted-foreground">
{{ query ? 'Nichts gefunden.' : 'Noch keine Gespräche. Oben rechts eine neue Nachricht beginnen.' }}
</li>
</ul>
</div>
</template>