Skip to content

Commit 247823a

Browse files
committed
Refactor subscription actions to improve notification handling and sidebar updates
1 parent eaf5513 commit 247823a

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/Filament/Actions/SubscriptionAction.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ protected function setUp(): void
2525
return;
2626
}
2727

28-
$this->success($subscribed ? 'Subscribed to notifications' : 'Unsubscribed from notifications');
28+
$this->successNotificationTitle(
29+
$subscribed ? 'Subscribed to notifications' : 'Unsubscribed from notifications'
30+
);
31+
32+
$this->success();
33+
34+
// Ask any listening components (like the sidebar) to refresh
35+
/** @var \Livewire\Component|null $livewire */
36+
$livewire = $this->getLivewire();
37+
$livewire?->dispatch('commentions:subscription:toggled')->to('commentions::subscription-sidebar');
2938
})
3039
->requiresConfirmation(false);
3140
}

src/Filament/Actions/SubscriptionTableAction.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ protected function setUp(): void
2525
return;
2626
}
2727

28-
$this->success($subscribed ? 'Subscribed to notifications' : 'Unsubscribed from notifications');
28+
$this->successNotificationTitle(
29+
$subscribed ? 'Subscribed to notifications' : 'Unsubscribed from notifications'
30+
);
31+
32+
$this->success();
33+
34+
// Ask any listening components (like the sidebar) to refresh
35+
/** @var \Livewire\Component|null $livewire */
36+
$livewire = $this->getLivewire();
37+
$livewire?->dispatch('commentions:subscription:toggled')->to('commentions::subscription-sidebar');
2938
})
3039
->requiresConfirmation(false);
3140
}

src/Livewire/Concerns/HasSidebar.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Kirschbaum\Commentions\Contracts\Commenter;
99
use Livewire\Attributes\Computed;
1010
use Livewire\Attributes\Renderless;
11+
use Livewire\Attributes\On;
1112

1213
trait HasSidebar
1314
{
@@ -89,6 +90,13 @@ public function toggleSubscription(): void
8990
unset($this->subscribers);
9091
}
9192

93+
#[On('commentions:subscription:toggled')]
94+
public function handleExternalSubscriptionToggle(): void
95+
{
96+
unset($this->isSubscribed);
97+
unset($this->subscribers);
98+
}
99+
92100
protected function getCurrentUser(): ?Commenter
93101
{
94102
return Config::resolveAuthenticatedUser();

0 commit comments

Comments
 (0)