Skip to content

Commit fa498dc

Browse files
committed
Add some missing events and clean up post.card component
1 parent c527dc7 commit fa498dc

File tree

13 files changed

+50
-73
lines changed

13 files changed

+50
-73
lines changed

src/Events/UserBulkManagedCategories.php renamed to src/Events/UserBulkReorderedCategories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use TeamTeaTime\Forum\Events\Types\BaseEvent;
66

7-
class UserBulkManagedCategories extends BaseEvent
7+
class UserBulkReorderedCategories extends BaseEvent
88
{
99
/** @var mixed */
1010
public $user;

src/Events/UserManagingCategories.php renamed to src/Events/UserReorderingCategories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use TeamTeaTime\Forum\Events\Types\BaseEvent;
66

7-
class UserManagingCategories extends BaseEvent
7+
class UserReorderingCategories extends BaseEvent
88
{
99
/** @var mixed */
1010
public $user;

src/Http/Livewire/Pages/CategoryCreate.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public function mount(Request $request)
5050
$this->parent_category = $this->parent_id;
5151
}
5252

53-
if ($request->user() !== null) {
54-
UserCreatingCategory::dispatch($request->user());
55-
}
53+
UserCreatingCategory::dispatch($request->user());
5654
}
5755

5856
public function create(Request $request)

src/Http/Livewire/Pages/CategoryEdit.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Livewire\Component;
1111
use TeamTeaTime\Forum\{
1212
Actions\EditCategory,
13+
Events\UserDeletedCategory,
1314
Events\UserEditingCategory,
1415
Events\UserEditedCategory,
1516
Models\Category,
@@ -54,9 +55,7 @@ public function mount(Request $request)
5455
$this->accepts_threads = $category->accepts_threads;
5556
$this->is_private = $category->is_private;
5657

57-
if ($request->user() !== null) {
58-
UserEditingCategory::dispatch($request->user(), $category);
59-
}
58+
UserEditingCategory::dispatch($request->user(), $category);
6059
}
6160

6261
public function save(Request $request)
@@ -88,6 +87,8 @@ public function delete(Request $request)
8887

8988
$this->category->delete();
9089

90+
UserDeletedCategory::dispatch($request->user(), $this->category);
91+
9192
return $this->redirect(Forum::route('category.index'));
9293
}
9394

src/Http/Livewire/Pages/CategoryShow.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Actions\Bulk\UnpinThreads,
1818
Events\UserBulkDeletedThreads,
1919
Events\UserBulkLockedThreads,
20+
Events\UserBulkMovedThreads,
2021
Events\UserBulkPinnedThreads,
2122
Events\UserBulkRestoredThreads,
2223
Events\UserBulkUnlockedThreads,
@@ -121,6 +122,10 @@ public function moveThreads(Request $request, array $threadIds, int $destination
121122
$action = new MoveThreads($threadIds, $destination, $request->user()->can('viewTrashedThreads'));
122123
$result = $action->execute();
123124

125+
if ($result !== null) {
126+
UserBulkMovedThreads::dispatch($request->user(), $result);
127+
}
128+
124129
return $this->handleActionResult($result);
125130
}
126131

src/Http/Livewire/Pages/PostEdit.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public function mount(Request $request)
3535
abort(404);
3636
}
3737

38-
if ($request->user() !== null) {
39-
UserEditingPost::dispatch($request->user(), $request->route('post'));
40-
}
38+
UserEditingPost::dispatch($request->user(), $request->route('post'));
4139
}
4240

4341
public function save(Request $request)
@@ -53,8 +51,6 @@ public function save(Request $request)
5351

5452
UserEditedPost::dispatch($request->user(), $post);
5553

56-
$route = $post->route;
57-
5854
return $this->redirect($post->route);
5955
}
6056

src/Http/Livewire/Pages/ThreadCreate.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Livewire\Component;
1010
use TeamTeaTime\Forum\{
1111
Actions\CreateThread as Action,
12+
Events\UserCreatingThread,
1213
Events\UserCreatedThread,
1314
Support\Authorization\CategoryAuthorization,
1415
Support\Validation\ThreadRules,
@@ -30,6 +31,8 @@ public function mount(Request $request)
3031
{
3132
$this->category = $request->route('category');
3233
$this->breadcrumbs_append = [trans('forum::threads.new_thread')];
34+
35+
UserCreatingThread::dispatch($request->user(), $this->category);
3336
}
3437

3538
public function create(Request $request)

src/Http/Livewire/Pages/ThreadReply.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
use Livewire\Attributes\Locked;
99
use Livewire\Component;
1010
use TeamTeaTime\Forum\{
11-
Actions\CreatePost as Action,
12-
Events\UserCreatedPost,
1311
Events\UserCreatingPost,
12+
Http\Livewire\Forms\ThreadReplyForm,
1413
Http\Livewire\Traits\CreatesAlerts,
1514
Http\Livewire\Traits\UpdatesContent,
1615
Models\Post,
1716
Models\Thread,
18-
Support\Validation\PostRules,
1917
};
2018

2119
class ThreadReply extends Component
@@ -28,8 +26,7 @@ class ThreadReply extends Component
2826
#[Locked]
2927
public ?Post $parent = null;
3028

31-
// Form fields
32-
public string $content = '';
29+
public ThreadReplyForm $form;
3330

3431
public function mount(Request $request)
3532
{
@@ -43,26 +40,12 @@ public function mount(Request $request)
4340
$this->parent = $this->thread->posts->find($request->input('parent_id'));
4441
}
4542

46-
if ($request->user() !== null) {
47-
UserCreatingPost::dispatch($request->user(), $this->thread);
48-
}
43+
UserCreatingPost::dispatch($request->user(), $this->thread);
4944
}
5045

5146
public function reply(Request $request)
5247
{
53-
if (!$request->user()->can('reply', $this->thread)) {
54-
abort(403);
55-
}
56-
57-
$validated = $this->validate(PostRules::create());
58-
$action = new Action($this->thread, $this->parent, $request->user(), $validated['content']);
59-
$post = $action->execute();
60-
61-
$post->thread->markAsRead($request->user());
62-
63-
UserCreatedPost::dispatch($request->user(), $post);
64-
65-
$this->content = "";
48+
$post = $this->threadReplyForm->reply($request, $this->thread);
6649

6750
return redirect($post->route);
6851
}

src/Http/Livewire/Pages/ThreadShow.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use TeamTeaTime\Forum\{
99
Actions\Bulk\DeletePosts,
1010
Actions\Bulk\RestorePosts,
11+
Events\UserBulkDeletedPosts,
12+
Events\UserBulkRestoredPosts,
1113
Events\UserViewingThread,
1214
Http\Livewire\Forms\ThreadEditForm,
1315
Http\Livewire\Forms\ThreadReplyForm,
@@ -18,7 +20,6 @@
1820
Models\Thread,
1921
Support\Access\CategoryAccess,
2022
Support\Authorization\PostAuthorization,
21-
Support\Validation\PostRules,
2223
Support\Traits\HandlesDeletion,
2324
};
2425

@@ -130,11 +131,15 @@ public function deletePosts(Request $request, array $postIds, bool $permadelete)
130131
}
131132

132133
$action = new DeletePosts($postIds, $this->shouldPermaDelete($permadelete));
133-
$action->execute();
134+
$result = $action->execute();
134135

135136
$this->touchUpdateKey();
136137

137-
return $this->pluralAlert('threads.deleted')->toLivewire();
138+
if ($result !== null) {
139+
UserBulkDeletedPosts::dispatch($request->user(), $result);
140+
}
141+
142+
return $this->pluralAlert('posts.deleted', $result->count())->toLivewire();
138143
}
139144

140145
public function restorePosts(Request $request, array $postIds): array
@@ -144,11 +149,15 @@ public function restorePosts(Request $request, array $postIds): array
144149
}
145150

146151
$action = new RestorePosts($postIds);
147-
$action->execute();
152+
$result = $action->execute();
148153

149154
$this->touchUpdateKey();
150155

151-
return $this->pluralAlert('threads.restored')->toLivewire();
156+
if ($result !== null) {
157+
UserBulkRestoredPosts::dispatch($request->user(), $result);
158+
}
159+
160+
return $this->pluralAlert('posts.restored', $result->count())->toLivewire();
152161
}
153162

154163
public function render(Request $request): View

src/Http/Livewire/Pages/UnreadThreads.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\View\View;
99
use Livewire\Component;
1010
use TeamTeaTime\Forum\{
11+
Events\UserMarkedThreadsAsRead,
1112
Events\UserViewingUnread,
1213
Http\Livewire\Traits\CreatesAlerts,
1314
Http\Livewire\Traits\UpdatesContent,
@@ -47,16 +48,16 @@ public function markAsRead(Request $request): array
4748

4849
$this->touchUpdateKey();
4950

51+
UserMarkedThreadsAsRead::dispatch($request->user(), $threads);
52+
5053
return $this->alert('threads.marked_read')->toLivewire();
5154
}
5255

5356
public function render(Request $request): View
5457
{
5558
$threads = $this->getThreads($request);
5659

57-
if ($request->user() !== null) {
58-
UserViewingUnread::dispatch($request->user(), $threads);
59-
}
60+
UserViewingUnread::dispatch($request->user(), $threads);
6061

6162
return ViewFactory::make('forum::pages.thread.unread', [
6263
'threads' => $threads,

0 commit comments

Comments
 (0)