inhaus-plugin-kleinanzeigen/resources/js/pages/Index.vue
Friederich Loheide 9a418d5465 Kleinanzeigen 1.3.0: einheitliche Werkzeugleiste mit Listenansicht
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-06 19:57:17 +00:00

114 lines
8.2 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 { watch } from 'vue';
import { Link, router, usePage } from '@inertiajs/vue3';
import { Heart, ListChecks, Plus, ShieldCheck, ShoppingBag } from '@lucide/vue';
import { AppLayout, Button, EmptyState, ListToolbar, PageHeader, toast, useListView } from '@inhaus/ui';
import ListingCard from '../components/ListingCard.vue';
const props = defineProps({
listings: { type: Array, required: true },
pagination: { type: Object, required: true },
filters: { type: Object, required: true },
types: { type: Object, required: true },
categories: { type: Object, required: true },
counts: { type: Object, default: () => ({}) },
pending: { type: Number, default: null },
mine: { type: Number, default: 0 },
});
const page = usePage();
watch(() => page.props.flash?.status, (status) => status && toast.success(status), { immediate: true });
const view = useListView('kleinanzeigen', 'grid');
function apply(changes) {
const params = { ...props.filters, ...changes };
router.get('/kleinanzeigen', Object.fromEntries(Object.entries(params).filter(([key, value]) => value && !(key === 'sortierung' && value === 'neu'))), { preserveState: true, preserveScroll: true });
}
const sorts = { neu: 'Neueste zuerst', preis: 'Preis aufsteigend', 'preis-ab': 'Preis absteigend' };
</script>
<template>
<AppLayout title="Kleinanzeigen">
<PageHeader title="Kleinanzeigen" description="Von Kolleginnen und Kollegen für Kolleginnen und Kollegen – verkaufen, verschenken, suchen, tauschen.">
<template #actions>
<Button v-if="pending !== null" variant="outline" as-child>
<Link href="/kleinanzeigen/moderation"><ShieldCheck /> Freigabe<span v-if="pending" class="ih:rounded-full ih:bg-brand ih:px-1.5 ih:text-[11px] ih:text-brand-foreground">{{ pending }}</span></Link>
</Button>
<Button variant="outline" as-child><Link href="/kleinanzeigen/meine"><ListChecks /> Meine Anzeigen<span v-if="mine" class="ih:text-muted-foreground">({{ mine }})</span></Link></Button>
<Button as-child><Link href="/kleinanzeigen/neu"><Plus /> Anzeige aufgeben</Link></Button>
</template>
</PageHeader>
<div class="ih:grid ih:gap-6 ih:lg:grid-cols-[15rem_minmax(0,1fr)]">
<aside class="ih:grid ih:content-start ih:gap-5">
<nav aria-label="Kategorien" class="ih:hidden ih:lg:block">
<h2 class="ih:mb-1.5 ih:text-xs ih:font-semibold ih:tracking-wider ih:text-muted-foreground ih:uppercase">Kategorien</h2>
<ul class="ih:grid ih:gap-0.5 ih:text-sm">
<li><button type="button" class="ih:flex ih:w-full ih:justify-between ih:rounded ih:px-2 ih:py-1.5 ih:text-left" :class="!filters.kategorie ? 'ih:bg-brand-soft ih:font-medium ih:text-brand-text' : 'ih:hover:bg-accent'" @click="apply({ kategorie: null })">Alle Kategorien</button></li>
<li v-for="(label, key) in categories" :key="key">
<button type="button" class="ih:flex ih:w-full ih:justify-between ih:gap-2 ih:rounded ih:px-2 ih:py-1.5 ih:text-left" :class="filters.kategorie === key ? 'ih:bg-brand-soft ih:font-medium ih:text-brand-text' : 'ih:hover:bg-accent'" @click="apply({ kategorie: key })">
<span>{{ label }}</span><span class="ih:text-xs ih:text-muted-foreground ih:tabular-nums">{{ counts[key] ?? 0 }}</span>
</button>
</li>
</ul>
</nav>
<select class="ih:h-10 ih:rounded-md ih:border ih:bg-card ih:px-2 ih:text-sm ih:lg:hidden" aria-label="Kategorie" :value="filters.kategorie ?? ''" @change="apply({ kategorie: $event.target.value || null })">
<option value="">Alle Kategorien</option>
<option v-for="(label, key) in categories" :key="key" :value="key">{{ label }} ({{ counts[key] ?? 0 }})</option>
</select>
</aside>
<section class="ih:min-w-0">
<ListToolbar
:filters="[{ value: null, label: 'Alle' }, ...Object.entries(types).map(([value, label]) => ({ value, label }))]"
:filter="filters.typ || null"
filter-label="Art"
:search="filters.q ?? ''"
search-placeholder="Anzeigen durchsuchen"
:sorts="Object.entries(sorts).map(([value, label]) => ({ value, label }))"
:sort="filters.sortierung || 'neu'"
v-model:view="view"
@update:filter="(value) => apply({ typ: value })"
@update:search="(value) => apply({ q: value })"
@update:sort="(value) => apply({ sortierung: value })"
>
<button type="button" class="ih:inline-flex ih:h-9 ih:items-center ih:gap-1.5 ih:rounded-full ih:border ih:px-3 ih:text-sm" :class="filters.merkliste ? 'ih:border-brand ih:bg-brand-soft ih:text-brand-text' : 'ih:bg-card ih:hover:bg-accent'" :aria-pressed="!!filters.merkliste" @click="apply({ merkliste: filters.merkliste ? null : 1 })">
<Heart class="ih:size-4" :class="filters.merkliste ? 'ih:fill-current' : ''" /> Merkliste
</button>
</ListToolbar>
<p class="ih:-mt-2 ih:mb-3 ih:text-sm ih:text-muted-foreground">{{ pagination.total }} {{ pagination.total === 1 ? 'Anzeige' : 'Anzeigen' }}</p>
<div v-if="listings.length && view === 'grid'" class="ih:grid ih:grid-cols-2 ih:gap-3 ih:sm:gap-4 ih:md:grid-cols-3 ih:xl:grid-cols-4">
<ListingCard v-for="listing in listings" :key="listing.id" :listing="listing" />
</div>
<ul v-else-if="listings.length" class="ih:divide-y ih:rounded-lg ih:border ih:bg-card">
<li v-for="listing in listings" :key="listing.id">
<Link :href="listing.url" class="ih:flex ih:items-center ih:gap-3 ih:px-4 ih:py-2.5 ih:hover:bg-accent/60">
<span class="ih:grid ih:size-14 ih:shrink-0 ih:place-items-center ih:overflow-hidden ih:rounded-md ih:bg-muted">
<img v-if="listing.thumb_url" :src="listing.thumb_url" alt="" class="ih:size-full ih:object-cover" />
<ShoppingBag v-else class="ih:size-5 ih:text-muted-foreground" />
</span>
<span class="ih:grid ih:min-w-0 ih:flex-1">
<span class="ih:text-xs ih:text-muted-foreground">{{ listing.type_label }} · {{ listing.category_label }}<template v-if="listing.reserved"> · reserviert</template></span>
<span class="ih:truncate ih:font-medium">{{ listing.title }}</span>
<span v-if="listing.location" class="ih:truncate ih:text-xs ih:text-muted-foreground">{{ listing.location }}</span>
</span>
<span v-if="listing.price" class="ih:shrink-0 ih:font-semibold ih:text-brand-text">{{ listing.price }}</span>
</Link>
</li>
</ul>
<div v-else class="ih:rounded-lg ih:border ih:bg-card">
<EmptyState :icon="ShoppingBag" :title="filters.q || filters.typ || filters.kategorie || filters.merkliste ? 'Keine passenden Anzeigen' : 'Noch keine Anzeigen'" text="Etwas übrig oder auf der Suche? Geben Sie die erste Anzeige auf." />
</div>
<nav v-if="pagination.last > 1" class="ih:mt-6 ih:flex ih:items-center ih:justify-between ih:text-sm" aria-label="Seiten">
<Link v-if="pagination.prev" :href="pagination.prev" preserve-scroll class="ih:font-medium ih:text-brand-text ih:hover:underline">← Zurück</Link><span v-else />
<span class="ih:text-muted-foreground">Seite {{ pagination.current }} von {{ pagination.last }}</span>
<Link v-if="pagination.next" :href="pagination.next" preserve-scroll class="ih:font-medium ih:text-brand-text ih:hover:underline">Weiter →</Link><span v-else />
</nav>
</section>
</div>
</AppLayout>
</template>