Skip to content

Commit c8d688e

Browse files
committed
feat: [LAR-138] update dashboard transform volt component into livewire
1 parent a5ea96d commit c8d688e

30 files changed

+595
-1044
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();
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+
}

lang/en/pages/discussion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
],
4141
'min_discussion_length' => '160 characters maximum',
4242
'placeholder' => 'Your comment here...',
43-
'your_discussion' => 'Your discussion',
43+
'my_discussion' => 'My discussions',
4444

4545
];

lang/en/pages/forum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'min_thread_length' => '10 characters minimum',
4141
'answer_reply' => 'Answer to',
4242
'threads_count' => ':count messages',
43-
'your_thread' => 'Your thread',
43+
'my_thread' => 'My threads',
4444
'not_thread_created' => "You haven't created any topic yet",
4545
'subject' => 'Subject',
4646

lang/fr/pages/discussion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
],
4141
'min_discussion_length' => 'Maximum de 160 caractères.',
4242
'placeholder' => 'Votre commentaire',
43-
'your_discussion' => 'Vos Discussions',
43+
'my_discussion' => 'Mes discussions',
4444

4545
];

lang/fr/pages/forum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'min_thread_length' => 'Minimum de 10 caractères.',
4141
'answer_reply' => 'Répondre au sujet',
4242
'threads_count' => ':count messages',
43-
'your_thread' => 'Vos Sujets',
43+
'my_thread' => 'Mes Sujets',
4444
'not_thread_created' => "Vous n'avez pas encore créé de sujet",
4545
'subject' => 'Sujets',
4646

0 commit comments

Comments
 (0)