Herzen und Kommentare schon in der Vorschau (0.44.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m6s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m4s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m25s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 8m3s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m26s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m49s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m1s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m41s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 45s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m6s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m6s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m4s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m25s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 8m3s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m26s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m49s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m1s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m41s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 45s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m6s
- NewsPost::withStats: Herzen (Anzahl, eigenes) und Kommentare (Anzahl) für alle Vorschau-Abfragen: Übersicht, Widgets, Slider, Block, Profil, „Weitere Beiträge“, API - NewsPostResource: „comments“ (null bei ausgeschalteten Kommentaren) - NewsStats.vue in Karte, Listeneintrag, Block-Layouts, Slider und Seitenleiste Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
60dd200300
commit
21307fc953
145 changed files with 471 additions and 358 deletions
|
|
@ -6,6 +6,7 @@ import CategoryLabel from '../components/CategoryLabel.vue';
|
|||
import NewsCard from '../components/NewsCard.vue';
|
||||
import NewsImage from '../components/NewsImage.vue';
|
||||
import NewsListItem from '../components/NewsListItem.vue';
|
||||
import NewsStats from '../components/NewsStats.vue';
|
||||
import { formatShortDate } from '@/lib/format';
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +39,10 @@ const moreLabel = computed(() => props.block.data.more_label ?? 'Alle anzeigen')
|
|||
<CategoryLabel :category="post.category" />
|
||||
<h4 class="mt-1 line-clamp-2 text-base leading-snug font-semibold group-hover:underline">{{ post.title }}</h4>
|
||||
<p v-if="post.teaser" class="mt-1 line-clamp-2 text-[13px] text-muted-foreground">{{ post.teaser }}</p>
|
||||
<p class="mt-1.5 text-xs text-muted-foreground">{{ formatShortDate(post.published_at) }}</p>
|
||||
<p class="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground">
|
||||
{{ formatShortDate(post.published_at) }}
|
||||
<NewsStats :post="post" />
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
|
|
@ -51,6 +55,10 @@ const moreLabel = computed(() => props.block.data.more_label ?? 'Alle anzeigen')
|
|||
<CategoryLabel :category="posts[0].category" />
|
||||
<h4 class="mt-1 line-clamp-2 text-lg leading-snug font-semibold group-hover:underline">{{ posts[0].title }}</h4>
|
||||
<p v-if="posts[0].teaser" class="mt-1 line-clamp-3 text-sm text-muted-foreground">{{ posts[0].teaser }}</p>
|
||||
<p class="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground">
|
||||
{{ formatShortDate(posts[0].published_at) }}
|
||||
<NewsStats :post="posts[0]" />
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
<div v-if="posts.length > 1" class="divide-y border-t">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<script setup>
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import NewsStats from './NewsStats.vue';
|
||||
import { ArrowRight, ChevronLeft, ChevronRight, Pause, Play } from '@lucide/vue';
|
||||
|
||||
const props = defineProps({
|
||||
|
|
@ -66,6 +67,7 @@ onBeforeUnmount(stop);
|
|||
</span>
|
||||
<h2 class="text-2xl leading-tight font-semibold tracking-tight sm:text-[32px]">{{ current.title }}</h2>
|
||||
<p v-if="current.teaser" class="mt-3 line-clamp-3 hidden text-[15px] text-white/85 sm:block">{{ current.teaser }}</p>
|
||||
<NewsStats v-if="current.likes || current.comments" :post="current" light class="mt-3" />
|
||||
<Link
|
||||
:href="`/neuigkeiten/${current.slug}`"
|
||||
class="mt-5 inline-flex w-fit items-center gap-2 rounded-md bg-brand px-4 py-2.5 text-sm font-medium text-brand-foreground transition-colors hover:bg-brand-700"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { Heart } from '@lucide/vue';
|
||||
import CategoryLabel from './CategoryLabel.vue';
|
||||
import NewsImage from './NewsImage.vue';
|
||||
import NewsStats from './NewsStats.vue';
|
||||
import { formatShortDate } from '@/lib/format';
|
||||
|
||||
defineProps({
|
||||
|
|
@ -19,7 +19,7 @@ defineProps({
|
|||
<p v-if="post.teaser" class="mt-1.5 line-clamp-2 text-[13px] text-muted-foreground">{{ post.teaser }}</p>
|
||||
<p class="mt-auto flex items-center gap-1 pt-3 text-xs text-muted-foreground">
|
||||
{{ formatShortDate(post.published_at) }} · {{ post.reading_minutes }} Min.
|
||||
<span v-if="post.likes" class="ml-auto inline-flex items-center gap-1 tabular-nums" :title="`${post.likes} ${post.likes === 1 ? 'Herz' : 'Herzen'}`"><Heart class="size-3.5" :class="post.liked ? 'fill-current text-brand-text' : ''" /> {{ post.likes }}</span>
|
||||
<NewsStats :post="post" class="ml-auto" />
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import { Link } from '@inertiajs/vue3';
|
||||
import CategoryLabel from './CategoryLabel.vue';
|
||||
import NewsImage from './NewsImage.vue';
|
||||
import NewsStats from './NewsStats.vue';
|
||||
import { formatRelative } from '@/lib/format';
|
||||
|
||||
defineProps({
|
||||
|
|
@ -12,10 +13,13 @@ defineProps({
|
|||
<template>
|
||||
<Link :href="`/neuigkeiten/${post.slug}`" class="group flex gap-4 py-3">
|
||||
<NewsImage :src="post.thumb_url" :alt="post.title" class="w-28 shrink-0 rounded-md sm:w-32" />
|
||||
<div class="min-w-0">
|
||||
<div class="min-w-0 flex-1">
|
||||
<CategoryLabel :category="post.category" />
|
||||
<h3 class="mt-0.5 line-clamp-2 text-sm leading-snug font-semibold group-hover:underline">{{ post.title }}</h3>
|
||||
<p class="mt-1 text-xs text-muted-foreground">{{ formatRelative(post.published_at) }}</p>
|
||||
<p class="mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground">
|
||||
{{ formatRelative(post.published_at) }}
|
||||
<NewsStats :post="post" />
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
</template>
|
||||
|
|
|
|||
42
plugins-core/news/resources/js/components/NewsStats.vue
Normal file
42
plugins-core/news/resources/js/components/NewsStats.vue
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<script setup>
|
||||
import { Heart, MessageCircle } from '@lucide/vue';
|
||||
import { computed } from 'vue';
|
||||
|
||||
/**
|
||||
* Herzen und Kommentare eines Beitrags – schon in der Vorschau sichtbar.
|
||||
* Kommentare fehlen, wenn sie für den Beitrag ausgeschaltet sind (comments = null).
|
||||
*/
|
||||
const props = defineProps({
|
||||
post: { type: Object, required: true },
|
||||
light: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const hasLikes = computed(() => typeof props.post.likes === 'number');
|
||||
const hasComments = computed(() => typeof props.post.comments === 'number');
|
||||
const label = computed(() =>
|
||||
[
|
||||
hasLikes.value ? `${props.post.likes} ${props.post.likes === 1 ? 'Herz' : 'Herzen'}` : null,
|
||||
hasComments.value ? `${props.post.comments} ${props.post.comments === 1 ? 'Kommentar' : 'Kommentare'}` : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(', '),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span
|
||||
v-if="hasLikes || hasComments"
|
||||
class="inline-flex items-center gap-3 text-xs tabular-nums"
|
||||
:class="light ? 'text-white/85' : 'text-muted-foreground'"
|
||||
role="img"
|
||||
:aria-label="label"
|
||||
:title="label"
|
||||
>
|
||||
<span v-if="hasLikes" class="inline-flex items-center gap-1">
|
||||
<Heart class="size-3.5" :class="post.liked ? (light ? 'fill-current' : 'fill-current text-brand-text') : ''" aria-hidden="true" />{{ post.likes }}
|
||||
</span>
|
||||
<span v-if="hasComments" class="inline-flex items-center gap-1">
|
||||
<MessageCircle class="size-3.5" aria-hidden="true" />{{ post.comments }}
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
|
|
@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button';
|
|||
import EasyLanguageBar from '@/components/EasyLanguageBar.vue';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
import NewsComments from '../components/NewsComments.vue';
|
||||
import NewsStats from '../components/NewsStats.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import PageContent from '@/pagebuilder/PageContent.vue';
|
||||
import { formatDate, formatShortDate } from '@/lib/format';
|
||||
|
|
@ -220,7 +221,7 @@ const mailLink = () => `mailto:?subject=${encodeURIComponent(props.post.title)}&
|
|||
<span class="min-w-0">
|
||||
<span v-if="item.category" class="block text-[10px] font-semibold tracking-wider text-accent2-text uppercase">{{ item.category.name }}</span>
|
||||
<span class="line-clamp-2 text-sm leading-snug font-medium group-hover:underline">{{ item.title }}</span>
|
||||
<span class="block text-xs text-muted-foreground">{{ formatShortDate(item.published_at) }}</span>
|
||||
<span class="flex flex-wrap items-center gap-x-3 text-xs text-muted-foreground">{{ formatShortDate(item.published_at) }} <NewsStats :post="item" /></span>
|
||||
</span>
|
||||
</Link>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class NewsApiController extends Controller
|
|||
? NewsCategory::query()->visibleTo($request->user())->where('slug', $request->query('category'))->first()
|
||||
: null;
|
||||
|
||||
$posts = NewsPost::query()->published()->visibleTo($request->user())->with('category')->withLikes($request->user())
|
||||
$posts = NewsPost::query()->published()->visibleTo($request->user())->with('category')->withStats($request->user())
|
||||
->when($category, fn ($q) => $q->where('category_id', $category->id))
|
||||
->latest('published_at')->paginate(20);
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ class NewsApiController extends Controller
|
|||
public function show(Request $request, NewsPost $post, Content $content): JsonResponse
|
||||
{
|
||||
abort_unless($post->isPublished() && $post->isVisibleTo($request->user()), 404);
|
||||
$post->load(['category', 'author'])->loadCount('likes');
|
||||
$post->load(['category', 'author'])->loadCount(['likes', 'comments']);
|
||||
$post->setAttribute('liked', $post->likes()->where('user_id', $request->user()->id)->exists());
|
||||
app(Reach::class)->record($post, $request->user());
|
||||
$rendered = $content->render($post->blocks(), $request->user(), ['news_id' => $post->id]);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class NewsController extends Controller
|
|||
->published()
|
||||
->visibleTo($request->user())
|
||||
->with('category')
|
||||
->withLikes($request->user())
|
||||
->withStats($request->user())
|
||||
->when($category, fn ($query) => $query->where('category_id', $category->id))
|
||||
->when($author, fn ($query) => $query->where('author_id', $author->id))
|
||||
->when($only->isNotEmpty(), fn ($query) => $query->whereIn('category_id', $only->pluck('id')))
|
||||
|
|
@ -96,6 +96,7 @@ class NewsController extends Controller
|
|||
->published()
|
||||
->visibleTo(request()->user())
|
||||
->with('category')
|
||||
->withStats(request()->user())
|
||||
->whereKeyNot($post->id)
|
||||
->orderByRaw('category_id = ? DESC', [$post->category_id ?? 0])
|
||||
->latest('published_at')
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ class NewsPostResource extends JsonResource
|
|||
'reading_minutes' => $this->reading_minutes,
|
||||
'likes' => $this->when(isset($this->likes_count), fn () => (int) $this->likes_count),
|
||||
'liked' => $this->when(isset($this->liked), fn () => (bool) $this->liked),
|
||||
// null = Kommentare für diesen Beitrag ausgeschaltet
|
||||
'comments' => $this->when(isset($this->comments_count), fn () => $this->comments_enabled ? (int) $this->comments_count : null),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,6 +164,16 @@ class NewsPost extends Model
|
|||
$query->withCount('likes')->withExists(['likes as liked' => fn ($q) => $q->where('user_id', $user?->id ?? 0)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Herzen (Anzahl, eigenes) und Kommentare (Anzahl) – für Vorschauen in Listen, Kacheln und Slider.
|
||||
*
|
||||
* @param Builder<NewsPost> $query
|
||||
*/
|
||||
public function scopeWithStats(Builder $query, ?User $user): void
|
||||
{
|
||||
$query->withLikes($user)->withCount('comments');
|
||||
}
|
||||
|
||||
/** @return HasMany<NewsComment, $this> */
|
||||
public function comments(): HasMany
|
||||
{
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class NewsPlugin extends Plugin
|
|||
|
||||
return $total === 0 ? null : [
|
||||
'total' => $total,
|
||||
'posts' => NewsPostResource::collection($query->with('category')->latest('published_at')->limit(4)->get())->resolve(),
|
||||
'posts' => NewsPostResource::collection($query->with('category')->withStats($viewer)->latest('published_at')->limit(4)->get())->resolve(),
|
||||
'all_url' => '/neuigkeiten?autor='.$person->id,
|
||||
];
|
||||
});
|
||||
|
|
@ -140,7 +140,7 @@ class NewsPlugin extends Plugin
|
|||
])
|
||||
->resolveUsing(function (array $data, ?User $user) {
|
||||
$slugs = $data['filter'] === 'all' ? [] : $data['categories'];
|
||||
$posts = NewsPost::query()->published()->visibleTo($user)->with('category')
|
||||
$posts = NewsPost::query()->published()->visibleTo($user)->with('category')->withStats($user)
|
||||
->when($slugs !== [] && $data['filter'] === 'include', fn ($q) => $q->whereHas('category', fn ($c) => $c->whereIn('slug', $slugs)))
|
||||
->when($slugs !== [] && $data['filter'] === 'exclude', fn ($q) => $q->where(fn ($q) => $q->whereNull('category_id')->orWhereHas('category', fn ($c) => $c->whereNotIn('slug', $slugs))))
|
||||
->latest('published_at')->limit($data['count'])->get();
|
||||
|
|
@ -204,7 +204,7 @@ class NewsPlugin extends Plugin
|
|||
}, label: 'Slider mit hervorgehobenen Beiträgen', mobileSort: 10);
|
||||
|
||||
$widgets->add('news.latest', 'news::Latest', 'feed', sort: 10, props: function (User $user, Request $request) {
|
||||
$posts = NewsPost::query()->published()->visibleTo($user)->with('category')
|
||||
$posts = NewsPost::query()->published()->visibleTo($user)->with('category')->withStats($user)
|
||||
->whereKeyNot($this->featured($user)->modelKeys())
|
||||
->latest('published_at')->limit(4)->get();
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ class NewsPlugin extends Plugin
|
|||
}, label: 'Neuigkeiten', mobileSort: 20);
|
||||
|
||||
$widgets->add('news.areas', 'news::Areas', 'main', sort: 20, props: function (User $user) {
|
||||
$posts = NewsPost::query()->published()->visibleTo($user)->with('category')
|
||||
$posts = NewsPost::query()->published()->visibleTo($user)->with('category')->withStats($user)
|
||||
->whereKeyNot($this->featured($user)->modelKeys())
|
||||
->latest('published_at')->skip(4)->limit(8)->get();
|
||||
|
||||
|
|
@ -231,11 +231,11 @@ class NewsPlugin extends Plugin
|
|||
static $cache = [];
|
||||
|
||||
return $cache[$user->id] ??= (function () use ($user) {
|
||||
$featured = NewsPost::query()->published()->visibleTo($user)->with('category')
|
||||
$featured = NewsPost::query()->published()->visibleTo($user)->with('category')->withStats($user)
|
||||
->where('is_featured', true)->whereNotNull('cover_path')
|
||||
->latest('published_at')->limit(5)->get();
|
||||
|
||||
return $featured->isNotEmpty() ? $featured : NewsPost::query()->published()->visibleTo($user)->with('category')
|
||||
return $featured->isNotEmpty() ? $featured : NewsPost::query()->published()->visibleTo($user)->with('category')->withStats($user)
|
||||
->whereNotNull('cover_path')->latest('published_at')->limit(3)->get();
|
||||
})();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue