Skip to content

feat: (LAR-138) update user dashboard #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Actions/Discussion/DeleteDiscussionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function execute(Discussion $discussion): void
DB::beginTransaction();

undoPoint(new DiscussionCreated($discussion));

$discussion->delete();

DB::commit();
Expand Down
1 change: 1 addition & 0 deletions app/Actions/Forum/DeleteThreadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function execute(Thread $thread): void
DB::beginTransaction();

undoPoint(new ThreadCreated($thread));

$thread->delete();

DB::commit();
Expand Down
79 changes: 79 additions & 0 deletions app/Livewire/Components/User/Articles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace App\Livewire\Components\User;

use App\Models\Article;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Computed;
use Livewire\Component;
use Livewire\WithoutUrlPagination;
use Livewire\WithPagination;

final class Articles extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;
use WithoutUrlPagination;
use WithPagination;

#[Computed]
public function articles(): LengthAwarePaginator
{
return Article::with(['user', 'tags', 'reactions'])
->where('user_id', Auth::id())
->latest()
->paginate(10);
}

public function editAction(): Action
{
return Action::make('edit')
->label(__('actions.edit'))
->color('gray')
->badge()
->action(
fn (array $arguments) => $this->dispatch(
'openPanel',
component: 'components.slideovers.article-form',
arguments: ['articleId' => $arguments['id']]
)
);
}

public function deleteAction(): Action
{
return Action::make('delete')
->label(__('actions.delete'))
->color('danger')
->badge()
->requiresConfirmation()
->action(function (array $arguments): void {
/** @var Article $article */
$article = Article::query()->find($arguments['id']);

$this->authorize('delete', $article);

$article->delete();

Notification::make()
->success()
->title(__('notifications.article.deleted'))
->send();
});
}

public function render(): View
{
return view('livewire.components.user.articles');
}
}
87 changes: 87 additions & 0 deletions app/Livewire/Components/User/Discussions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

namespace App\Livewire\Components\User;

use App\Actions\Discussion\DeleteDiscussionAction;
use App\Models\Discussion;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Lazy;
use Livewire\Component;
use Livewire\WithoutUrlPagination;
use Livewire\WithPagination;

#[Lazy]
final class Discussions extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;
use WithoutUrlPagination;
use WithPagination;

#[Computed]
public function discussions(): LengthAwarePaginator
{
return Discussion::with('user')
->where('user_id', Auth::id())
->latest()
->paginate(10);
}

public function placeholder(): View
{
return view('components.skeletons.discussions');
}

public function editAction(): Action
{
return Action::make('edit')
->label(__('actions.edit'))
->color('gray')
->badge()
->action(
fn (array $arguments) => $this->dispatch(
'openPanel',
component: 'components.slideovers.discussion-form',
arguments: ['discussionId' => $arguments['id']]
)
);
}

public function deleteAction(): Action
{
return Action::make('delete')
->label(__('actions.delete'))
->color('danger')
->badge()
->requiresConfirmation()
->action(function (array $arguments): void {
/** @var Discussion $discussion */
$discussion = Discussion::query()->find($arguments['id']);

$this->authorize('delete', $discussion);

app(DeleteDiscussionAction::class)->execute($discussion);

Notification::make()
->success()
->title(__('notifications.discussion.deleted'))
->send();
});
}

public function render(): View
{
return view('livewire.components.user.discussions');
}
}
88 changes: 88 additions & 0 deletions app/Livewire/Components/User/Threads.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

declare(strict_types=1);

namespace App\Livewire\Components\User;

use App\Actions\Forum\DeleteThreadAction;
use App\Models\Thread;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Lazy;
use Livewire\Component;
use Livewire\WithoutUrlPagination;
use Livewire\WithPagination;

#[Lazy]
final class Threads extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;
use WithoutUrlPagination;
use WithPagination;

#[Computed]
public function threads(): LengthAwarePaginator
{
return Thread::with('user')
->scopes('withViewsCount')
->where('user_id', Auth::id())
->latest()
->paginate(10);
}

public function placeholder(): View
{
return view('components.skeletons.discussions');
}

public function editAction(): Action
{
return Action::make('edit')
->label(__('actions.edit'))
->color('gray')
->badge()
->action(
fn (array $arguments) => $this->dispatch(
'openPanel',
component: 'components.slideovers.thread-form',
arguments: ['threadId' => $arguments['id']]
)
);
}

public function deleteAction(): Action
{
return Action::make('delete')
->label(__('actions.delete'))
->color('danger')
->badge()
->requiresConfirmation()
->action(function (array $arguments): void {
/** @var Thread $thread */
$thread = Thread::query()->find($arguments['thread']);

$this->authorize('delete', $thread);

app(DeleteThreadAction::class)->execute($thread);

Notification::make()
->success()
->title(__('notifications.thread.deleted'))
->send();
});
}

public function render(): View
{
return view('livewire.components.user.threads');
}
}
10 changes: 3 additions & 7 deletions app/Livewire/Pages/Account/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ final class Dashboard extends Component
#[Computed]
public function user(): User
{
return User::with('articles')
return User::query()
->scopes('withCounts')
->find(Auth::id());
}

public function render(): View
{
return view('livewire.pages.account.dashboard', [
'articles' => $this->user->articles()
->orderByDesc('created_at')
->orderBy('submitted_at')
->paginate(12),
])->title(__('pages/account.dashboard.title', ['username' => $this->user->username]));
return view('livewire.pages.account.dashboard')
->title(__('pages/account.dashboard.title', ['username' => $this->user->username]));
}
}
1 change: 0 additions & 1 deletion app/Livewire/Pages/Forum/DetailThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function deleteAction(): Action
->authorize('delete', $this->thread)
->requiresConfirmation()
->action(function (): void {

app(DeleteThreadAction::class)->execute($this->thread);

$this->redirectRoute('forum.index', navigate: true);
Expand Down
1 change: 1 addition & 0 deletions lang/en/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
'unban' => 'Cancel ban',
'confirm' => 'Confirm',
'start' => 'Start',
'view' => 'View',

];
4 changes: 2 additions & 2 deletions lang/en/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
'launch_modal' => [
'forum_action' => 'Create thread',
'forum_description' => 'Do you have a question? Ask it in the forum',
'post_action' => 'Writing an article',
'post_description' => 'Share your discoveries with thousands of developers',
'article_action' => 'Writing an article',
'article_description' => 'Share your discoveries with thousands of developers',
'discussion_action' => 'Start a discussion',
'discussion_description' => 'Discuss and debate different themes and ideas',
],
Expand Down
1 change: 1 addition & 0 deletions lang/en/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'created' => 'Your article has been created.',
'submitted' => 'Thank you for submitting your article. We will only contact you once we have accepted your article.',
'updated' => 'Your article has been updated.',
'deleted' => 'Your article has been deleted.',
],

'thread' => [
Expand Down
4 changes: 3 additions & 1 deletion lang/en/pages/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'next_article' => 'Next article',
'prev_article' => 'Previous article',
'share_article' => 'Share',
'new_article' => 'Write a new article',
'advice' => [
'title' => 'Important advices for articles',
'content' => 'Submit your article to the Laravel.cm portal. We\'re looking for high quality articles revolving around Laravel, PHP, JavaScript, CSS, and related topics. Articles can\'t be promotional in nature and should be educational and informative. We reserve the right to decline articles that don\'t meet our quality standards.',
Expand All @@ -27,5 +26,8 @@
'canonical_help' => 'If you have already posted this article on your own site, enter the URL here and the content will be attributed to you.',
'draft_help' => 'Putting an article in draft allows you to update it later.',
'unpublished' => 'This article has not yet been published.',
'draft' => 'Draft',
'my_article' => 'My articles',
'not_article_created' => "You haven't created any articles yet",

];
1 change: 1 addition & 0 deletions lang/en/pages/discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
],
'min_discussion_length' => '160 characters maximum',
'placeholder' => 'Your comment here...',
'my_discussion' => 'My discussions',

];
3 changes: 3 additions & 0 deletions lang/en/pages/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
'min_thread_length' => '10 characters minimum',
'answer_reply' => 'Answer to',
'threads_count' => ':count messages',
'my_thread' => 'My threads',
'not_thread_created' => "You haven't created any topic yet",
'subject' => 'Subject',

];
2 changes: 1 addition & 1 deletion lang/fr/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
'unban' => 'Dé-bannir',
'confirm' => 'Confirmer',
'start' => 'Démarrer',

'view' => 'Voir',
];
1 change: 1 addition & 0 deletions lang/fr/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'created' => 'Votre article a été crée.',
'submitted' => 'Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.',
'updated' => 'Votre article a été mis à jour.',
'deleted' => 'Votre article a été supprimé.',
],

'thread' => [
Expand Down
4 changes: 3 additions & 1 deletion lang/fr/pages/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'next_article' => 'Article suivant',
'prev_article' => 'Article précédent',
'share_article' => 'Partager',
'new_article' => 'Rédiger un article',
'advice' => [
'title' => 'Conseils importants concernant les articles',
'content' => 'Soumettez votre article au site Laravel.cm. Nous recherchons des articles de haute qualité autour de Laravel, PHP, JavaScript, CSS et autres sujets connexes. Les articles ne peuvent pas être de nature promotionnelle et doivent être éducatifs et informatifs. Nous nous réservons le droit de refuser les articles qui ne répondent pas à nos critères de qualité.',
Expand All @@ -27,5 +26,8 @@
'canonical_help' => 'Précisez si l\'article a été publié pour la première fois ailleurs (comme sur votre propre blog).',
'draft_help' => 'Mettre en article en brouillon vous donne la possibilité de le modifier plus tard',
'unpublished' => 'Cet article n\'a pas encore été publié.',
'draft' => 'Brouillon',
'my_article' => 'Mes articles',
'not_article_created' => "Vous n'avez pas encore créé d'articles",

];
Loading
Loading