Skip to content

Commit 45572a6

Browse files
committed
🚧 wip dashboard user
1 parent 6fa9e9e commit 45572a6

File tree

15 files changed

+258
-12
lines changed

15 files changed

+258
-12
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\User;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\Auth;
8+
9+
class DashboardController extends Controller
10+
{
11+
public function dashboard()
12+
{
13+
return view('user.dashboard', [
14+
'user' => $user = Auth::user(),
15+
'articles' => $user->articles()->latest()->paginate(10),
16+
]);
17+
}
18+
19+
public function threads()
20+
{
21+
return view('user.threads', [
22+
'user' => $user = Auth::user(),
23+
]);
24+
}
25+
26+
public function discussions()
27+
{
28+
return view('user.discussions', [
29+
'user' => $user = Auth::user(),
30+
]);
31+
}
32+
}

app/Http/Livewire/Articles/Create.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public function store()
7070

7171
if ($this->submitted) {
7272
// Envoi du mail a l'admin pour la validation de l'article
73-
session()->flash('success', 'Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.');
73+
session()->flash('status', 'Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.');
7474
}
7575

7676
$user->hasRole('user') ?
77-
$this->redirect('/articles/me') :
77+
$this->redirectRoute('dashboard') :
7878
$this->redirectRoute('articles.show', $article);
7979
}
8080

app/Models/User.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Foundation\Auth\User as Authenticatable;
1313
use Illuminate\Notifications\Notifiable;
1414
use Illuminate\Support\Facades\Auth;
15+
use Illuminate\Support\Facades\Cache;
1516
use Spatie\MediaLibrary\HasMedia;
1617
use Spatie\MediaLibrary\InteractsWithMedia;
1718
use Spatie\Permission\Traits\HasRoles;
@@ -292,19 +293,34 @@ public function routeNotificationForSlack($notification): string
292293
return env('SLACK_WEBHOOK_URL', '');
293294
}
294295

295-
public function countReplies(): int
296+
public function replies(): Collection
296297
{
297-
return $this->replyAble()->count();
298+
return $this->replyAble;
298299
}
299300

300-
public function replies(): Collection
301+
public function countReplies(): int
301302
{
302-
return $this->replyAble;
303+
return Cache::remember('replies_count', now()->addHours(2), fn () => $this->replyAble()->count());
303304
}
304305

305306
public function countSolutions(): int
306307
{
307-
return $this->replyAble()->isSolution()->count();
308+
return Cache::remember('solutions_count', now()->addHours(2), fn () => $this->replyAble()->isSolution()->count());
309+
}
310+
311+
public function countArticles(): int
312+
{
313+
return Cache::remember('articles_count', now()->addHours(2), fn () => $this->articles()->approved()->count());
314+
}
315+
316+
public function countDiscussions(): int
317+
{
318+
return Cache::remember('discussions_count', now()->addHours(2), fn () => $this->discussions()->count());
319+
}
320+
321+
public function countThreads(): int
322+
{
323+
return Cache::remember('threads_count', now()->addHours(2), fn () => $this->threads()->count());
308324
}
309325

310326
public function scopeMostSolutions(Builder $query, int $inLastDays = null)
@@ -345,6 +361,7 @@ public function scopeMostSubmissionsInLastDays(Builder $query, int $days)
345361
public function scopeWithCounts(Builder $query)
346362
{
347363
return $query->withCount([
364+
'articles as articles_count',
348365
'threads as threads_count',
349366
'replyAble as replies_count',
350367
'replyAble as solutions_count' => function (Builder $query) {

public/css/app.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5039,6 +5039,9 @@ select {
50395039
.gap-3 {
50405040
gap: 0.75rem;
50415041
}
5042+
.gap-5 {
5043+
gap: 1.25rem;
5044+
}
50425045
.gap-y-12 {
50435046
row-gap: 3rem;
50445047
}
@@ -6272,6 +6275,10 @@ select {
62726275
--tw-text-opacity: 1;
62736276
color: rgba(127, 29, 29, var(--tw-text-opacity));
62746277
}
6278+
.text-gray-900 {
6279+
--tw-text-opacity: 1;
6280+
color: rgba(17, 24, 39, var(--tw-text-opacity));
6281+
}
62756282
.underline {
62766283
text-decoration: underline;
62776284
}
@@ -7640,6 +7647,10 @@ html {
76407647
grid-template-columns: none;
76417648
}
76427649

7650+
.sm\:grid-cols-4 {
7651+
grid-template-columns: repeat(4, minmax(0, 1fr));
7652+
}
7653+
76437654
.sm\:flex-row {
76447655
flex-direction: row;
76457656
}
@@ -7746,6 +7757,12 @@ html {
77467757
margin-bottom: calc(2.5rem * var(--tw-space-y-reverse));
77477758
}
77487759

7760+
.sm\:truncate {
7761+
overflow: hidden;
7762+
text-overflow: ellipsis;
7763+
white-space: nowrap;
7764+
}
7765+
77497766
.sm\:rounded-lg {
77507767
border-radius: 0.5rem;
77517768
}
@@ -9318,6 +9335,10 @@ html {
93189335
grid-column: span 10 / span 10;
93199336
}
93209337

9338+
.lg\:col-span-9 {
9339+
grid-column: span 9 / span 9;
9340+
}
9341+
93219342
.lg\:col-start-10 {
93229343
grid-column-start: 10;
93239344
}
@@ -9452,6 +9473,10 @@ html {
94529473
grid-template-columns: repeat(8, minmax(0, 1fr));
94539474
}
94549475

9476+
.lg\:grid-cols-4 {
9477+
grid-template-columns: repeat(4, minmax(0, 1fr));
9478+
}
9479+
94559480
.lg\:grid-rows-2 {
94569481
grid-template-rows: repeat(2, minmax(0, 1fr));
94579482
}
@@ -9623,6 +9648,11 @@ html {
96239648
line-height: 1.75rem;
96249649
}
96259650

9651+
.lg\:text-3xl {
9652+
font-size: 1.875rem;
9653+
line-height: 2.25rem;
9654+
}
9655+
96269656
.lg\:leading-\[3\.5rem\] {
96279657
line-height: 3.5rem;
96289658
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@props(['section'])
2+
3+
<nav class="flex mb-3" aria-label="Breadcrumb">
4+
<ol role="list" class="flex items-center space-x-4">
5+
<li>
6+
<div>
7+
<a href="{{ route('dashboard') }}" class="text-skin-muted hover:text-skin-base">
8+
<x-heroicon-s-home class="flex-shrink-0 h-5 w-5" />
9+
<span class="sr-only">Accueil</span>
10+
</a>
11+
</div>
12+
</li>
13+
14+
<li>
15+
<div class="flex items-center">
16+
<svg class="flex-shrink-0 h-5 w-5 text-gray-300" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
17+
<path d="M5.555 17.776l8-16 .894.448-8 16-.894-.448z" />
18+
</svg>
19+
<span href="#" class="ml-4 text-sm font-medium text-skin-base" aria-current="page">{{ $section }}</span>
20+
</div>
21+
</li>
22+
</ol>
23+
</nav>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@props(['user'])
2+
3+
<nav aria-label="Sidebar" class="sticky top-4">
4+
<div class="space-y-2">
5+
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
6+
<span class="flex-1">{{ __('Articles') }}</span>
7+
<span>{{ number_format($user->countArticles()) }}</span>
8+
</x-nav-link>
9+
10+
<x-nav-link :href="route('discussions.me')" :active="request()->routeIs('discussions.me')">
11+
<span class="flex-1">{{ __('Discussions') }}</span>
12+
<span>{{ number_format($user->countDiscussions()) }}</span>
13+
</x-nav-link>
14+
15+
<x-nav-link :href="route('threads.me')" :active="request()->routeIs('threads.me')">
16+
<span class="flex-1">{{ __('Sujets') }}</span>
17+
<span>{{ number_format($user->countThreads()) }}</span>
18+
</x-nav-link>
19+
</div>
20+
</nav>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@props(['user'])
2+
3+
<dl class="mt-5 grid grid-cols-1 sm:grid-cols-2 gap-5 lg:grid-cols-4">
4+
<div class="px-4 py-5 bg-skin-card-gray shadow rounded-lg overflow-hidden sm:p-6">
5+
<dt class="text-sm font-medium text-skin-base truncate font-sans">
6+
Total Articles/Discussions
7+
</dt>
8+
<dd class="mt-1 text-3xl font-semibold text-skin-inverted">
9+
{{ number_format($user->countArticles() + $user->countDiscussions()) }}
10+
</dd>
11+
</div>
12+
13+
<div class="px-4 py-5 bg-skin-card-gray shadow rounded-lg overflow-hidden sm:p-6">
14+
<dt class="text-sm font-medium text-skin-base truncate font-sans">
15+
Total Réponses
16+
</dt>
17+
<dd class="mt-1 text-3xl font-semibold text-skin-inverted">
18+
{{ number_format($user->countReplies()) }}
19+
</dd>
20+
</div>
21+
22+
<div class="px-4 py-5 bg-skin-card-gray shadow rounded-lg overflow-hidden sm:p-6">
23+
<dt class="text-sm font-medium text-skin-base truncate font-sans">
24+
Sujets Résolus
25+
</dt>
26+
<dd class="mt-1 text-3xl font-semibold text-skin-inverted">
27+
{{ number_format($user->countSolutions()) }}
28+
</dd>
29+
</div>
30+
31+
<div class="px-4 py-5 bg-skin-card-gray shadow rounded-lg overflow-hidden sm:p-6">
32+
<dt class="text-sm font-medium text-skin-base truncate font-sans">
33+
Total Experience
34+
</dt>
35+
<dd class="mt-1 text-3xl font-semibold text-skin-inverted">
36+
0
37+
</dd>
38+
</div>
39+
</dl>

resources/views/discussions/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<p class="inline-flex items-center text-sm text-skin-inverted font-medium">
3737
{{ $discussion->author->name }}
3838
@if($discussion->author->hasAnyRole('admin', 'moderator'))
39-
<x-user-status />
39+
<x-user.status />
4040
@endif
4141
</p>
4242
</div>

resources/views/layouts/_nav.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ class="origin-top-right absolute right-0 mt-2 w-60 rounded-md shadow-lg py-1 bg-
237237
<div class="py-1.5 px-3.5" role="none">
238238
@if(Auth::user()->hasRole(['admin', 'moderator']))
239239
<a href="#" class="group flex items-center py-1.5 text-sm text-skin-base hover:text-skin-primary font-normal" role="menuitem" tabindex="-1" id="user-menu-item-0">
240-
<x-heroicon-o-view-grid class="flex-none h-5 w-5 mr-3 text-skin-muted group-hover:text-skin-primary" />
240+
<x-heroicon-o-chart-square-bar class="flex-none h-5 w-5 mr-3 text-skin-muted group-hover:text-skin-primary" />
241241
{{ __('CPanel') }}
242242
</a>
243243
@endif
244-
<a href="#" class="group flex items-center py-1.5 text-sm text-skin-base hover:text-skin-primary font-normal" role="menuitem" tabindex="-1" id="user-menu-item-0">
244+
<a href="{{ route('dashboard') }}" class="group flex items-center py-1.5 text-sm text-skin-base hover:text-skin-primary font-normal" role="menuitem" tabindex="-1" id="user-menu-item-0">
245245
<x-heroicon-o-view-grid class="flex-none h-5 w-5 mr-3 text-skin-muted group-hover:text-skin-primary" />
246246
{{ __('Dashboard') }}
247247
</a>

0 commit comments

Comments
 (0)