Gruppen-Plugin 1.0.0

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 17:17:10 +00:00
commit 5bdfb8a082
49 changed files with 4679 additions and 0 deletions

View file

@ -0,0 +1,103 @@
<script setup>
import { ref } from 'vue';
import { CornerDownRight, LoaderCircle, SendHorizontal, Trash2 } from '@lucide/vue';
import { PersonAvatar, formatRelative, http, toast } from '@inhaus/ui';
import RichText from './RichText.vue';
/** Kommentare unter einem Beitrag – mit Antworten (eine Ebene) */
const props = defineProps({
post: { type: Object, required: true },
full: { type: Boolean, default: false },
initial: { type: Array, default: null },
});
const comments = ref(props.initial ?? props.post.comments);
const loadedAll = ref(props.full);
const body = ref('');
const replyTo = ref(null);
const replyBody = ref('');
const busy = ref(false);
async function loadAll() {
comments.value = (await http.get(`/gruppen/beitraege/${props.post.id}/kommentare`)).comments;
loadedAll.value = true;
}
async function send(text, parentId = null) {
if (!text.trim()) return;
busy.value = true;
try {
const data = await http.post(`/gruppen/beitraege/${props.post.id}/kommentare`, { body: text, parent_id: parentId });
comments.value = data.comments;
loadedAll.value = true;
props.post.comments_count = data.comments.reduce((n, c) => n + 1 + c.replies.length, 0);
body.value = replyBody.value = '';
replyTo.value = null;
} catch (error) {
toast.error(error.message);
} finally {
busy.value = false;
}
}
async function remove(comment) {
if (!window.confirm('Kommentar löschen?')) return;
await http.delete(`/gruppen/kommentare/${comment.id}`);
await loadAll();
props.post.comments_count = comments.value.reduce((n, c) => n + 1 + c.replies.length, 0);
}
</script>
<template>
<div class="ih:grid ih:gap-3 ih:border-t ih:px-4 ih:pt-3 ih:pb-4 ih:sm:px-5">
<button v-if="!loadedAll && post.comments_count > comments.length" type="button" class="ih:justify-self-start ih:text-[13px] ih:font-medium ih:text-muted-foreground ih:hover:text-foreground ih:hover:underline" @click="loadAll">
Alle {{ post.comments_count }} Kommentare anzeigen
</button>
<div v-for="c in comments" :id="`kommentar-${c.id}`" :key="c.id" class="ih:grid ih:gap-2">
<div class="ih:flex ih:gap-2.5">
<PersonAvatar v-if="c.user" :person="c.user" class="ih:size-8 ih:text-[11px]" />
<div class="ih:min-w-0 ih:flex-1">
<div class="ih:inline-block ih:max-w-full ih:rounded-2xl ih:bg-muted ih:px-3 ih:py-2 ih:text-sm">
<a v-if="c.user" :href="`/personen/${c.user.id}`" class="ih:font-semibold ih:hover:underline">{{ c.user.name }}</a>
<RichText :text="c.body" :limit="400" />
</div>
<div class="ih:mt-0.5 ih:flex ih:gap-3 ih:px-3 ih:text-xs ih:text-muted-foreground">
<span>{{ formatRelative(c.created_at) }}</span>
<button v-if="post.can_comment" type="button" class="ih:font-medium ih:hover:text-foreground" @click="replyTo = replyTo === c.id ? null : c.id">Antworten</button>
<button v-if="c.can_delete" type="button" class="ih:hover:text-destructive" :aria-label="`Kommentar von ${c.user?.name} löschen`" @click="remove(c)"><Trash2 class="ih:size-3.5" /></button>
</div>
</div>
</div>
<div v-for="r in c.replies" :id="`kommentar-${r.id}`" :key="r.id" class="ih:ml-10 ih:flex ih:gap-2.5">
<PersonAvatar v-if="r.user" :person="r.user" class="ih:size-7 ih:text-[10px]" />
<div class="ih:min-w-0 ih:flex-1">
<div class="ih:inline-block ih:max-w-full ih:rounded-2xl ih:bg-muted ih:px-3 ih:py-2 ih:text-sm">
<a v-if="r.user" :href="`/personen/${r.user.id}`" class="ih:font-semibold ih:hover:underline">{{ r.user.name }}</a>
<RichText :text="r.body" :limit="400" />
</div>
<div class="ih:mt-0.5 ih:flex ih:gap-3 ih:px-3 ih:text-xs ih:text-muted-foreground">
<span>{{ formatRelative(r.created_at) }}</span>
<button v-if="r.can_delete" type="button" class="ih:hover:text-destructive" aria-label="Antwort löschen" @click="remove(r)"><Trash2 class="ih:size-3.5" /></button>
</div>
</div>
</div>
<form v-if="replyTo === c.id" class="ih:ml-10 ih:flex ih:items-center ih:gap-2" @submit.prevent="send(replyBody, c.id)">
<CornerDownRight class="ih:size-4 ih:shrink-0 ih:text-muted-foreground" />
<input v-model="replyBody" maxlength="3000" :placeholder="`Antwort an ${c.user?.name ?? ''}`" aria-label="Antwort" autofocus class="ih:h-9 ih:min-w-0 ih:flex-1 ih:rounded-full ih:border ih:border-input ih:bg-background ih:px-4 ih:text-sm ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none" />
</form>
</div>
<form v-if="post.can_comment" class="ih:flex ih:items-center ih:gap-2" @submit.prevent="send(body)">
<input v-model="body" maxlength="3000" placeholder="Kommentieren …" aria-label="Kommentar" class="ih:h-9 ih:min-w-0 ih:flex-1 ih:rounded-full ih:border ih:border-input ih:bg-background ih:px-4 ih:text-sm ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none" />
<button type="submit" class="ih:grid ih:size-9 ih:shrink-0 ih:place-items-center ih:rounded-full ih:text-brand-text ih:hover:bg-brand-soft ih:disabled:opacity-40" :disabled="busy || !body.trim()" aria-label="Kommentar senden">
<LoaderCircle v-if="busy" class="ih:size-4 ih:animate-spin" /><SendHorizontal v-else class="ih:size-4" />
</button>
</form>
</div>
</template>

View file

@ -0,0 +1,27 @@
<script setup>
import { Link, router } from '@inertiajs/vue3';
import { Globe, Lock, EyeOff, Users } from '@lucide/vue';
import { Button } from '@inhaus/ui';
const props = defineProps({ group: { type: Object, required: true } });
const icons = { open: Globe, closed: Lock, secret: EyeOff };
const join = () => router.post(`/gruppen/${props.group.slug}/beitreten`, {}, { preserveScroll: true });
</script>
<template>
<article class="ih:flex ih:flex-col ih:overflow-hidden ih:rounded-xl ih:border ih:bg-card ih:shadow-xs">
<Link :href="group.url" class="ih:block ih:h-24 ih:bg-brand ih:bg-cover ih:bg-center" :style="group.cover_url ? { backgroundImage: `url(${group.cover_url})` } : {}" :aria-label="group.name" />
<div class="ih:flex ih:flex-1 ih:flex-col ih:gap-1 ih:p-4">
<Link :href="group.url" class="ih:font-semibold ih:hover:underline">{{ group.name }}</Link>
<p class="ih:flex ih:items-center ih:gap-1.5 ih:text-xs ih:text-muted-foreground">
<component :is="icons[group.privacy]" class="ih:size-3.5" /> {{ group.privacy_label }} · <Users class="ih:size-3.5" /> {{ group.members_count }}
</p>
<p v-if="group.description" class="ih:line-clamp-2 ih:text-sm ih:text-muted-foreground">{{ group.description }}</p>
<div class="ih:mt-auto ih:pt-3">
<Button v-if="group.status === 'active'" variant="outline" size="sm" class="ih:w-full" as-child><Link :href="group.url">Ansehen</Link></Button>
<Button v-else-if="group.status === 'pending'" variant="outline" size="sm" class="ih:w-full" disabled>Angefragt</Button>
<Button v-else size="sm" class="ih:w-full" @click="join">{{ group.status === 'invited' ? 'Einladung annehmen' : group.privacy === 'open' ? 'Beitreten' : 'Beitritt anfragen' }}</Button>
</div>
</div>
</article>
</template>

View file

@ -0,0 +1,60 @@
<script setup>
import { watch } from 'vue';
import { useForm } from '@inertiajs/vue3';
import { LoaderCircle } from '@lucide/vue';
import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, FormField, Input, Textarea } from '@inhaus/ui';
/** Gruppe gründen bzw. bearbeiten */
const props = defineProps({
group: { type: Object, default: null },
privacy: { type: Object, required: true },
privacyHints: { type: Object, required: true },
});
const open = defineModel('open', { type: Boolean, default: false });
const form = useForm({ name: '', description: '', privacy: 'open', cover: null, remove_cover: false });
watch(open, (value) => {
if (!value) return;
form.clearErrors();
form.defaults({ name: props.group?.name ?? '', description: props.group?.description ?? '', privacy: props.group?.privacy ?? 'open', cover: null, remove_cover: false });
form.reset();
});
function submit() {
form.post(props.group ? `/gruppen/${props.group.slug}` : '/gruppen', { forceFormData: true, preserveScroll: true, onSuccess: () => (open.value = false) });
}
</script>
<template>
<Dialog v-model:open="open">
<DialogContent class="ih:sm:max-w-lg">
<DialogHeader>
<DialogTitle>{{ group ? 'Gruppe bearbeiten' : 'Gruppe gründen' }}</DialogTitle>
<DialogDescription>{{ group ? 'Name, Beschreibung, Art und Titelbild.' : 'Zu einem Thema, einem Hobby oder einem Projekt – Sie verwalten die Gruppe.' }}</DialogDescription>
</DialogHeader>
<form id="group-form" class="ih:grid ih:gap-4" @submit.prevent="submit">
<FormField id="g-name" label="Name" :error="form.errors.name">
<Input id="g-name" v-model="form.name" maxlength="100" placeholder="z. B. Laufgruppe Mainz" />
</FormField>
<FormField id="g-description" label="Worum geht es? (optional)" :error="form.errors.description">
<Textarea id="g-description" v-model="form.description" rows="3" maxlength="2000" />
</FormField>
<fieldset class="ih:grid ih:gap-2">
<legend class="ih:mb-1 ih:text-sm ih:font-medium">Wer darf rein?</legend>
<label v-for="(label, key) in privacy" :key="key" class="ih:flex ih:cursor-pointer ih:items-start ih:gap-3 ih:rounded-md ih:border ih:p-3 ih:text-sm ih:has-[:checked]:border-brand ih:has-[:checked]:bg-brand-soft/50">
<input v-model="form.privacy" type="radio" name="privacy" :value="key" class="ih:mt-0.5 ih:size-4 ih:accent-[var(--color-brand)]" />
<span><span class="ih:font-medium">{{ label }}</span><span class="ih:block ih:text-xs ih:text-muted-foreground">{{ privacyHints[key] }}</span></span>
</label>
</fieldset>
<FormField id="g-cover" label="Titelbild (optional)" :error="form.errors.cover">
<input id="g-cover" type="file" accept="image/jpeg,image/png,image/webp" class="ih:text-sm" @change="form.cover = $event.target.files[0] ?? null" />
</FormField>
<label v-if="group?.cover_url" class="ih:flex ih:items-center ih:gap-2 ih:text-sm"><input v-model="form.remove_cover" type="checkbox" /> Titelbild entfernen</label>
</form>
<DialogFooter>
<Button variant="ghost" @click="open = false">Abbrechen</Button>
<Button type="submit" form="group-form" :disabled="form.processing || !form.name.trim()"><LoaderCircle v-if="form.processing" class="ih:animate-spin" /> {{ group ? 'Speichern' : 'Gründen' }}</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</template>

View file

@ -0,0 +1,98 @@
<script setup>
import { ref, watch } from 'vue';
import { Search, X } from '@lucide/vue';
import { PersonAvatar } from '@inhaus/ui';
import { http } from '@inhaus/ui';
/**
* Personen suchen und auswählen – einzeln (Direktnachricht) oder mehrere (Gruppe).
* v-model: Liste der Personen [{ id, name, … }]
*/
const props = defineProps({
multiple: { type: Boolean, default: false },
exclude: { type: Array, default: () => [] },
placeholder: { type: String, default: 'Name oder E-Mail eingeben …' },
autofocus: { type: Boolean, default: false },
});
const emit = defineEmits(['pick']);
const selected = defineModel({ type: Array, default: () => [] });
const query = ref('');
const results = ref([]);
const active = ref(0);
const loading = ref(false);
let timer;
watch(query, (value) => {
clearTimeout(timer);
if (value.trim().length < 2) {
results.value = [];
return;
}
timer = setTimeout(async () => {
loading.value = true;
try {
const ids = [...props.exclude, ...selected.value.map((p) => p.id)];
results.value = (await http.get(`/personen/suche?q=${encodeURIComponent(value.trim())}`)).people.filter((p) => !ids.includes(p.id));
active.value = 0;
} finally {
loading.value = false;
}
}, 200);
});
function choose(person) {
if (!person) return;
emit('pick', person);
if (props.multiple) selected.value = [...selected.value, person];
query.value = '';
results.value = [];
}
const remove = (person) => (selected.value = selected.value.filter((p) => p.id !== person.id));
</script>
<template>
<div class="ih:grid ih:gap-2">
<div v-if="multiple && selected.length" class="ih:flex ih:flex-wrap ih:gap-1.5">
<span v-for="person in selected" :key="person.id" class="ih:inline-flex ih:items-center ih:gap-1.5 ih:rounded-full ih:border ih:bg-card ih:py-0.5 ih:pr-1 ih:pl-0.5 ih:text-[13px]">
<PersonAvatar :person="person" class="ih:size-6 ih:text-[10px]" />
{{ person.name }}
<button type="button" class="ih:rounded-full ih:p-0.5 ih:text-muted-foreground ih:hover:bg-muted ih:hover:text-foreground" :aria-label="`${person.name} entfernen`" @click="remove(person)"><X class="ih:size-3.5" /></button>
</span>
</div>
<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"
autocomplete="off"
:autofocus="autofocus"
:placeholder="placeholder"
aria-label="Person suchen"
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"
@keydown.down.prevent="active = Math.min(results.length - 1, active + 1)"
@keydown.up.prevent="active = Math.max(0, active - 1)"
@keydown.enter.prevent="choose(results[active])"
/>
</div>
<ul v-if="results.length" class="ih:max-h-64 ih:overflow-y-auto ih:rounded-md ih:border ih:bg-popover ih:p-1" role="listbox">
<li v-for="(person, i) in results" :key="person.id" role="option" :aria-selected="i === active">
<button type="button" class="ih:flex ih:w-full ih:items-center ih:gap-2.5 ih:rounded ih:px-2 ih:py-1.5 ih:text-left ih:text-sm" :class="i === active ? 'ih:bg-accent' : 'ih:hover:bg-accent/60'" @click="choose(person)" @mouseenter="active = i">
<PersonAvatar :person="person" class="ih:size-7 ih:text-[11px]" />
<span class="ih:min-w-0 ih:flex-1">
<span class="ih:block ih:truncate ih:font-medium">{{ person.name }}</span>
<span v-if="person.job_title || person.department" class="ih:block ih:truncate ih:text-xs ih:text-muted-foreground">{{ [person.job_title, person.department].filter(Boolean).join(' · ') }}</span>
</span>
</button>
</li>
</ul>
<p v-else-if="query.trim().length >= 2 && !loading" class="ih:px-1 ih:text-[13px] ih:text-muted-foreground">Niemand gefunden.</p>
</div>
</template>

View file

@ -0,0 +1,191 @@
<script setup>
import { computed, ref } from 'vue';
import { Download, Flag, MessageCircle, MoreHorizontal, Pencil, Pin, PinOff, Trash2 } from '@lucide/vue';
import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, FileIcon, PersonAvatar, formatRelative, http, toast } from '@inhaus/ui';
import Comments from './Comments.vue';
import RichText from './RichText.vue';
import { fileSize } from '../lib/format';
const props = defineProps({
post: { type: Object, required: true },
reactions: { type: Array, required: true },
showGroup: { type: Boolean, default: false },
fullComments: { type: Array, default: null },
});
const emit = defineEmits(['deleted', 'changed']);
const p = props.post;
const showComments = ref(!!props.fullComments || p.comments.length > 0);
const editing = ref(false);
const draft = ref(p.body ?? '');
// Reaktion: ein Klick = 👍, Auswahl beim Überfahren
async function react(emoji) {
const next = p.my_reaction === emoji ? null : emoji;
const old = p.my_reaction;
const bump = (e, d) => {
if (!e) return;
const r = p.reactions.find((x) => x.emoji === e);
r ? (r.count += d) : d > 0 && p.reactions.push({ emoji: e, count: 1 });
p.reactions = p.reactions.filter((x) => x.count > 0).sort((a, b) => b.count - a.count);
p.reactions_total += d;
};
bump(old, -1);
bump(next, 1);
p.my_reaction = next;
await http.post(`/gruppen/beitraege/${p.id}/reaktion`, { emoji: next }).catch((e) => toast.error(e.message));
}
// Umfrage
const selection = ref([...(p.poll?.mine ?? [])]);
const voted = computed(() => (p.poll?.mine ?? []).length > 0);
const totalVotes = computed(() => p.poll?.options.reduce((n, o) => n + o.votes, 0) ?? 0);
async function vote(options) {
try {
p.poll = (await http.post(`/gruppen/beitraege/${p.id}/abstimmen`, { options })).poll;
selection.value = [...p.poll.mine];
} catch (e) {
toast.error(e.message);
}
}
function choose(i) {
if (!p.can_comment) return;
if (p.poll.multiple) {
selection.value = selection.value.includes(i) ? selection.value.filter((x) => x !== i) : [...selection.value, i];
} else {
vote([i]);
}
}
async function pin() {
try {
await http.post(`/gruppen/beitraege/${p.id}/anpinnen`, { pinned: !p.pinned });
p.pinned = !p.pinned;
emit('changed');
} catch (e) {
toast.error(e.message);
}
}
async function remove() {
if (!window.confirm('Beitrag löschen?')) return;
await http.delete(`/gruppen/beitraege/${p.id}`);
emit('deleted', p);
}
async function saveEdit() {
await http.put(`/gruppen/beitraege/${p.id}`, { body: draft.value });
p.body = draft.value;
p.edited = true;
editing.value = false;
}
async function report() {
const reason = window.prompt('Was stimmt mit diesem Beitrag nicht?');
if (!reason?.trim()) return;
const data = await http.post(`/gruppen/beitraege/${p.id}/melden`, { reason });
toast.success(data.message);
}
const shownImages = computed(() => p.images.slice(0, 4));
</script>
<template>
<article class="ih:overflow-hidden ih:rounded-xl ih:border ih:bg-card ih:shadow-xs" :aria-label="`Beitrag von ${p.user?.name ?? 'Gelöschtes Konto'}`">
<header class="ih:flex ih:items-start ih:gap-3 ih:px-4 ih:pt-4 ih:sm:px-5">
<PersonAvatar v-if="p.user" :person="p.user" class="ih:size-10" />
<div class="ih:min-w-0 ih:flex-1 ih:text-sm">
<p class="ih:leading-snug">
<a v-if="p.user" :href="`/personen/${p.user.id}`" class="ih:font-semibold ih:hover:underline">{{ p.user.name }}</a>
<template v-if="showGroup"><span class="ih:mx-1 ih:text-muted-foreground">in</span><a :href="`/gruppen/${p.group.slug}`" class="ih:font-semibold ih:hover:underline">{{ p.group.name }}</a></template>
</p>
<p class="ih:flex ih:items-center ih:gap-1.5 ih:text-xs ih:text-muted-foreground">
<a :href="p.url" class="ih:hover:underline">{{ formatRelative(p.created_at) }}</a>
<template v-if="p.edited"> · bearbeitet</template>
<span v-if="p.pinned" class="ih:inline-flex ih:items-center ih:gap-0.5 ih:font-medium ih:text-brand-text"><Pin class="ih:size-3" /> Angepinnt</span>
</p>
</div>
<DropdownMenu>
<DropdownMenuTrigger as-child>
<button type="button" class="ih:grid ih:size-8 ih:place-items-center ih:rounded-full ih:text-muted-foreground ih:hover:bg-accent" aria-label="Weitere Aktionen"><MoreHorizontal class="ih:size-5" /></button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem v-if="p.can_pin" @select="pin"><component :is="p.pinned ? PinOff : Pin" /> {{ p.pinned ? 'Nicht mehr anpinnen' : 'Oben anpinnen' }}</DropdownMenuItem>
<DropdownMenuItem v-if="p.can_edit && p.body !== null" @select="editing = true; draft = p.body"><Pencil /> Bearbeiten</DropdownMenuItem>
<DropdownMenuItem v-if="p.can_delete" class="ih:text-destructive" @select="remove"><Trash2 /> Löschen</DropdownMenuItem>
<DropdownMenuItem v-if="!p.can_edit" @select="report"><Flag /> Melden</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</header>
<div class="ih:px-4 ih:pt-3 ih:text-[15px] ih:leading-relaxed ih:sm:px-5">
<form v-if="editing" class="ih:grid ih:gap-2" @submit.prevent="saveEdit">
<textarea v-model="draft" rows="4" maxlength="10000" aria-label="Beitrag bearbeiten" class="ih:w-full ih:rounded-md ih:border ih:border-input ih:bg-background ih:p-3 ih:text-sm" />
<div class="ih:flex ih:gap-2"><Button size="sm" type="submit">Speichern</Button><Button size="sm" variant="ghost" type="button" @click="editing = false">Abbrechen</Button></div>
</form>
<RichText v-else-if="p.body" :text="p.body" />
</div>
<!-- Fotos -->
<div v-if="p.images.length" class="ih:mt-3 ih:grid ih:gap-0.5" :class="p.images.length === 1 ? '' : 'ih:grid-cols-2'">
<a v-for="(img, i) in shownImages" :key="img.id" :href="img.url" target="_blank" rel="noopener" class="ih:relative ih:block ih:overflow-hidden ih:bg-muted" :class="p.images.length === 3 && i === 0 ? 'ih:row-span-2' : ''">
<img :src="p.images.length === 1 ? img.url : img.thumb_url" :alt="img.name" loading="lazy" class="ih:w-full ih:object-cover" :class="p.images.length === 1 ? 'ih:max-h-[32rem]' : 'ih:aspect-square ih:h-full'" />
<span v-if="i === 3 && p.images.length > 4" class="ih:absolute ih:inset-0 ih:grid ih:place-items-center ih:bg-foreground/55 ih:text-2xl ih:font-semibold ih:text-background">+{{ p.images.length - 4 }}</span>
</a>
</div>
<!-- Dateien -->
<div v-if="p.files.length" class="ih:grid ih:gap-2 ih:px-4 ih:pt-3 ih:sm:px-5">
<a v-for="f in p.files" :key="f.id" :href="f.url" class="ih:flex ih:items-center ih:gap-3 ih:rounded-lg ih:border ih:p-2.5 ih:hover:bg-accent/60">
<FileIcon :extension="f.name.split('.').pop()" class="ih:shrink-0" />
<span class="ih:min-w-0 ih:flex-1"><span class="ih:block ih:truncate ih:text-sm ih:font-medium">{{ f.name }}</span><span class="ih:text-xs ih:text-muted-foreground">{{ fileSize(f.size) }}</span></span>
<Download class="ih:size-4 ih:text-muted-foreground" />
</a>
</div>
<!-- Umfrage -->
<fieldset v-if="p.poll" class="ih:mx-4 ih:mt-3 ih:grid ih:gap-2 ih:rounded-lg ih:border ih:p-3 ih:sm:mx-5">
<legend class="ih:px-1 ih:text-xs ih:font-semibold ih:text-muted-foreground">Umfrage{{ p.poll.multiple ? ' · mehrere Antworten möglich' : '' }}</legend>
<button
v-for="(o, i) in p.poll.options"
:key="i"
type="button"
class="ih:relative ih:overflow-hidden ih:rounded-md ih:border ih:px-3 ih:py-2 ih:text-left ih:text-sm ih:disabled:cursor-default"
:class="(voted ? p.poll.mine : selection).includes(i) ? 'ih:border-brand' : 'ih:hover:border-brand/50'"
:aria-pressed="(voted ? p.poll.mine : selection).includes(i)"
:disabled="!p.can_comment"
@click="choose(i)"
>
<span v-if="voted" class="ih:absolute ih:inset-y-0 ih:left-0 ih:bg-brand-soft" :style="{ width: `${totalVotes ? Math.round((o.votes / totalVotes) * 100) : 0}%` }" aria-hidden="true" />
<span class="ih:relative ih:flex ih:justify-between ih:gap-3">
<span :class="{ 'ih:font-semibold': p.poll.mine.includes(i) }">{{ o.label }}</span>
<span v-if="voted" class="ih:text-muted-foreground ih:tabular-nums">{{ totalVotes ? Math.round((o.votes / totalVotes) * 100) : 0 }} % · {{ o.votes }}</span>
</span>
</button>
<div class="ih:flex ih:items-center ih:justify-between ih:text-xs ih:text-muted-foreground">
<span>{{ p.poll.voters }} {{ p.poll.voters === 1 ? 'Person hat' : 'Personen haben' }} abgestimmt</span>
<Button v-if="p.poll.multiple && p.can_comment" size="sm" variant="outline" :disabled="!selection.length && !voted" @click="vote(selection)">{{ voted ? 'Stimme ändern' : 'Abstimmen' }}</Button>
</div>
</fieldset>
<!-- Reaktionen und Kommentare -->
<div class="ih:mt-3 ih:flex ih:items-center ih:justify-between ih:px-4 ih:text-[13px] ih:text-muted-foreground ih:sm:px-5">
<span v-if="p.reactions_total" class="ih:inline-flex ih:items-center ih:gap-1"><span class="ih:tracking-tighter">{{ p.reactions.slice(0, 3).map((r) => r.emoji).join('') }}</span> {{ p.reactions_total }}</span><span v-else />
<button v-if="p.comments_count" type="button" class="ih:hover:underline" @click="showComments = !showComments">{{ p.comments_count }} {{ p.comments_count === 1 ? 'Kommentar' : 'Kommentare' }}</button>
</div>
<div v-if="p.can_comment" class="ih:mx-4 ih:mt-2 ih:grid ih:grid-cols-2 ih:border-t ih:py-1 ih:sm:mx-5">
<div class="ih:group/react ih:relative">
<button type="button" class="ih:flex ih:w-full ih:items-center ih:justify-center ih:gap-2 ih:rounded-md ih:py-2 ih:text-sm ih:font-medium ih:hover:bg-accent" :class="p.my_reaction ? 'ih:text-brand-text' : 'ih:text-muted-foreground'" :aria-pressed="!!p.my_reaction" @click="react(p.my_reaction ?? '👍')">
<span class="ih:text-base">{{ p.my_reaction ?? '👍' }}</span> {{ p.my_reaction ? 'Reagiert' : 'Gefällt mir' }}
</button>
<div class="ih:absolute ih:bottom-full ih:left-2 ih:z-20 ih:hidden ih:gap-0.5 ih:rounded-full ih:border ih:bg-popover ih:p-1 ih:shadow-md ih:group-focus-within/react:flex ih:group-hover/react:flex">
<button v-for="emoji in reactions" :key="emoji" type="button" class="ih:grid ih:size-9 ih:place-items-center ih:rounded-full ih:text-xl ih:transition-transform ih:hover:scale-125" :aria-label="`Mit ${emoji} reagieren`" @click="react(emoji)">{{ emoji }}</button>
</div>
</div>
<button type="button" class="ih:flex ih:items-center ih:justify-center ih:gap-2 ih:rounded-md ih:py-2 ih:text-sm ih:font-medium ih:text-muted-foreground ih:hover:bg-accent" @click="showComments = true"><MessageCircle class="ih:size-4" /> Kommentieren</button>
</div>
<div v-else class="ih:h-3" />
<Comments v-if="showComments" :post="p" :full="!!fullComments" :initial="fullComments" />
</article>
</template>

View file

@ -0,0 +1,112 @@
<script setup>
import { computed, ref } from 'vue';
import { BarChart3, File as FileGlyph, ImagePlus, LoaderCircle, Paperclip, Plus, X } from '@lucide/vue';
import { Button, PersonAvatar, Switch, http, toast } from '@inhaus/ui';
import { fileSize } from '../lib/format';
const props = defineProps({
group: { type: Object, required: true },
me: { type: Object, required: true },
});
const emit = defineEmits(['created']);
const body = ref('');
const files = ref([]);
const poll = ref(null); // Liste der Antworten oder null
const multiple = ref(false);
const busy = ref(false);
const photoInput = ref(null);
const fileInput = ref(null);
const focused = ref(false);
const canSend = computed(() => !busy.value && (body.value.trim() || files.value.length || (poll.value && poll.value.filter((o) => o.trim()).length >= 2)));
function add(list) {
for (const file of list) {
if (files.value.length >= 10) {
toast.error('Höchstens 10 Dateien je Beitrag.');
break;
}
files.value.push({ file, url: file.type.startsWith('image/') ? URL.createObjectURL(file) : null });
}
focused.value = true;
}
function removeFile(i) {
const [f] = files.value.splice(i, 1);
f?.url && URL.revokeObjectURL(f.url);
}
async function submit() {
busy.value = true;
const data = new FormData();
body.value.trim() && data.append('body', body.value);
files.value.forEach((f) => data.append('files[]', f.file));
if (poll.value) {
poll.value.filter((o) => o.trim()).forEach((o) => data.append('poll[]', o));
data.append('multiple', multiple.value ? '1' : '0');
}
try {
const { post } = await http.post(`/gruppen/${props.group.slug}/beitraege`, data);
emit('created', post);
files.value.forEach((f) => f.url && URL.revokeObjectURL(f.url));
body.value = '';
files.value = [];
poll.value = null;
focused.value = false;
} catch (error) {
toast.error(error.message);
} finally {
busy.value = false;
}
}
</script>
<template>
<section class="ih:rounded-xl ih:border ih:bg-card ih:p-4 ih:shadow-xs" aria-label="Neuer Beitrag" @dragover.prevent @drop.prevent="add([...$event.dataTransfer.files])">
<div class="ih:flex ih:gap-3">
<PersonAvatar :person="me" class="ih:size-10" />
<textarea
v-model="body"
:rows="focused || body ? 4 : 1"
maxlength="10000"
:placeholder="`Was möchten Sie mit „${group.name}“ teilen?`"
aria-label="Beitrag schreiben"
class="ih:min-h-10 ih:flex-1 ih:resize-none ih:rounded-2xl ih:bg-muted ih:px-4 ih:py-2 ih:text-[15px] ih:focus-visible:bg-background ih:focus-visible:ring-3 ih:focus-visible:ring-ring/30 ih:focus-visible:outline-none"
@focus="focused = true"
@paste="$event.clipboardData?.files?.length && ($event.preventDefault(), add([...$event.clipboardData.files]))"
/>
</div>
<ul v-if="files.length" class="ih:mt-3 ih:flex ih:flex-wrap ih:gap-2 ih:pl-13">
<li v-for="(f, i) in files" :key="i" class="ih:relative">
<img v-if="f.url" :src="f.url" :alt="f.file.name" class="ih:size-20 ih:rounded-md ih:border ih:object-cover" />
<span v-else class="ih:flex ih:h-20 ih:w-40 ih:items-center ih:gap-2 ih:rounded-md ih:border ih:bg-muted ih:px-2 ih:text-xs"><FileGlyph class="ih:size-5 ih:shrink-0" /><span class="ih:min-w-0"><span class="ih:block ih:truncate ih:font-medium">{{ f.file.name }}</span>{{ fileSize(f.file.size) }}</span></span>
<button type="button" class="ih:absolute ih:-top-1.5 ih:-right-1.5 ih:grid ih:size-5 ih:place-items-center ih:rounded-full ih:bg-foreground ih:text-background" :aria-label="`${f.file.name} entfernen`" @click="removeFile(i)"><X class="ih:size-3" /></button>
</li>
</ul>
<div v-if="poll" class="ih:mt-3 ih:grid ih:gap-2 ih:rounded-lg ih:border ih:p-3 ih:sm:ml-13">
<div class="ih:flex ih:items-center ih:justify-between">
<span class="ih:text-sm ih:font-medium">Umfrage</span>
<button type="button" class="ih:text-xs ih:text-muted-foreground ih:hover:text-foreground" @click="poll = null">Entfernen</button>
</div>
<input v-for="(o, i) in poll" :key="i" v-model="poll[i]" maxlength="120" :placeholder="`Antwort ${i + 1}`" :aria-label="`Antwort ${i + 1}`" class="ih:h-9 ih:rounded-md ih:border ih:border-input ih:bg-background ih:px-3 ih:text-sm" />
<div class="ih:flex ih:flex-wrap ih:items-center ih:justify-between ih:gap-2">
<button v-if="poll.length < 10" type="button" class="ih:inline-flex ih:items-center ih:gap-1 ih:text-sm ih:text-brand-text ih:hover:underline" @click="poll.push('')"><Plus class="ih:size-4" /> Antwort</button>
<label class="ih:flex ih:items-center ih:gap-2 ih:text-sm"><Switch v-model="multiple" /> Mehrere Antworten erlauben</label>
</div>
</div>
<div v-if="focused || body || files.length || poll" class="ih:mt-3 ih:flex ih:flex-wrap ih:items-center ih:gap-1 ih:border-t ih:pt-3">
<button type="button" class="ih:inline-flex ih:items-center ih:gap-1.5 ih:rounded-md ih:px-2.5 ih:py-1.5 ih:text-sm ih:text-muted-foreground ih:hover:bg-accent" @click="photoInput?.click()"><ImagePlus class="ih:size-4" /> Foto</button>
<button type="button" class="ih:inline-flex ih:items-center ih:gap-1.5 ih:rounded-md ih:px-2.5 ih:py-1.5 ih:text-sm ih:text-muted-foreground ih:hover:bg-accent" @click="fileInput?.click()"><Paperclip class="ih:size-4" /> Datei</button>
<button v-if="!poll" type="button" class="ih:inline-flex ih:items-center ih:gap-1.5 ih:rounded-md ih:px-2.5 ih:py-1.5 ih:text-sm ih:text-muted-foreground ih:hover:bg-accent" @click="poll = ['', '']"><BarChart3 class="ih:size-4" /> Umfrage</button>
<span class="ih:flex-1" />
<Button :disabled="!canSend" @click="submit"><LoaderCircle v-if="busy" class="ih:animate-spin" /> Veröffentlichen</Button>
<input ref="photoInput" type="file" accept="image/*" multiple class="ih:hidden" @change="add([...$event.target.files]); $event.target.value = ''" />
<input ref="fileInput" type="file" multiple class="ih:hidden" @change="add([...$event.target.files]); $event.target.value = ''" />
</div>
</section>
</template>

View file

@ -0,0 +1,23 @@
<script setup>
import { computed, ref } from 'vue';
import { linkify } from '../lib/format';
/** Text mit Links; lange Texte werden gekürzt („Mehr anzeigen“) */
const props = defineProps({
text: { type: String, default: '' },
limit: { type: Number, default: 600 },
});
const expanded = ref(false);
const long = computed(() => props.text.length > props.limit);
const shown = computed(() => (long.value && !expanded.value ? `${props.text.slice(0, props.limit).trimEnd()} …` : props.text));
</script>
<template>
<p class="ih:break-words ih:whitespace-pre-wrap">
<template v-for="(part, i) in linkify(shown)" :key="i">
<a v-if="part.href" :href="part.href" target="_blank" rel="noopener noreferrer" class="ih:text-brand-text ih:underline ih:underline-offset-2">{{ part.text }}</a>
<template v-else>{{ part.text }}</template>
</template>
<button v-if="long" type="button" class="ih:ml-1 ih:font-medium ih:text-brand-text ih:hover:underline" @click="expanded = !expanded">{{ expanded ? 'Weniger' : 'Mehr anzeigen' }}</button>
</p>
</template>