Skip to content

Commit 428fc2e

Browse files
committed
✨ Ajout des discussions sur le dashboard user
1 parent 622957e commit 428fc2e

File tree

7 files changed

+110
-38
lines changed

7 files changed

+110
-38
lines changed

app/Http/Controllers/User/DashboardController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ public function threads()
2323
{
2424
return view('user.threads', [
2525
'user' => $user = Auth::user(),
26+
'threads' => $user->threads()
27+
->recent()
28+
->paginate(5),
2629
]);
2730
}
2831

2932
public function discussions()
3033
{
3134
return view('user.discussions', [
3235
'user' => $user = Auth::user(),
36+
'discussions' => $user->discussions()
37+
->orderByDesc('created_at')
38+
->paginate(5),
3339
]);
3440
}
3541
}

app/Models/Discussion.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ public function excerpt(int $limit = 110): string
121121

122122
public function isPinned(): bool
123123
{
124-
return (bool) $this->is_pinned;
124+
return $this->is_pinned;
125125
}
126126

127127
public function isLocked(): bool
128128
{
129-
return (bool) $this->locked;
129+
return $this->locked;
130130
}
131131

132132
public function getCountAllRepliesWithChildAttribute(): int

public/css/app.css

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,6 +4785,12 @@ select {
47854785
.w-4 {
47864786
width: 1rem;
47874787
}
4788+
.w-3\/4 {
4789+
width: 75%;
4790+
}
4791+
.w-5\/6 {
4792+
width: 83.333333%;
4793+
}
47884794
.w-2 {
47894795
width: 0.5rem;
47904796
}
@@ -4812,12 +4818,6 @@ select {
48124818
.w-48 {
48134819
width: 12rem;
48144820
}
4815-
.w-3\/4 {
4816-
width: 75%;
4817-
}
4818-
.w-5\/6 {
4819-
width: 83.333333%;
4820-
}
48214821
.min-w-0 {
48224822
min-width: 0px;
48234823
}
@@ -5184,16 +5184,16 @@ select {
51845184
margin-right: calc(-0.5rem * var(--tw-space-x-reverse));
51855185
margin-left: calc(-0.5rem * calc(1 - var(--tw-space-x-reverse)));
51865186
}
5187-
.space-y-16 > :not([hidden]) ~ :not([hidden]) {
5188-
--tw-space-y-reverse: 0;
5189-
margin-top: calc(4rem * calc(1 - var(--tw-space-y-reverse)));
5190-
margin-bottom: calc(4rem * var(--tw-space-y-reverse));
5191-
}
51925187
.space-y-2 > :not([hidden]) ~ :not([hidden]) {
51935188
--tw-space-y-reverse: 0;
51945189
margin-top: calc(0.5rem * calc(1 - var(--tw-space-y-reverse)));
51955190
margin-bottom: calc(0.5rem * var(--tw-space-y-reverse));
51965191
}
5192+
.space-y-16 > :not([hidden]) ~ :not([hidden]) {
5193+
--tw-space-y-reverse: 0;
5194+
margin-top: calc(4rem * calc(1 - var(--tw-space-y-reverse)));
5195+
margin-bottom: calc(4rem * var(--tw-space-y-reverse));
5196+
}
51975197
.space-x-6 > :not([hidden]) ~ :not([hidden]) {
51985198
--tw-space-x-reverse: 0;
51995199
margin-right: calc(1.5rem * var(--tw-space-x-reverse));
@@ -5494,6 +5494,10 @@ select {
54945494
--tw-bg-opacity: 1;
54955495
background-color: rgba(209, 250, 229, var(--tw-bg-opacity));
54965496
}
5497+
.bg-skin-card-muted {
5498+
--tw-bg-opacity: 1;
5499+
background-color: rgba(var(--color-card-muted-fill), var(--tw-bg-opacity));
5500+
}
54975501
.bg-blue-100 {
54985502
--tw-bg-opacity: 1;
54995503
background-color: rgba(219, 234, 254, var(--tw-bg-opacity));
@@ -5541,10 +5545,6 @@ select {
55415545
--tw-bg-opacity: 1;
55425546
background-color: rgba(55, 65, 81, var(--tw-bg-opacity));
55435547
}
5544-
.bg-skin-card-muted {
5545-
--tw-bg-opacity: 1;
5546-
background-color: rgba(var(--color-card-muted-fill), var(--tw-bg-opacity));
5547-
}
55485548
.bg-yellow-50 {
55495549
--tw-bg-opacity: 1;
55505550
background-color: rgba(255, 251, 235, var(--tw-bg-opacity));
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@props(['discussion'])
2+
3+
<div class="py-6 border-b border-skin-base">
4+
<div class="mt-2 lg:flex lg:items-center lg:justify-between">
5+
<div class="flex-1">
6+
<h2 class="text-xl font-semibold font-sans text-skin-inverted leading-7">
7+
<a href="{{ route('discussions.show', $discussion) }}" class="hover:text-skin-primary">{{ $discussion->title }}</a>
8+
</h2>
9+
</div>
10+
<div class="mt-2 lg:mt-0 flex-shrink-0 self-start">
11+
@if (count($tags = $discussion->tags))
12+
<div class="flex flex-wrap gap-2 lg:gap-x-3">
13+
@foreach ($tags as $tag)
14+
<x-tag :tag="$tag" />
15+
@endforeach
16+
</div>
17+
@endif
18+
</div>
19+
</div>
20+
<p class="mt-1 text-sm font-normal text-skin-base leading-5">
21+
{!! $discussion->excerpt(175) !!}
22+
</p>
23+
<div class="mt-3 flex justify-between">
24+
<div class="flex items-center text-sm font-sans text-skin-muted">
25+
<a class="flex-shrink-0" href="{{ route('profile', $discussion->author->username) }}">
26+
<img class="h-6 w-6 rounded-full" src="{{ $discussion->author->profile_photo_url }}" alt="{{ $discussion->author->name }}">
27+
</a>
28+
<span class="ml-2 pr-1">Posté par</span>
29+
<div class="flex items-center space-x-1">
30+
<a href="{{ route('profile', $discussion->author->username) }}" class="text-skin-inverted hover:underline">{{ $discussion->author->name }}</a>
31+
<span aria-hidden="true">&middot;</span>
32+
<time-ago time="{{ $discussion->created_at->getTimestamp() }}"/>
33+
</div>
34+
</div>
35+
<div class="flex items-center text-sm space-x-4">
36+
<p class="inline-flex space-x-2 text-skin-base">
37+
<x-heroicon-o-chat-alt-2 class="h-5 w-5" />
38+
<span class="font-normal text-skin-inverted-muted">{{ $discussion->count_all_replies_with_child }}</span>
39+
<span class="sr-only">réponses</span>
40+
</p>
41+
<a href="{{ route('discussions.edit', $discussion->slug()) }}" class="inline-flex items-center font-normal text-skin-inverted-muted hover:text-skin-base hover:underline">
42+
<x-heroicon-o-pencil class="h-4 w-4 mr-1.5" />
43+
Éditer
44+
</a>
45+
</div>
46+
</div>
47+
</div>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@props(['title', 'button', 'url'])
2+
3+
<div class="md:flex md:items-center md:justify-between">
4+
<div class="flex-1 min-w-0">
5+
<h2 class="text-lg font-bold leading-7 text-skin-inverted sm:text-xl sm:truncate font-sans">
6+
{{ $title }}
7+
</h2>
8+
</div>
9+
<div class="mt-4 flex md:mt-0 md:ml-4">
10+
<x-button :link="$url" class="ml-3">
11+
{{ $button }}
12+
</x-button>
13+
</div>
14+
</div>

resources/views/user/dashboard.blade.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,7 @@
2020
<x-user.sidebar :user="$user" />
2121
</div>
2222
<main class="lg:col-span-9">
23-
<div class="md:flex md:items-center md:justify-between">
24-
<div class="flex-1 min-w-0">
25-
<h2 class="text-lg font-bold leading-7 text-skin-inverted sm:text-xl sm:truncate font-sans">
26-
Vos articles
27-
</h2>
28-
</div>
29-
<div class="mt-4 flex md:mt-0 md:ml-4">
30-
<x-button :link="route('articles.new')" class="ml-3">
31-
Nouvel article
32-
</x-button>
33-
</div>
34-
</div>
23+
<x-user.page-heading title="Vos articles" :url="route('articles.new')" button="Nouvel article" />
3524

3625
<div class="mt-5">
3726
@unless(Auth::user()->hasTwitterAccount())
@@ -62,12 +51,14 @@
6251
</h3>
6352

6453
<div class="flex items-center text-skin-muted font-sans">
65-
<a href="{{ route('articles.show', $article->slug()) }}" class="hover:text-skin-base hover:underline">
66-
Voir
67-
</a>
68-
<span class="mx-1">
69-
&middot;
70-
</span>
54+
@if($article->isPublished())
55+
<a href="{{ route('articles.show', $article->slug()) }}" class="hover:text-skin-base hover:underline">
56+
Voir
57+
</a>
58+
<span class="mx-1">
59+
&middot;
60+
</span>
61+
@endif
7162
<a href="{{ route('articles.edit', $article->slug()) }}" class="hover:text-skin-base hover:underline">
7263
Éditer
7364
</a>
@@ -96,8 +87,8 @@
9687

9788
<div class="flex text-sm leading-5 text-skin-base">
9889
@if ($article->isPublished())
99-
<time datetime="{{ $article->submitted_at->format('Y-m-d') }}">
100-
Publié le {{ $article->submitted_at->format('j M, Y') }}
90+
<time datetime="{{ $article->submittedAt()->format('Y-m-d') }}">
91+
Publié le {{ $article->submittedAt()->format('j M, Y') }}
10192
</time>
10293
@else
10394
@if ($article->isAwaitingApproval())

resources/views/user/discussions.blade.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@
2020
<x-user.sidebar :user="$user" />
2121
</div>
2222
<main class="lg:col-span-9">
23-
23+
<x-user.page-heading title="Vos discussions" :url="route('discussions.new')" button="Nouvelle discussion" />
24+
25+
<div class="mt-5">
26+
@forelse($discussions as $discussion)
27+
<x-discussions.summary :discussion="$discussion" />
28+
@empty
29+
<p class="text-skin-base text-base">
30+
Vous n'avez pas encore créé de discussions.
31+
</p>
32+
@endforelse
33+
34+
<div class="pt-5">
35+
{{ $discussions->links() }}
36+
</div>
37+
</div>
2438
</main>
2539
</section>
2640

0 commit comments

Comments
 (0)