151 lines
11 KiB
Vue
151 lines
11 KiB
Vue
<script setup>
|
||
import { computed, ref, watch } from 'vue';
|
||
import { Link, router, useForm, usePage } from '@inertiajs/vue3';
|
||
import { CalendarDays, ChevronLeft, ChevronRight, Flag, Heart, ImageOff, LoaderCircle, Mail, MapPin, MessageCircle, PencilLine, Phone, ShieldCheck, Trash2 } from '@lucide/vue';
|
||
import { AppLayout, Button, PageHeader, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, PersonAvatar, Textarea, formatDate, toast } from '@inhaus/ui';
|
||
import ListingCard from '../components/ListingCard.vue';
|
||
|
||
const props = defineProps({
|
||
listing: { type: Object, required: true },
|
||
more: { type: Array, default: () => [] },
|
||
});
|
||
|
||
const page = usePage();
|
||
watch(() => page.props.flash?.status, (status) => status && toast.success(status), { immediate: true });
|
||
|
||
const l = computed(() => props.listing);
|
||
const current = ref(0);
|
||
const photo = computed(() => l.value.photos[current.value]);
|
||
const step = (delta) => (current.value = (current.value + delta + l.value.photos.length) % l.value.photos.length);
|
||
|
||
// Kontakt
|
||
const contact = useForm({ message: `Hallo ${l.value.seller?.name?.split(' ')[0] ?? ''}, ist „${l.value.title}“ noch zu haben?` });
|
||
const send = () => contact.post(`/kleinanzeigen/${l.value.id}/kontakt`, { preserveScroll: true, onSuccess: () => contact.reset() });
|
||
|
||
// Melden
|
||
const reporting = ref(false);
|
||
const report = useForm({ reason: '' });
|
||
const sendReport = () => report.post(`/kleinanzeigen/${l.value.id}/melden`, { preserveScroll: true, onSuccess: () => { reporting.value = false; report.reset(); } });
|
||
|
||
function toggleFavorite() {
|
||
router.visit(`/kleinanzeigen/${l.value.id}/merken`, { method: l.value.favorite ? 'delete' : 'post', preserveScroll: true });
|
||
}
|
||
|
||
function remove() {
|
||
window.confirm('Anzeige löschen?') && router.delete(`/kleinanzeigen/${l.value.id}`);
|
||
}
|
||
|
||
const statusNote = computed(() => ({
|
||
pending: 'Diese Anzeige wartet auf Freigabe und ist noch nicht öffentlich.',
|
||
rejected: 'Diese Anzeige wurde nicht freigegeben.',
|
||
done: 'Diese Anzeige ist erledigt.',
|
||
expired: 'Diese Anzeige ist abgelaufen.',
|
||
})[l.value.status]);
|
||
</script>
|
||
|
||
<template>
|
||
<AppLayout :title="l.title">
|
||
<PageHeader :title="l.title" :breadcrumbs="[{ label: 'Kleinanzeigen', href: '/kleinanzeigen' }]">
|
||
<template #description>
|
||
<span class="ih:flex ih:flex-wrap ih:items-center ih:gap-2 ih:text-xs">
|
||
<span class="ih:rounded ih:bg-brand-soft ih:px-2 ih:py-0.5 ih:font-semibold ih:text-brand-text">{{ l.type_label }}</span>
|
||
<span>{{ l.category_label }}</span>
|
||
<span v-if="l.reserved" class="ih:rounded ih:bg-foreground ih:px-2 ih:py-0.5 ih:font-semibold ih:text-background">Reserviert</span>
|
||
<span v-if="l.price" class="ih:text-base ih:font-semibold ih:text-brand-text">{{ l.price }}</span>
|
||
</span>
|
||
</template>
|
||
<template v-if="l.own || l.can_moderate" #actions>
|
||
<Button v-if="l.own" variant="outline" size="sm" as-child><Link :href="`/kleinanzeigen/${l.id}/bearbeiten`"><PencilLine /> Bearbeiten</Link></Button>
|
||
<Button variant="ghost" size="sm" class="ih:text-destructive ih:hover:text-destructive" @click="remove"><Trash2 /> Löschen</Button>
|
||
</template>
|
||
</PageHeader>
|
||
|
||
<p v-if="statusNote" class="ih:mb-4 ih:rounded-md ih:border ih:bg-muted ih:px-4 ih:py-3 ih:text-sm">
|
||
{{ statusNote }}<template v-if="l.review_note"> Hinweis: {{ l.review_note }}</template>
|
||
</p>
|
||
|
||
<div class="ih:grid ih:gap-6 ih:lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||
<div class="ih:grid ih:min-w-0 ih:content-start ih:gap-6">
|
||
<!-- Galerie -->
|
||
<section class="ih:overflow-hidden ih:rounded-xl ih:border ih:bg-card" aria-label="Fotos">
|
||
<div class="ih:relative ih:flex ih:aspect-[4/3] ih:items-center ih:justify-center ih:bg-muted ih:sm:aspect-[16/10]">
|
||
<img v-if="photo" :src="photo.url" :alt="`${l.title} – Foto ${current + 1}`" class="ih:max-h-full ih:max-w-full ih:object-contain" />
|
||
<ImageOff v-else class="ih:size-10 ih:text-muted-foreground" :stroke-width="1.5" />
|
||
<template v-if="l.photos.length > 1">
|
||
<button type="button" class="ih:absolute ih:left-3 ih:grid ih:size-10 ih:place-items-center ih:rounded-full ih:bg-card/90 ih:shadow" aria-label="Vorheriges Foto" @click="step(-1)"><ChevronLeft class="ih:size-5" /></button>
|
||
<button type="button" class="ih:absolute ih:right-3 ih:grid ih:size-10 ih:place-items-center ih:rounded-full ih:bg-card/90 ih:shadow" aria-label="Nächstes Foto" @click="step(1)"><ChevronRight class="ih:size-5" /></button>
|
||
<span class="ih:absolute ih:right-3 ih:bottom-3 ih:rounded ih:bg-foreground/70 ih:px-2 ih:py-0.5 ih:text-xs ih:text-background ih:tabular-nums">{{ current + 1 }} / {{ l.photos.length }}</span>
|
||
</template>
|
||
</div>
|
||
<div v-if="l.photos.length > 1" class="ih:flex ih:gap-2 ih:overflow-x-auto ih:p-3">
|
||
<button v-for="(p, i) in l.photos" :key="p.id" type="button" class="ih:size-16 ih:shrink-0 ih:overflow-hidden ih:rounded-md ih:border-2" :class="i === current ? 'ih:border-brand' : 'ih:border-transparent ih:opacity-70 ih:hover:opacity-100'" :aria-label="`Foto ${i + 1}`" :aria-current="i === current" @click="current = i">
|
||
<img :src="p.thumb_url" alt="" class="ih:size-full ih:object-cover" />
|
||
</button>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="ih:rounded-xl ih:border ih:bg-card ih:p-5 ih:sm:p-6">
|
||
<dl class="ih:flex ih:flex-wrap ih:gap-x-6 ih:gap-y-2 ih:text-sm ih:text-muted-foreground">
|
||
<div v-if="l.location" class="ih:flex ih:items-center ih:gap-1.5"><dt class="ih:sr-only">Ort</dt><MapPin class="ih:size-4" aria-hidden="true" /><dd>{{ l.location }}</dd></div>
|
||
<div v-if="l.published_at" class="ih:flex ih:items-center ih:gap-1.5"><dt class="ih:sr-only">Eingestellt</dt><CalendarDays class="ih:size-4" aria-hidden="true" /><dd>seit {{ formatDate(l.published_at) }}</dd></div>
|
||
</dl>
|
||
<h2 class="ih:mt-6 ih:mb-2 ih:text-sm ih:font-semibold">Beschreibung</h2>
|
||
<p class="ih:text-[15px] ih:leading-relaxed ih:whitespace-pre-line">{{ l.description }}</p>
|
||
</section>
|
||
</div>
|
||
|
||
<aside class="ih:grid ih:content-start ih:gap-4">
|
||
<section v-if="l.seller" class="ih:rounded-xl ih:border ih:bg-card ih:p-5">
|
||
<Link :href="`/personen/${l.seller.id}`" class="ih:flex ih:items-center ih:gap-3 ih:rounded-md ih:hover:bg-accent/50">
|
||
<PersonAvatar :person="l.seller" class="ih:size-12" />
|
||
<span class="ih:min-w-0">
|
||
<span class="ih:block ih:font-semibold">{{ l.seller.name }}</span>
|
||
<span class="ih:block ih:truncate ih:text-[13px] ih:text-muted-foreground">{{ [l.seller.department, l.seller.location].filter(Boolean).join(' · ') }}</span>
|
||
</span>
|
||
</Link>
|
||
<p v-if="l.seller.listings > 1" class="ih:mt-2 ih:text-xs ih:text-muted-foreground">{{ l.seller.listings }} Anzeigen online</p>
|
||
|
||
<form v-if="l.contact" class="ih:mt-4 ih:grid ih:gap-2 ih:border-t ih:pt-4" @submit.prevent="send">
|
||
<label for="kontakt" class="ih:text-sm ih:font-medium">Nachricht an {{ l.seller.name.split(' ')[0] }}</label>
|
||
<Textarea id="kontakt" v-model="contact.message" rows="4" maxlength="2000" />
|
||
<p v-if="contact.errors.message" class="ih:text-[13px] ih:text-destructive">{{ contact.errors.message }}</p>
|
||
<Button type="submit" :disabled="contact.processing || !contact.message.trim()">
|
||
<LoaderCircle v-if="contact.processing" class="ih:animate-spin" />
|
||
<component :is="l.contact === 'chat' ? MessageCircle : Mail" v-else />
|
||
{{ l.contact === 'chat' ? 'Im Chat schreiben' : 'Per E-Mail schreiben' }}
|
||
</Button>
|
||
<p class="ih:text-xs ih:text-muted-foreground">{{ l.contact === 'chat' ? 'Öffnet ein Gespräch unter „Nachrichten“.' : 'Die Antwort kommt per E-Mail; die Adresse der anbietenden Person bleibt verborgen.' }}</p>
|
||
</form>
|
||
<a v-if="l.phone" :href="`tel:${l.phone.replace(/[^0-9+]/g, '')}`" class="ih:mt-3 ih:flex ih:items-center ih:gap-2 ih:text-sm ih:font-medium ih:text-brand-text ih:hover:underline"><Phone class="ih:size-4" /> {{ l.phone }}</a>
|
||
</section>
|
||
|
||
<div v-if="!l.own" class="ih:flex ih:gap-2">
|
||
<Button variant="outline" class="ih:flex-1" :aria-pressed="l.favorite" @click="toggleFavorite"><Heart :class="l.favorite ? 'ih:fill-current ih:text-brand-text' : ''" /> {{ l.favorite ? 'Gemerkt' : 'Merken' }}</Button>
|
||
<Button variant="ghost" class="ih:text-muted-foreground" @click="reporting = true"><Flag /> Melden</Button>
|
||
</div>
|
||
<p v-if="l.can_moderate && l.status === 'pending'" class="ih:flex ih:items-center ih:gap-2 ih:text-sm"><ShieldCheck class="ih:size-4 ih:text-brand-text" /> <Link href="/kleinanzeigen/moderation" class="ih:font-medium ih:text-brand-text ih:hover:underline">Zur Freigabe</Link></p>
|
||
</aside>
|
||
</div>
|
||
|
||
<section v-if="more.length" class="ih:mt-10">
|
||
<h2 class="ih:mb-4 ih:text-lg ih:font-semibold">Das könnte Sie auch interessieren</h2>
|
||
<div class="ih:grid ih:grid-cols-2 ih:gap-3 ih:md:grid-cols-4">
|
||
<ListingCard v-for="item in more" :key="item.id" :listing="item" />
|
||
</div>
|
||
</section>
|
||
|
||
<Dialog v-model:open="reporting">
|
||
<DialogContent class="ih:sm:max-w-md">
|
||
<DialogHeader>
|
||
<DialogTitle>Anzeige melden</DialogTitle>
|
||
<DialogDescription>Was stimmt nicht? Die Moderation sieht sich die Anzeige an.</DialogDescription>
|
||
</DialogHeader>
|
||
<Textarea v-model="report.reason" rows="3" maxlength="500" placeholder="z. B. unpassend, doppelt, kein Mitarbeiterangebot …" aria-label="Grund" />
|
||
<DialogFooter>
|
||
<Button variant="ghost" @click="reporting = false">Abbrechen</Button>
|
||
<Button :disabled="report.processing || !report.reason.trim()" @click="sendReport">Melden</Button>
|
||
</DialogFooter>
|
||
</DialogContent>
|
||
</Dialog>
|
||
</AppLayout>
|
||
</template>
|