fix: close profile editor on save, reactively update period tracker
Profile editor closes on successful save. Period tracker visibility uses a reactive savedSex state variable that updates on save, so changing sex to female/male immediately shows/hides the tracker without requiring a page refresh.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
let showWeightHistory = $state(false);
|
let showWeightHistory = $state(false);
|
||||||
|
|
||||||
// Profile fields (sex, height, birth year) — stored in FitnessGoal
|
// Profile fields (sex, height, birth year) — stored in FitnessGoal
|
||||||
|
let savedSex = $state(data.profile?.sex ?? 'male');
|
||||||
let profileSex = $state(data.profile?.sex ?? 'male');
|
let profileSex = $state(data.profile?.sex ?? 'male');
|
||||||
let profileHeight = $state(data.profile?.heightCm != null ? String(data.profile.heightCm) : '');
|
let profileHeight = $state(data.profile?.heightCm != null ? String(data.profile.heightCm) : '');
|
||||||
let profileBirthYear = $state(data.profile?.birthYear != null ? String(data.profile.birthYear) : '');
|
let profileBirthYear = $state(data.profile?.birthYear != null ? String(data.profile.birthYear) : '');
|
||||||
@@ -60,6 +61,8 @@
|
|||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const d = await res.json();
|
const d = await res.json();
|
||||||
data.profile = d;
|
data.profile = d;
|
||||||
|
savedSex = d.sex ?? profileSex;
|
||||||
|
profileEditing = false;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
profileSaving = false;
|
profileSaving = false;
|
||||||
@@ -224,7 +227,7 @@
|
|||||||
</section>
|
</section>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if data.profile?.sex === 'female'}
|
{#if savedSex === 'female'}
|
||||||
<PeriodTracker periods={data.periods ?? []} {lang} sharedWith={data.periodSharedWith ?? []} />
|
<PeriodTracker periods={data.periods ?? []} {lang} sharedWith={data.periodSharedWith ?? []} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user