Symptom: clicking + Add time would insert the new entry sorted into
the list, hiding it among the existing rows. Editing an existing
row's hour/minute/AM-PM moved the row mid-keystroke.
Both behaviors made the user lose track of what they were editing.
The list now only sorts at save time (which the backend already
canonicalizes via setWakeTimes()). New entries land at the end,
edits stay in place. Two regression tests pin this:
- + Add appends; the new row is the last DOM row even when its
minutes-of-day are smaller than an existing entry.
- Editing a row's hour from 9 to 1 keeps the row at the same
index (would have moved to index 0 under the old sort-on-edit).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -506,17 +506,21 @@ const DEFAULT_TIME_CANDIDATES = [
|
||||
0, // 12:00 AM
|
||||
]
|
||||
|
||||
// Appends to the end of the list — never sorts mid-edit. Sorting a row away
|
||||
// from where the user just clicked is disorienting; they lose track of "the
|
||||
// one I just added." Backend's setWakeTimes() sorts on save, so the persisted
|
||||
// state stays canonical.
|
||||
function addTime() {
|
||||
for (const c of DEFAULT_TIME_CANDIDATES) {
|
||||
if (!editWakeTimes.value.includes(c)) {
|
||||
editWakeTimes.value = [...editWakeTimes.value, c].sort((a, b) => a - b)
|
||||
editWakeTimes.value = [...editWakeTimes.value, c]
|
||||
return
|
||||
}
|
||||
}
|
||||
// Fallback: pick the next free 5-minute slot.
|
||||
for (let m = 0; m < 24 * 60; m += 5) {
|
||||
if (!editWakeTimes.value.includes(m)) {
|
||||
editWakeTimes.value = [...editWakeTimes.value, m].sort((a, b) => a - b)
|
||||
editWakeTimes.value = [...editWakeTimes.value, m]
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -531,11 +535,12 @@ function onTimePart(idx: number, part: 'h' | 'mm' | 'p', raw: string) {
|
||||
const h = part === 'h' ? parseInt(raw, 10) : cur.h
|
||||
const mm = part === 'mm' ? parseInt(raw, 10) : cur.mm
|
||||
const p = part === 'p' ? (raw as AmPm) : cur.p
|
||||
// Update in-place; don't dedupe — leave it to the user to clean up duplicates.
|
||||
// (Backend's setWakeTimes() dedupes on save, so the persisted state stays clean.)
|
||||
// Update in-place — don't reorder, don't dedupe. Reordering a row while
|
||||
// the user's mid-edit would yank their focus to the new position. Backend
|
||||
// setWakeTimes() sorts and dedupes on save.
|
||||
const arr = [...editWakeTimes.value]
|
||||
arr[idx] = minutesFromHmp(h, mm, p)
|
||||
editWakeTimes.value = arr.sort((a, b) => a - b)
|
||||
editWakeTimes.value = arr
|
||||
}
|
||||
|
||||
// "Next update" is when the device will *actually* next sync — and the new
|
||||
|
||||
Reference in New Issue
Block a user