Skip to content

Commit 16c53be

Browse files
StevyMarlinocybersoldattechmckenziearts
authored
feat: (LAR-138) update user dashboard (#266)
Co-authored-by: Chri$ <samorytakougne@gmail.com> Co-authored-by: Arthur Monney <monneylobe@gmail.com>
1 parent 473e087 commit 16c53be

39 files changed

+667
-519
lines changed

app/Actions/Discussion/DeleteDiscussionAction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function execute(Discussion $discussion): void
1515
DB::beginTransaction();
1616

1717
undoPoint(new DiscussionCreated($discussion));
18+
1819
$discussion->delete();
1920

2021
DB::commit();

app/Actions/Forum/DeleteThreadAction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function execute(Thread $thread): void
1515
DB::beginTransaction();
1616

1717
undoPoint(new ThreadCreated($thread));
18+
1819
$thread->delete();
1920

2021
DB::commit();
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Livewire\Components\User;
6+
7+
use App\Models\Article;
8+
use Filament\Actions\Action;
9+
use Filament\Actions\Concerns\InteractsWithActions;
10+
use Filament\Actions\Contracts\HasActions;
11+
use Filament\Forms\Concerns\InteractsWithForms;
12+
use Filament\Forms\Contracts\HasForms;
13+
use Filament\Notifications\Notification;
14+
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
15+
use Illuminate\Contracts\View\View;
16+
use Illuminate\Support\Facades\Auth;
17+
use Livewire\Attributes\Computed;
18+
use Livewire\Component;
19+
use Livewire\WithoutUrlPagination;
20+
use Livewire\WithPagination;
21+
22+
final class Articles extends Component implements HasActions, HasForms
23+
{
24+
use InteractsWithActions;
25+
use InteractsWithForms;
26+
use WithoutUrlPagination;
27+
use WithPagination;
28+
29+
#[Computed]
30+
public function articles(): LengthAwarePaginator
31+
{
32+
return Article::with(['user', 'tags', 'reactions'])
33+
->where('user_id', Auth::id())
34+
->latest()
35+
->paginate(10);
36+
}
37+
38+
public function editAction(): Action
39+
{
40+
return Action::make('edit')
41+
->label(__('actions.edit'))
42+
->color('gray')
43+
->badge()
44+
->action(
45+
fn (array $arguments) => $this->dispatch(
46+
'openPanel',
47+
component: 'components.slideovers.article-form',
48+
arguments: ['articleId' => $arguments['id']]
49+
)
50+
);
51+
}
52+
53+
public function deleteAction(): Action
54+
{
55+
return Action::make('delete')
56+
->label(__('actions.delete'))
57+
->color('danger')
58+
->badge()
59+
->requiresConfirmation()
60+
->action(function (array $arguments): void {
61+
/** @var Article $article */
62+
$article = Article::query()->find($arguments['id']);
63+
64+
$this->authorize('delete', $article);
65+
66+
$article->delete();
67+
68+
Notification::make()
69+
->success()
70+
->title(__('notifications.article.deleted'))
71+
->send();
72+
});
73+
}
74+
75+
public function render(): View
76+
{
77+
return view('livewire.components.user.articles');
78+
}
79+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Livewire\Components\User;
6+
7+
use App\Actions\Discussion\DeleteDiscussionAction;
8+
use App\Models\Discussion;
9+
use Filament\Actions\Action;
10+
use Filament\Actions\Concerns\InteractsWithActions;
11+
use Filament\Actions\Contracts\HasActions;
12+
use Filament\Forms\Concerns\InteractsWithForms;
13+
use Filament\Forms\Contracts\HasForms;
14+
use Filament\Notifications\Notification;
15+
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
16+
use Illuminate\Contracts\View\View;
17+
use Illuminate\Support\Facades\Auth;
18+
use Livewire\Attributes\Computed;
19+
use Livewire\Attributes\Lazy;
20+
use Livewire\Component;
21+
use Livewire\WithoutUrlPagination;
22+
use Livewire\WithPagination;
23+
24+
#[Lazy]
25+
final class Discussions extends Component implements HasActions, HasForms
26+
{
27+
use InteractsWithActions;
28+
use InteractsWithForms;
29+
use WithoutUrlPagination;
30+
use WithPagination;
31+
32+
#[Computed]
33+
public function discussions(): LengthAwarePaginator
34+
{
35+
return Discussion::with('user')
36+
->where('user_id', Auth::id())
37+
->latest()
38+
->paginate(10);
39+
}
40+
41+
public function placeholder(): View
42+
{
43+
return view('components.skeletons.discussions');
44+
}
45+
46+
public function editAction(): Action
47+
{
48+
return Action::make('edit')
49+
->label(__('actions.edit'))
50+
->color('gray')
51+
->badge()
52+
->action(
53+
fn (array $arguments) => $this->dispatch(
54+
'openPanel',
55+
component: 'components.slideovers.discussion-form',
56+
arguments: ['discussionId' => $arguments['id']]
57+
)
58+
);
59+
}
60+
61+
public function deleteAction(): Action
62+
{
63+
return Action::make('delete')
64+
->label(__('actions.delete'))
65+
->color('danger')
66+
->badge()
67+
->requiresConfirmation()
68+
->action(function (array $arguments): void {
69+
/** @var Discussion $discussion */
70+
$discussion = Discussion::query()->find($arguments['id']);
71+
72+
$this->authorize('delete', $discussion);
73+
74+
app(DeleteDiscussionAction::class)->execute($discussion);
75+
76+
Notification::make()
77+
->success()
78+
->title(__('notifications.discussion.deleted'))
79+
->send();
80+
});
81+
}
82+
83+
public function render(): View
84+
{
85+
return view('livewire.components.user.discussions');
86+
}
87+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Livewire\Components\User;
6+
7+
use App\Actions\Forum\DeleteThreadAction;
8+
use App\Models\Thread;
9+
use Filament\Actions\Action;
10+
use Filament\Actions\Concerns\InteractsWithActions;
11+
use Filament\Actions\Contracts\HasActions;
12+
use Filament\Forms\Concerns\InteractsWithForms;
13+
use Filament\Forms\Contracts\HasForms;
14+
use Filament\Notifications\Notification;
15+
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
16+
use Illuminate\Contracts\View\View;
17+
use Illuminate\Support\Facades\Auth;
18+
use Livewire\Attributes\Computed;
19+
use Livewire\Attributes\Lazy;
20+
use Livewire\Component;
21+
use Livewire\WithoutUrlPagination;
22+
use Livewire\WithPagination;
23+
24+
#[Lazy]
25+
final class Threads extends Component implements HasActions, HasForms
26+
{
27+
use InteractsWithActions;
28+
use InteractsWithForms;
29+
use WithoutUrlPagination;
30+
use WithPagination;
31+
32+
#[Computed]
33+
public function threads(): LengthAwarePaginator
34+
{
35+
return Thread::with('user')
36+
->scopes('withViewsCount')
37+
->where('user_id', Auth::id())
38+
->latest()
39+
->paginate(10);
40+
}
41+
42+
public function placeholder(): View
43+
{
44+
return view('components.skeletons.discussions');
45+
}
46+
47+
public function editAction(): Action
48+
{
49+
return Action::make('edit')
50+
->label(__('actions.edit'))
51+
->color('gray')
52+
->badge()
53+
->action(
54+
fn (array $arguments) => $this->dispatch(
55+
'openPanel',
56+
component: 'components.slideovers.thread-form',
57+
arguments: ['threadId' => $arguments['id']]
58+
)
59+
);
60+
}
61+
62+
public function deleteAction(): Action
63+
{
64+
return Action::make('delete')
65+
->label(__('actions.delete'))
66+
->color('danger')
67+
->badge()
68+
->requiresConfirmation()
69+
->action(function (array $arguments): void {
70+
/** @var Thread $thread */
71+
$thread = Thread::query()->find($arguments['thread']);
72+
73+
$this->authorize('delete', $thread);
74+
75+
app(DeleteThreadAction::class)->execute($thread);
76+
77+
Notification::make()
78+
->success()
79+
->title(__('notifications.thread.deleted'))
80+
->send();
81+
});
82+
}
83+
84+
public function render(): View
85+
{
86+
return view('livewire.components.user.threads');
87+
}
88+
}

app/Livewire/Pages/Account/Dashboard.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,14 @@ final class Dashboard extends Component
1818
#[Computed]
1919
public function user(): User
2020
{
21-
return User::with('articles')
21+
return User::query()
2222
->scopes('withCounts')
2323
->find(Auth::id());
2424
}
2525

2626
public function render(): View
2727
{
28-
return view('livewire.pages.account.dashboard', [
29-
'articles' => $this->user->articles()
30-
->orderByDesc('created_at')
31-
->orderBy('submitted_at')
32-
->paginate(12),
33-
])->title(__('pages/account.dashboard.title', ['username' => $this->user->username]));
28+
return view('livewire.pages.account.dashboard')
29+
->title(__('pages/account.dashboard.title', ['username' => $this->user->username]));
3430
}
3531
}

app/Livewire/Pages/Forum/DetailThread.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public function deleteAction(): Action
5454
->authorize('delete', $this->thread)
5555
->requiresConfirmation()
5656
->action(function (): void {
57-
5857
app(DeleteThreadAction::class)->execute($this->thread);
5958

6059
$this->redirectRoute('forum.index', navigate: true);

lang/en/actions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
'unban' => 'Cancel ban',
1515
'confirm' => 'Confirm',
1616
'start' => 'Start',
17+
'view' => 'View',
1718

1819
];

lang/en/global.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
'launch_modal' => [
8989
'forum_action' => 'Create thread',
9090
'forum_description' => 'Do you have a question? Ask it in the forum',
91-
'post_action' => 'Writing an article',
92-
'post_description' => 'Share your discoveries with thousands of developers',
91+
'article_action' => 'Writing an article',
92+
'article_description' => 'Share your discoveries with thousands of developers',
9393
'discussion_action' => 'Start a discussion',
9494
'discussion_description' => 'Discuss and debate different themes and ideas',
9595
],

lang/en/notifications.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'created' => 'Your article has been created.',
99
'submitted' => 'Thank you for submitting your article. We will only contact you once we have accepted your article.',
1010
'updated' => 'Your article has been updated.',
11+
'deleted' => 'Your article has been deleted.',
1112
],
1213

1314
'thread' => [

0 commit comments

Comments
 (0)