Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 13m31s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 13m53s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 13m53s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 13m44s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 12m3s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 12m20s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 10m35s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 1m1s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 12m13s
CI / Build-Artefakte aktuell (pull_request) Successful in 4m56s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
107 lines
5.9 KiB
Vue
107 lines
5.9 KiB
Vue
<script setup>
|
|
import { computed, ref } from 'vue';
|
|
import { Link } from '@inertiajs/vue3';
|
|
import { CalendarDays, Heart, MessageCircle, Vote } from '@lucide/vue';
|
|
import { Button } from '@/components/ui/button';
|
|
import PersonAvatar from '@/components/PersonAvatar.vue';
|
|
import { formatRelative } from '@/lib/format';
|
|
import { http } from '@/lib/http';
|
|
|
|
/** Ein Beitrag im Feed der Mitarbeiter-App (Neuigkeit, neue Kollegin, Termin, Umfrage, Gruppenbeitrag …) */
|
|
const props = defineProps({
|
|
item: { type: Object, required: true },
|
|
});
|
|
|
|
// Gefällt mir: sofort umschalten, bei Fehler zurück
|
|
const liked = ref(!!props.item.like?.liked);
|
|
const likes = ref(props.item.stats?.likes ?? 0);
|
|
const busy = ref(false);
|
|
|
|
async function toggleLike() {
|
|
if (!props.item.like || busy.value) return;
|
|
|
|
const next = !liked.value;
|
|
liked.value = next;
|
|
likes.value += next ? 1 : -1;
|
|
busy.value = true;
|
|
|
|
try {
|
|
if (props.item.like.mode === 'reaction') {
|
|
await http.post(props.item.like.url, { emoji: next ? '❤️' : null });
|
|
} else {
|
|
await (next ? http.post(props.item.like.url) : http.delete(props.item.like.url));
|
|
}
|
|
} catch {
|
|
liked.value = !next;
|
|
likes.value += next ? -1 : 1;
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
const kindIcon = computed(() => ({ event: CalendarDays, poll: Vote })[props.item.kind] ?? null);
|
|
const internal = (url) => url?.startsWith('/');
|
|
</script>
|
|
|
|
<template>
|
|
<!-- Neu im Team: Person im Mittelpunkt -->
|
|
<article v-if="item.kind === 'welcome'" class="flex items-center gap-5 rounded-lg border bg-card p-5">
|
|
<Link :href="item.url" class="shrink-0"><PersonAvatar :person="item.actor" class="size-20 text-2xl" /></Link>
|
|
<div class="grid min-w-0 flex-1 gap-1.5">
|
|
<span class="text-xs font-bold tracking-wider text-accent2-text uppercase">{{ item.badge }}</span>
|
|
<Link :href="item.url" class="text-lg leading-snug font-semibold hover:underline">{{ item.title }}</Link>
|
|
<p v-if="item.text" class="text-sm text-muted-foreground">{{ item.text }}</p>
|
|
<div v-if="item.cta" class="pt-1">
|
|
<Button size="sm" class="rounded-pill" as-child><Link :href="item.cta.url">{{ item.cta.label }}</Link></Button>
|
|
</div>
|
|
</div>
|
|
</article>
|
|
|
|
<article v-else class="overflow-hidden rounded-lg border bg-card">
|
|
<header class="flex items-center gap-3 px-5 pt-4 pb-3">
|
|
<PersonAvatar v-if="item.actor" :person="item.actor" class="size-10" />
|
|
<span v-else-if="kindIcon" class="grid size-10 place-items-center rounded-full bg-brand-soft text-brand-text"><component :is="kindIcon" class="size-5" /></span>
|
|
<div class="min-w-0 flex-1 text-sm leading-snug">
|
|
<p>
|
|
<Link v-if="item.actor" :href="`/personen/${item.actor.id}`" class="font-semibold hover:underline">{{ item.actor.name }}</Link>
|
|
<span v-else class="font-semibold">{{ item.badge }}</span>
|
|
<template v-if="item.context"> in <Link :href="item.context.url" class="font-semibold hover:underline">{{ item.context.label }}</Link></template>
|
|
<span v-else-if="item.action" class="text-muted-foreground"> {{ item.action }}</span>
|
|
</p>
|
|
<p class="text-xs text-muted-foreground">{{ formatRelative(item.time) }}<template v-if="item.actor?.subtitle"> · {{ item.actor.subtitle }}</template></p>
|
|
</div>
|
|
</header>
|
|
|
|
<component :is="internal(item.url) ? Link : 'a'" :href="item.url" class="block">
|
|
<div v-if="item.title || item.text" class="grid gap-1.5 px-5 pb-4">
|
|
<span v-if="item.badge && item.actor" class="text-xs font-bold tracking-wider text-accent2-text uppercase">{{ item.badge }}</span>
|
|
<h3 v-if="item.title" class="text-lg leading-snug font-semibold text-balance">{{ item.title }}</h3>
|
|
<p v-if="item.text" class="line-clamp-4 text-[15px] leading-relaxed whitespace-pre-line text-muted-foreground">{{ item.text }}</p>
|
|
</div>
|
|
<img v-if="item.image_url" :src="item.image_url" alt="" loading="lazy" class="max-h-[380px] w-full object-cover" />
|
|
<div v-else-if="item.images.length" class="grid gap-0.5" :class="item.images.length > 1 ? 'grid-cols-2' : ''">
|
|
<img v-for="(src, i) in item.images.slice(0, 4)" :key="i" :src="src" alt="" loading="lazy" class="w-full object-cover" :class="item.images.length > 1 ? 'aspect-[4/3]' : 'max-h-[380px]'" />
|
|
</div>
|
|
</component>
|
|
|
|
<footer v-if="item.stats || item.cta || item.like" class="flex items-center gap-4 border-t px-5 py-2 text-sm text-muted-foreground">
|
|
<button
|
|
v-if="item.like"
|
|
type="button"
|
|
class="-ml-2 inline-flex items-center gap-1.5 rounded-pill px-2 py-1 font-medium hover:bg-accent"
|
|
:class="liked ? 'text-rose-600 dark:text-rose-400' : ''"
|
|
:aria-pressed="liked"
|
|
:aria-label="liked ? 'Gefällt mir nicht mehr' : 'Gefällt mir'"
|
|
@click="toggleLike"
|
|
>
|
|
<Heart class="size-4" :fill="liked ? 'currentColor' : 'none'" /> {{ likes }}
|
|
</button>
|
|
<span v-else-if="item.stats?.likes != null" class="inline-flex items-center gap-1.5"><Heart class="size-4" /> {{ item.stats.likes }}</span>
|
|
<span v-if="item.stats?.comments != null" class="inline-flex items-center gap-1.5"><MessageCircle class="size-4" /> {{ item.stats.comments }}</span>
|
|
<span v-if="item.stats?.label">{{ item.stats.label }}</span>
|
|
<Button v-if="item.cta" size="sm" variant="outline" class="ml-auto rounded-pill" as-child>
|
|
<component :is="internal(item.cta.url) ? Link : 'a'" :href="item.cta.url">{{ item.cta.label }}</component>
|
|
</Button>
|
|
</footer>
|
|
</article>
|
|
</template>
|