Skip to content

Commit 37148c1

Browse files
author
Marc Geurts
committed
Migrated listeners to Livewire 4
1 parent 7c93388 commit 37148c1

File tree

15 files changed

+52
-44
lines changed

15 files changed

+52
-44
lines changed

resources/views/components/livewire/people/add/⚡child/child.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Livewire\Traits\TrimStringsAndConvertEmptyStringsToNull;
99
use App\Models\Person;
1010
use Illuminate\Support\Collection;
11+
use Livewire\Attributes\On;
1112
use Livewire\Component;
1213
use Livewire\WithFileUploads;
1314
use TallStackUi\Traits\Interactions;
@@ -29,8 +30,11 @@
2930

3031
public ?string $selectedTab = null;
3132

33+
#[On('person_added_as_child')]
3234
public function mount(): void
3335
{
36+
$this->form->reset();
37+
3438
$this->persons = Person::where('id', '!=', $this->person->id)
3539
->whereNull($this->person->sex === 'm' ? 'father_id' : 'mother_id')
3640
->youngerThan($this->person->dob, $this->person->yob)
@@ -56,7 +60,7 @@ public function saveChild(): void
5660
$this->createNewChild($validated['form']);
5761
}
5862

59-
$this->redirect(route('people.show', $this->person->id));
63+
$this->dispatch('person_added_as_child');
6064
}
6165

6266
/**

resources/views/components/livewire/people/add/⚡father/father.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function saveFather(): void
5757
$this->createNewFather($validated['form']);
5858
}
5959

60-
$this->redirect(route('people.show', $this->person->id));
60+
$this->dispatch('father_added');
6161
}
6262

6363
/**

resources/views/components/livewire/people/add/⚡mother/mother.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function saveMother(): void
5757
$this->createNewMother($validated['form']);
5858
}
5959

60-
$this->redirect(route('people.show', $this->person->id));
60+
$this->dispatch('mother_added');
6161
}
6262

6363
/**

resources/views/components/livewire/people/add/⚡partner/partner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function savePartner(): void
7777
$this->createNewPartner($validated);
7878
}
7979

80-
$this->redirect(route('people.show', $this->person->id));
80+
$this->dispatch('couple_added');
8181
}
8282

8383
/**

resources/views/components/livewire/people/add/⚡person/person.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
public PersonForm $form;
2323

24-
public function mount(): void {}
25-
2624
public function savePerson(): void
2725
{
2826
$user = auth()->user();

resources/views/components/livewire/people/edit/⚡family/family.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function saveFamily(): void
7272

7373
$this->toast()->success(__('app.save'), __('app.saved'))->send();
7474

75-
$this->redirect('/people/' . $this->person->id);
75+
$this->dispatch('family_updated');
7676
}
7777

7878
// -----------------------------------------------------------------------

resources/views/components/livewire/people/edit/⚡partner/partner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@ public function savePartner(): void
6363
'date_start' => $validated['date_start'] ?? null,
6464
'date_end' => $validated['date_end'] ?? null,
6565
'is_married' => $validated['is_married'],
66-
'has_ended' => $validated['date_end'] or $validated['has_ended'],
66+
'has_ended' => $validated['date_end'] || $validated['has_ended'],
6767
]);
6868
} elseif ($this->person->id === $this->couple->person2_id) {
6969
$this->couple->update([
7070
'person1_id' => $validated['partner_id'],
7171
'date_start' => $validated['date_start'] ?? null,
7272
'date_end' => $validated['date_end'] ?? null,
7373
'is_married' => $validated['is_married'],
74-
'has_ended' => $validated['date_end'] or $validated['has_ended'],
74+
'has_ended' => $validated['date_end'] || $validated['has_ended'],
7575
]);
7676
}
7777

7878
$this->toast()->success(__('app.save'), __('app.saved'))->send();
7979

80-
$this->redirect('/people/' . $this->person->id);
80+
$this->dispatch('couple_updated');
8181
}
8282

8383
// -----------------------------------------------------------------------

resources/views/components/livewire/people/edit/⚡profile/profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function saveProfile(): void
6969

7070
$this->toast()->success(__('app.save'), __('app.saved'))->send();
7171

72-
$this->redirect('/people/' . $this->person->id);
72+
$this->dispatch('person_updated');
7373
}
7474

7575
// -----------------------------------------------------------------------

resources/views/components/livewire/people/⚡children/children.php

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

55
use App\Models\Person;
66
use Illuminate\Support\Collection;
7+
use Livewire\Attributes\On;
78
use Livewire\Component;
89
use TallStackUi\Traits\Interactions;
910

@@ -19,6 +20,7 @@
1920
public Collection $children;
2021

2122
// ------------------------------------------------------------------------------
23+
#[On('person_added_as_child')]
2224
public function mount(): void
2325
{
2426
$this->children = $this->person->childrenNaturalAll();
@@ -48,6 +50,6 @@ public function disconnect(int $child_id): void
4850

4951
$this->toast()->success(__('app.disconnect'), e($child->name) . ' ' . __('app.disconnected') . '.')->send();
5052

51-
$this->redirect(route('people.show', $this->person->id));
53+
$this->dispatch('person_added_as_child');
5254
}
5355
};

resources/views/components/livewire/people/⚡family/family.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

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

89
new class extends Component
@@ -11,8 +12,14 @@
1112
public Person $person;
1213

1314
// ------------------------------------------------------------------------------
14-
/** @var array<string, string> */
15-
protected $listeners = [
16-
'couple_deleted' => 'render',
17-
];
15+
#[On('couple_added')]
16+
#[On('couple_deleted')]
17+
#[On('family_updated')]
18+
#[On('father_added')]
19+
#[On('mother_added')]
20+
public function refreshFamily(): void
21+
{
22+
// optionally refresh any data here
23+
// Livewire will re-render automatically
24+
}
1825
};

0 commit comments

Comments
 (0)