Skip to content

Commit 2f26ae5

Browse files
authored
Merge pull request #31 from dorianim/fix/binding-loop-regression
Fix: regression which caused binding loop in timer editor
2 parents 287db7d + 4d56a3d commit 2f26ae5

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

web/src/routes/manage/[id]/edit/+page.svelte

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@
1818
if (browser && !localStorage.getItem('token')) goto('/manage/login');
1919
}
2020
21-
const onSubmit = async (newTimerData: TimerUpdateRequest) => {
22-
submitResult = updateTimer(
23-
timerData.id,
24-
newTimerData,
25-
localStorage.getItem('token')!,
26-
fetch
27-
).then((timer: Timer) => {
28-
timerData = timer;
29-
goto(`/manage/${timerData.id}`);
30-
return timer;
31-
});
21+
const onSubmit = async () => {
22+
submitResult = updateTimer(timerData.id, timerData, localStorage.getItem('token')!, fetch).then(
23+
(timer: Timer) => {
24+
timerData = timer;
25+
goto(`/manage/${timerData.id}`);
26+
return timer;
27+
}
28+
);
3229
};
3330
</script>
3431

@@ -52,7 +49,7 @@
5249
>
5350
</aside>
5451
{/if}
55-
<TimerForm {timerData} {onSubmit} />
52+
<TimerForm bind:timerData {onSubmit} />
5653
<ImportExport bind:timerData {data} />
5754
{:catch error}
5855
<div class="alert variant-ghost-error">

web/src/routes/manage/[id]/edit/TimerForm.svelte

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,11 @@
3030
}
3131
3232
export let timerData: Timer;
33-
export let onSubmit: (timerData: Timer) => void;
33+
export let onSubmit: () => void;
3434
3535
let formData: TimerFormData;
3636
let editingSegment: number | undefined = undefined;
3737
38-
const handleSubmit = () => {
39-
onSubmit(formDataToTimerData(formData));
40-
};
41-
4238
const timerDataToFormData = (timerData: Timer): TimerFormData => {
4339
return {
4440
start_at_date: new Date(timerData.start_at).toISOString().split('T')[0],
@@ -72,7 +68,16 @@
7268
}
7369
};
7470
75-
$: formData = timerDataToFormData(timerData);
71+
const updateFormData = (timerData: Timer) => {
72+
formData = timerDataToFormData(timerData);
73+
};
74+
75+
const updateTimerData = (formData: TimerFormData) => {
76+
timerData = formDataToTimerData(formData);
77+
};
78+
79+
$: updateFormData(timerData);
80+
$: updateTimerData(formData);
7681
7782
const precisionLabel = ['none', 'low', 'medium', 'high', 'very high'];
7883
</script>
@@ -267,7 +272,7 @@
267272
current time on the timer <b class="text-[#E01B24]">WILL CHANGE</b> as soon as you save!
268273
</p>
269274

270-
<button class="btn variant-filled-secondary" on:click={handleSubmit}>
275+
<button class="btn variant-filled-secondary" on:click={onSubmit}>
271276
<span><Fa icon={faSave} /></span><span>Save</span>
272277
</button>
273278
</form>

0 commit comments

Comments
 (0)