Loheide-eu-mitarbeiterplatt.../resources/js/widgets/PeopleSearch.vue
Friederich Loheide b276e1c6d0
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m24s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m26s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m31s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m18s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
Globale Live-Suche, Kontaktkarten-Personensuche, neue Beitragsansicht, Termine mit Seitenleiste, Demo-Inhalte, Plugin-Upload-Fix
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 19:07:13 +00:00

108 lines
4.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup>
import { ref, watch } from 'vue';
import { Link, router } from '@inertiajs/vue3';
import { useDebounceFn } from '@vueuse/core';
import { ArrowRight, LoaderCircle, Search } from '@lucide/vue';
import Panel from '@/components/Panel.vue';
import { http } from '@/lib/http';
import { colorFor } from '@/lib/colors';
/**
* Live-Suche nach Kolleginnen und Kollegen – Treffer als Kontaktkarten
* mit den unter „Portal → Startseite“ gewählten Profilfeldern.
*/
defineProps({
count: { type: Number, required: true },
});
const query = ref('');
const people = ref([]);
const total = ref(0);
const loading = ref(false);
let latest = 0;
const load = useDebounceFn(async (value) => {
const ticket = ++latest;
try {
const data = await http.get(`/personen/karten?q=${encodeURIComponent(value)}`);
if (ticket === latest) {
people.value = data.people;
total.value = data.total;
}
} finally {
if (ticket === latest) loading.value = false;
}
}, 220);
watch(query, (value) => {
if (value.trim().length < 2) {
latest++;
people.value = [];
total.value = 0;
loading.value = false;
return;
}
loading.value = true;
load(value.trim());
});
function submit() {
if (query.value.trim()) router.visit(`/personen?q=${encodeURIComponent(query.value.trim())}`);
}
const href = (field) => (field.type === 'email' ? `mailto:${field.value}` : field.type === 'phone' ? `tel:${field.value.replace(/[^\d+]/g, '')}` : null);
</script>
<template>
<Panel title="Kolleg:innen finden">
<form role="search" class="relative" @submit.prevent="submit">
<Search class="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" />
<input
v-model="query"
name="q"
type="search"
autocomplete="off"
placeholder="Name, Funktion, Abteilung …"
class="h-10 w-full rounded-full border border-input bg-background pr-9 pl-9 text-sm placeholder:text-muted-foreground focus-visible:border-brand-400 focus-visible:ring-3 focus-visible:ring-ring/30 focus-visible:outline-none"
/>
<LoaderCircle v-if="loading" class="absolute top-1/2 right-3 size-4 -translate-y-1/2 animate-spin text-muted-foreground" />
</form>
<div v-if="people.length" class="mt-4 grid gap-3">
<article v-for="person in people" :key="person.id" class="overflow-hidden rounded-lg border border-l-4 border-l-brand bg-card shadow-xs">
<Link :href="`/personen/${person.id}`" class="flex items-center gap-3 p-3 hover:bg-accent/40">
<img v-if="person.avatar_url" :src="person.avatar_url" :alt="person.name" class="size-14 shrink-0 rounded-lg object-cover" />
<span v-else class="grid size-14 shrink-0 place-items-center rounded-lg text-lg font-semibold" :class="colorFor(person.id).soft">{{ person.initials }}</span>
<span class="min-w-0">
<span class="block font-semibold leading-tight">{{ person.name }}</span>
<span v-if="person.subtitle" class="mt-0.5 block text-xs text-muted-foreground">{{ person.subtitle }}</span>
</span>
</Link>
<dl v-if="person.fields.length" class="divide-y border-t px-3 text-[13px]">
<div v-for="field in person.fields" :key="field.key" class="py-2">
<dt class="text-[10px] font-semibold tracking-wider text-muted-foreground uppercase">{{ field.label }}</dt>
<dd class="mt-0.5 break-words">
<a v-if="href(field)" :href="href(field)" class="text-brand-text hover:underline">{{ field.value }}</a>
<template v-else>{{ field.value }}</template>
</dd>
</div>
</dl>
</article>
</div>
<p v-else-if="query.trim().length >= 2 && !loading" class="mt-4 text-[13px] text-muted-foreground">Niemand gefunden für „{{ query.trim() }}“.</p>
<Link
:href="query.trim().length >= 2 ? `/personen?q=${encodeURIComponent(query.trim())}` : '/personen'"
class="mt-4 flex items-center justify-between text-[13px] text-muted-foreground hover:text-foreground"
>
<template v-if="query.trim().length >= 2 && total > people.length">Alle {{ total.toLocaleString('de-DE') }} Treffer anzeigen</template>
<template v-else>{{ count === 1 ? '1 Person' : `${count.toLocaleString('de-DE')} Personen` }} im Verzeichnis</template>
<ArrowRight class="size-4" />
</Link>
</Panel>
</template>