inhaus-plugin-kleinanzeigen/resources/js/pages/Index.vue
Friederich Loheide f05c44733f Kleinanzeigen-Plugin 1.0.0
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 17:06:02 +00:00

104 lines
7.8 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, usePage } from '@inertiajs/vue3';
import { Heart, ListChecks, Plus, Search, ShieldCheck, ShoppingBag } from '@lucide/vue';
import { AppLayout, Button, EmptyState, PageHeader, toast } 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 query = ref(props.filters.q);
let timer;
watch(query, (value) => {
clearTimeout(timer);
timer = setTimeout(() => apply({ q: value }), 350);
});
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">
<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="Suchen" aria-label="Anzeigen durchsuchen" class="ih:h-10 ih:w-full ih:rounded-md ih:border ih:border-input ih:bg-card ih:pr-3 ih:pl-8 ih:text-sm ih:shadow-xs ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none" />
</div>
<nav aria-label="Art" class="ih:flex ih:flex-wrap ih:gap-1.5">
<button type="button" class="ih:rounded-full ih:border ih:px-3 ih:py-1 ih:text-[13px]" :class="!filters.typ ? 'ih:border-brand ih:bg-brand ih:text-brand-foreground' : 'ih:bg-card ih:hover:bg-accent'" :aria-pressed="!filters.typ" @click="apply({ typ: null })">Alle</button>
<button v-for="(label, key) in types" :key="key" type="button" class="ih:rounded-full ih:border ih:px-3 ih:py-1 ih:text-[13px]" :class="filters.typ === key ? 'ih:border-brand ih:bg-brand ih:text-brand-foreground' : 'ih:bg-card ih:hover:bg-accent'" :aria-pressed="filters.typ === key" @click="apply({ typ: key })">{{ label }}</button>
</nav>
<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">
<div class="ih:mb-4 ih:flex ih:flex-wrap ih:items-center ih:gap-3">
<p class="ih:flex-1 ih:text-sm ih:text-muted-foreground">{{ pagination.total }} {{ pagination.total === 1 ? 'Anzeige' : 'Anzeigen' }}</p>
<button type="button" class="ih:inline-flex ih:items-center ih:gap-1.5 ih:rounded-md ih:border ih:px-3 ih:py-1.5 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>
<select class="ih:h-9 ih:rounded-md ih:border ih:bg-card ih:px-2 ih:text-sm" aria-label="Sortierung" :value="filters.sortierung" @change="apply({ sortierung: $event.target.value })">
<option v-for="(label, key) in sorts" :key="key" :value="key">{{ label }}</option>
</select>
</div>
<div v-if="listings.length" 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>
<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>