Skip to content

Commit 9fca836

Browse files
Merge pull request #1476 from liberu-genealogy/copilot/upgrade-livewire-3-to-livewire-4
[WIP] Upgrade syntax from Livewire 3 to Livewire 4
2 parents a01798b + 243a3ea commit 9fca836

24 files changed

+94
-96
lines changed

app/Http/Livewire/DescendantChartComponent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public function setRootPerson($personId): void
8282
{
8383
$this->rootPersonId = $personId;
8484
$this->mount($personId);
85-
$this->emit('refreshDescendantChart');
85+
$this->dispatch('refreshDescendantChart');
8686
}
8787

8888
public function setGenerations($generations): void
8989
{
9090
$this->generations = max(1, min(6, $generations));
9191
$this->mount($this->rootPersonId);
92-
$this->emit('refreshDescendantChart');
92+
$this->dispatch('refreshDescendantChart');
9393
}
9494

9595
public function render()

app/Http/Livewire/DescendantChartWidget.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,43 +130,43 @@ private function buildDescendantTree($person, $maxGenerations, $generation = 1):
130130
public function setRootPerson($personId): void
131131
{
132132
$this->rootPersonId = $personId;
133-
$this->emit('refreshDescendantChart');
133+
$this->dispatch('refreshDescendantChart');
134134
}
135135

136136
public function setGenerations($generations): void
137137
{
138138
$this->generations = max(1, min(8, $generations));
139-
$this->emit('refreshDescendantChart');
139+
$this->dispatch('refreshDescendantChart');
140140
}
141141

142142
public function toggleSpouses(): void
143143
{
144144
$this->showSpouses = !$this->showSpouses;
145-
$this->emit('refreshDescendantChart');
145+
$this->dispatch('refreshDescendantChart');
146146
}
147147

148148
public function toggleDates(): void
149149
{
150150
$this->showDates = !$this->showDates;
151-
$this->emit('refreshDescendantChart');
151+
$this->dispatch('refreshDescendantChart');
152152
}
153153

154154
public function togglePhotos(): void
155155
{
156156
$this->showPhotos = !$this->showPhotos;
157-
$this->emit('refreshDescendantChart');
157+
$this->dispatch('refreshDescendantChart');
158158
}
159159

160160
public function setLayout($layout): void
161161
{
162162
$this->layout = $layout;
163-
$this->emit('refreshDescendantChart');
163+
$this->dispatch('refreshDescendantChart');
164164
}
165165

166166
public function setColorScheme($scheme): void
167167
{
168168
$this->colorScheme = $scheme;
169-
$this->emit('refreshDescendantChart');
169+
$this->dispatch('refreshDescendantChart');
170170
}
171171

172172
public function expandPerson($personId): void

app/Http/Livewire/EditProfile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function updateProfile(): void
3131

3232
try {
3333
Auth::user()?->update($validated);
34-
$this->emit('profile-updated');
34+
$this->dispatch('profile-updated');
3535
} catch (Throwable $e) {
36-
$this->emit('profile-update-failed', message: $e->getMessage());
36+
$this->dispatch('profile-update-failed', message: $e->getMessage());
3737
throw $e;
3838
}
3939
}

app/Http/Livewire/FamilyTreeBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function updatePersonPosition(int $personId, float $x, float $y): void
4747
'tree_position_y' => $y
4848
]);
4949

50-
$this->emit('positionUpdated', personId: $personId);
50+
$this->dispatch('positionUpdated', personId: $personId);
5151
}
5252

5353
#[On('personAdded')]
@@ -63,15 +63,15 @@ public function addPerson(array $data): void
6363
]);
6464

6565
$this->loadTreeData();
66-
$this->emit('personCreated', personId: $person->id);
66+
$this->dispatch('personCreated', personId: $person->id);
6767
}
6868

6969
#[On('personRemoved')]
7070
public function removePerson(int $personId): void
7171
{
7272
Person::find($personId)?->delete();
7373
$this->loadTreeData();
74-
$this->emit('personDeleted', personId: $personId);
74+
$this->dispatch('personDeleted', personId: $personId);
7575
}
7676

7777
public function render()

app/Http/Livewire/FanChart.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,31 @@ private function buildFanData($person, $maxGenerations, $generation = 0): array
7979
public function setRootPerson($personId): void
8080
{
8181
$this->rootPersonId = $personId;
82-
$this->emit('refreshFanChart');
82+
$this->dispatch('refreshFanChart');
8383
}
8484

8585
public function setGenerations($generations): void
8686
{
8787
$this->generations = max(2, min(8, $generations));
88-
$this->emit('refreshFanChart');
88+
$this->dispatch('refreshFanChart');
8989
}
9090

9191
public function toggleNames(): void
9292
{
9393
$this->showNames = !$this->showNames;
94-
$this->emit('refreshFanChart');
94+
$this->dispatch('refreshFanChart');
9595
}
9696

9797
public function toggleDates(): void
9898
{
9999
$this->showDates = !$this->showDates;
100-
$this->emit('refreshFanChart');
100+
$this->dispatch('refreshFanChart');
101101
}
102102

103103
public function setColorScheme($scheme): void
104104
{
105105
$this->colorScheme = $scheme;
106-
$this->emit('refreshFanChart');
106+
$this->dispatch('refreshFanChart');
107107
}
108108

109109
public function render()

app/Http/Livewire/GamificationDashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function toggleLeaderboardVisibility()
5656
{
5757
$user = auth()->user();
5858
$user->update(['show_on_leaderboard' => !$user->show_on_leaderboard]);
59-
$this->emit('leaderboard-updated');
59+
$this->dispatch('leaderboard-updated');
6060
}
6161

6262
public function render()

app/Http/Livewire/PedigreeChart.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,25 @@ public function render()
8181
public function setRootPerson($personId): void
8282
{
8383
$this->rootPersonId = $personId;
84-
$this->emit('refreshChart');
84+
$this->dispatch('refreshChart');
8585
}
8686

8787
public function setGenerations($generations): void
8888
{
8989
$this->generations = max(1, min(6, $generations));
90-
$this->emit('refreshChart');
90+
$this->dispatch('refreshChart');
9191
}
9292

9393
public function toggleDates(): void
9494
{
9595
$this->showDates = !$this->showDates;
96-
$this->emit('refreshChart');
96+
$this->dispatch('refreshChart');
9797
}
9898

9999
public function togglePhotos(): void
100100
{
101101
$this->showPhotos = !$this->showPhotos;
102-
$this->emit('refreshChart');
102+
$this->dispatch('refreshChart');
103103
}
104104

105105
public function expandPerson($personId): void

app/Http/Livewire/PeopleSearch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
namespace App\Http\Livewire;
44

55
use App\Models\Person;
6+
use Livewire\Attributes\On;
67
use Livewire\Component;
78

89
class PeopleSearch extends Component
910
{
1011
public $query = '';
1112
public $results = [];
1213

13-
protected $listeners = ['updatedQuery' => 'searchPeople'];
14-
1514
public function mount(): void
1615
{
1716
$this->searchPeople();
1817
}
1918

19+
#[On('updatedQuery')]
2020
public function searchPeople(): void
2121
{
2222
try {

app/Http/Livewire/ResearchSpace/CollaboratorBoard.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Livewire\ResearchSpace;
44

5+
use Livewire\Attributes\On;
56
use Livewire\Component;
67
use App\Models\ResearchSpace;
78
use App\Events\ResearchSpaceUpdated;
@@ -12,16 +13,14 @@ class CollaboratorBoard extends Component
1213
use AuthorizesRequests;
1314

1415
public ResearchSpace $space;
16+
public int $spaceId = 0;
1517
public $content = '';
1618
public $userPermissions = [];
1719

18-
protected $listeners = [
19-
'echo:research-space.{spaceId},ResearchSpaceUpdated' => 'onExternalUpdate',
20-
];
21-
2220
public function mount($spaceId)
2321
{
2422
$this->space = ResearchSpace::with('collaborators.user')->findOrFail($spaceId);
23+
$this->spaceId = $this->space->id;
2524

2625
$this->authorize('view', $this->space);
2726

@@ -30,12 +29,10 @@ public function mount($spaceId)
3029
$this->userPermissions = []; // can be populated from collaborators
3130
}
3231

33-
public function saveContent(string $updated)
32+
public function saveContent()
3433
{
3534
$this->authorize('update', $this->space);
3635

37-
$this->content = $updated;
38-
3936
$settings = $this->space->settings ?? [];
4037
$settings['board'] = array_merge($settings['board'] ?? [], ['content' => $this->content, 'updated_at' => now()->toDateTimeString()]);
4138
$this->space->settings = $settings;
@@ -45,11 +42,12 @@ public function saveContent(string $updated)
4542
event(new ResearchSpaceUpdated($this->space->id, ['content' => $this->content, 'user_id' => auth()->id()]));
4643
}
4744

45+
#[On('echo:research-space.{spaceId},ResearchSpaceUpdated')]
4846
public function onExternalUpdate($payload)
4947
{
5048
// When we get an external broadcast, update local content
5149
$this->content = data_get($payload, 'content', $this->content);
52-
$this->emitSelf('contentUpdated');
50+
$this->dispatch('contentUpdated');
5351
}
5452

5553
public function render()

app/Http/Livewire/TimelineComponent.php

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

33
namespace App\Http\Livewire;
44

5+
use Livewire\Attributes\On;
56
use Livewire\Component;
67
use App\Models\Person;
78
use App\Services\HistoricalEventService;
@@ -12,10 +13,6 @@ class TimelineComponent extends Component
1213
public array $events = [];
1314
public ?array $selectedEvent = null;
1415

15-
protected $listeners = [
16-
'timelineItemClicked' => 'openEventFromJs',
17-
];
18-
1916
protected HistoricalEventService $historicalEventService;
2017

2118
public function boot(HistoricalEventService $historicalEventService)
@@ -102,9 +99,10 @@ public function loadEvents($start = null, $end = null)
10299
}
103100

104101
/**
105-
* JS calls Livewire via window.Livewire.emit('timelineItemClicked', id)
102+
* JS calls Livewire via Livewire.dispatch('timelineItemClicked', { id: '...' })
106103
*/
107-
public function openEventFromJs($id)
104+
#[On('timelineItemClicked')]
105+
public function openEventFromJs(string $id)
108106
{
109107
$item = collect($this->events)->firstWhere('id', $id);
110108
if ($item) {

0 commit comments

Comments
 (0)