inhaus-plugin-gruppen/resources/js/pages/Index.vue
Friederich Loheide 5bdfb8a082 Gruppen-Plugin 1.0.0
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 17:17:10 +00:00

82 lines
4.6 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, usePage } from '@inertiajs/vue3';
import { Compass, LoaderCircle, Plus, UsersRound } from '@lucide/vue';
import { AppLayout, Button, EmptyState, PageHeader, http, toast } from '@inhaus/ui';
import GroupCard from '../components/GroupCard.vue';
import GroupDialog from '../components/GroupDialog.vue';
import PostCard from '../components/PostCard.vue';
const props = defineProps({
posts: { type: Array, required: true },
more: { type: Boolean, default: false },
groups: { type: Array, required: true },
invitations: { type: Array, default: () => [] },
suggested: { type: Array, default: () => [] },
privacy: { type: Object, required: true },
privacyHints: { type: Object, required: true },
});
const page = usePage();
watch(() => page.props.flash?.status, (status) => status && toast.success(status), { immediate: true });
const feed = ref(props.posts);
const hasMore = ref(props.more);
const loading = ref(false);
const creating = ref(false);
const reactions = ['👍', '❤️', '😂', '😮', '😢', '👏'];
async function loadMore() {
loading.value = true;
const data = await http.get(`/gruppen?vor=${feed.value.at(-1).id}`);
feed.value.push(...data.posts);
hasMore.value = data.more;
loading.value = false;
}
</script>
<template>
<AppLayout title="Gruppen">
<PageHeader title="Gruppen" description="Austausch zu Themen, Hobbys und Projekten – offen, geschlossen oder privat.">
<template #actions>
<Button variant="outline" as-child><Link href="/gruppen/entdecken"><Compass /> Gruppen entdecken</Link></Button>
<Button @click="creating = true"><Plus /> Gruppe gründen</Button>
</template>
</PageHeader>
<div class="ih:grid ih:gap-6 ih:lg:grid-cols-[minmax(0,1fr)_20rem]">
<section class="ih:mx-auto ih:grid ih:w-full ih:max-w-2xl ih:content-start ih:gap-4" aria-label="Neue Beiträge aus Ihren Gruppen">
<PostCard v-for="post in feed" :key="post.id" :post="post" :reactions="reactions" show-group @deleted="feed = feed.filter((p) => p.id !== post.id)" />
<Button v-if="hasMore" variant="outline" :disabled="loading" @click="loadMore"><LoaderCircle v-if="loading" class="ih:animate-spin" /> Ältere Beiträge laden</Button>
<div v-if="!feed.length" class="ih:rounded-xl ih:border ih:bg-card">
<EmptyState :icon="UsersRound" :title="groups.length ? 'Noch keine Beiträge' : 'Sie sind noch in keiner Gruppe'" :text="groups.length ? 'Schreiben Sie den ersten Beitrag in einer Ihrer Gruppen.' : 'Entdecken Sie Gruppen zu Ihren Themen – oder gründen Sie selbst eine.'" />
</div>
</section>
<aside class="ih:grid ih:content-start ih:gap-5">
<section v-if="invitations.length" class="ih:rounded-xl ih:border ih:border-brand/40 ih:bg-brand-soft/40 ih:p-4">
<h2 class="ih:mb-2 ih:text-sm ih:font-semibold">Einladungen</h2>
<div class="ih:grid ih:gap-3"><GroupCard v-for="g in invitations" :key="g.id" :group="g" /></div>
</section>
<section class="ih:rounded-xl ih:border ih:bg-card ih:p-4">
<h2 class="ih:mb-2 ih:text-sm ih:font-semibold">Ihre Gruppen</h2>
<ul v-if="groups.length" class="ih:-mx-2 ih:grid">
<li v-for="g in groups" :key="g.id">
<Link :href="g.url" class="ih:flex ih:items-center ih:gap-3 ih:rounded-md ih:p-2 ih:hover:bg-accent/60">
<span class="ih:size-10 ih:shrink-0 ih:rounded-md ih:bg-brand ih:bg-cover ih:bg-center" :style="g.cover_url ? { backgroundImage: `url(${g.cover_url})` } : {}" />
<span class="ih:min-w-0"><span class="ih:block ih:truncate ih:text-sm ih:font-medium">{{ g.name }}</span><span class="ih:text-xs ih:text-muted-foreground">{{ g.members_count }} {{ g.members_count === 1 ? 'Mitglied' : 'Mitglieder' }}</span></span>
</Link>
</li>
</ul>
<p v-else class="ih:text-sm ih:text-muted-foreground">Noch keine.</p>
</section>
<section v-if="suggested.length" class="ih:grid ih:gap-3">
<h2 class="ih:text-sm ih:font-semibold">Vorschläge</h2>
<GroupCard v-for="g in suggested" :key="g.id" :group="g" />
</section>
</aside>
</div>
<GroupDialog v-model:open="creating" :privacy="privacy" :privacy-hints="privacyHints" />
</AppLayout>
</template>