Skip to content

Commit fd9cf45

Browse files
committed
✨ ajout de l'affichage en card dans le listing des articles
1 parent fc87426 commit fd9cf45

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

app/Http/Livewire/Articles/Browse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function validSort($sort): bool
4444
public function render(): View
4545
{
4646
$articles = Article::with('tags')
47+
->withCount(['views', 'reactions'])
4748
->published()
4849
->notPinned()
4950
->orderByDesc('sponsored_at')
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
11
@props(['article'])
2+
3+
<article class="pb-8 border-b border-skin-base" aria-labelledby="post-title-{{ $article->id }}">
4+
<div>
5+
<div class="flex space-x-3">
6+
<div class="flex-shrink-0">
7+
<img class="h-10 w-10 rounded-full" src="{{ $article->author->profile_photo_url }}" alt="{{ $article->author->name }}">
8+
</div>
9+
<div class="min-w-0 flex-1">
10+
<p class="text-sm font-medium text-skin-inverted">
11+
<a href="{{ route('profile', $article->author->username) }}" class="hover:underline">{{ $article->author->name }}</a>
12+
</p>
13+
<p class="text-sm text-skin-base">
14+
<a href="#" class="hover:underline">
15+
<time datetime="{{ $article->publishedAt()->format('Y-m-d') }}">{{ $article->publishedAt()->format('j M, Y') }}</time>
16+
</a>
17+
</p>
18+
</div>
19+
</div>
20+
<h2 id="post-title-{{ $article->id }}" class="mt-4 text-lg leading-7 font-medium text-skin-inverted">
21+
{{ $article->title }}
22+
</h2>
23+
</div>
24+
<a href="{{ route('articles.show', $article) }}" class="block mt-2 group space-y-4">
25+
<p class="text-sm text-skin-inverted-muted/70">
26+
{!! $article->excerpt(190) !!}
27+
</p>
28+
<div class="relative h-96 overflow-hidden">
29+
<img class="w-full h-full object-cover shadow-lg rounded-lg group-hover:opacity-75" src="{{ $article->getFirstMediaUrl('media') }}" alt="{{ $article->title }}" />
30+
</div>
31+
<div class="flex justify-between space-x-8">
32+
<div class="flex space-x-6">
33+
<span class="inline-flex items-center text-sm">
34+
<button type="button" class="inline-flex space-x-2 text-skin-muted hover:text-skin-base">
35+
<x-heroicon-o-thumb-up class="h-5 w-5" />
36+
<span class="font-medium text-skin-inverted">{{ $article->reactions_count }}</span>
37+
<span class="sr-only">likes</span>
38+
</button>
39+
</span>
40+
<span class="inline-flex items-center text-sm">
41+
<div class="inline-flex space-x-2 text-skin-muted">
42+
<x-heroicon-o-eye class="h-5 w-5" />
43+
<span class="font-medium text-skin-inverted">{{ $article->views_count }}</span>
44+
<span class="sr-only">views</span>
45+
</div>
46+
</span>
47+
</div>
48+
<div class="flex items-center space-x-3">
49+
@if ($article->tags->isNotEmpty())
50+
<div class="flex items-center space-x-2">
51+
@foreach ($article->tags as $tag)
52+
<x-tag :tag="$tag" />
53+
@endforeach
54+
</div>
55+
@endif
56+
57+
<x-articles.sponsored :isSponsored="$article->isSponsored()" />
58+
</div>
59+
</div>
60+
</a>
61+
</article>

resources/views/components/articles/overview.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
</div>
2121
<div class="mt-2">
2222
<a href="{{ route('articles.show', $article) }}" class="group">
23-
<h4 class="text-lg leading-6 font-semibold font-sans text-skin-inverted group-hover:text-skin-primary">{{ $article->title }}</h4>
23+
<h4 class="text-lg leading-7 font-semibold font-sans text-skin-inverted group-hover:text-skin-primary">{{ $article->title }}</h4>
2424
</a>
25-
<p class="mt-1 text-sm font-normal text-skin-base leading-5">
26-
{!! $article->excerpt() !!}
25+
<p class="mt-1 text-sm text-skin-base leading-5">
26+
{!! $article->excerpt(130) !!}
2727
</p>
2828
<div class="mt-3 flex items-center font-sans">
2929
<div class="shrink-0">

resources/views/livewire/articles/browse.blade.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class="lg:grid lg:grid-cols-8 lg:gap-8 lg:col-span-7"
4141

4242
<div class="py-12 space-y-8 sm:space-y-10 max-w-lg mx-auto lg:max-w-none">
4343
@foreach ($articles as $article)
44-
<x-articles.overview :article="$article" />
44+
@if($viewMode === 'card')
45+
<x-articles.card-with-author :article="$article" />
46+
@else
47+
<x-articles.overview :article="$article" />
48+
@endif
4549
@endforeach
4650
</div>
4751

0 commit comments

Comments
 (0)