Skip to content

Commit 85b8f15

Browse files
committed
Add subscription toggle handling and refresh logic to SubscriptionSidebar component
1 parent 5ab8788 commit 85b8f15

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/Livewire/Concerns/HasSidebar.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Kirschbaum\Commentions\Config;
88
use Kirschbaum\Commentions\Contracts\Commenter;
99
use Livewire\Attributes\Computed;
10-
use Livewire\Attributes\On;
1110
use Livewire\Attributes\Renderless;
1211

1312
trait HasSidebar
@@ -61,6 +60,13 @@ public function subscribers(): Collection
6160
return $this->record->getSubscribers();
6261
}
6362

63+
#[Renderless]
64+
public function refreshSubscribers(): void
65+
{
66+
unset($this->isSubscribed);
67+
unset($this->subscribers);
68+
}
69+
6470
#[Renderless]
6571
public function toggleSubscription(): void
6672
{
@@ -86,15 +92,9 @@ public function toggleSubscription(): void
8692
->send();
8793
}
8894

89-
unset($this->isSubscribed);
90-
unset($this->subscribers);
91-
}
95+
$this->refreshSubscribers();
9296

93-
#[On('commentions:subscription:toggled')]
94-
public function handleExternalSubscriptionToggle(): void
95-
{
96-
unset($this->isSubscribed);
97-
unset($this->subscribers);
97+
$this->dispatch('commentions:subscription:toggled')->to('commentions::subscription-sidebar');
9898
}
9999

100100
protected function getCurrentUser(): ?Commenter

src/Livewire/SubscriptionSidebar.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Eloquent\Model;
66
use Kirschbaum\Commentions\Livewire\Concerns\HasSidebar;
7+
use Livewire\Attributes\On;
78
use Livewire\Component;
89

910
class SubscriptionSidebar extends Component
@@ -18,6 +19,12 @@ public function mount(Model $record, ?bool $showSubscribers = null): void
1819
$this->mountHasSidebar(true, $showSubscribers);
1920
}
2021

22+
#[On('commentions:subscription:toggled')]
23+
public function handleExternalSubscriptionToggle(): void
24+
{
25+
$this->refreshSubscribers();
26+
}
27+
2128
public function render()
2229
{
2330
return view('commentions::subscription-sidebar');

0 commit comments

Comments
 (0)