Patch the day list in place instead of navigating
Kirjaa now works like the catalog: opening a day, picking a dish, saving, deleting, cancelling and "Näytä lisää" all patch the list where it stands. Nothing loads a page, so the scroll position never moves. One builder serves all three paths. buildLog takes what the screen should show — the day, an open dish, whether the entry is being changed or a delete confirmed — and the page render, the patch and the post-write response all go through it. After a save it is called with only the date, so the day comes back closed rather than reopening the sides step it was just submitted from. Links stay links and forms stay forms, with data-on:click__prevent and data-on:submit__prevent layered over them, so it all still works with JavaScript off. Each response patches a single element, so plain text/html is enough here; the SSE writer is only needed by the catalog, where the list and both forms have to move together. The anchors added in the previous attempt are gone. They could never have worked: the browser positions an anchor without knowing where the page was scrolled, so it jumped regardless.
This commit is contained in:
+22
-4
@@ -140,13 +140,31 @@ check "the saved day shows what was eaten" \
|
||||
# The selected day expands inside the list rather than in a panel above it,
|
||||
# so the rows below do not shift when one is tapped.
|
||||
day=$(curl -s -u ":$pass" "http://$addr/?pvm=2026-09-05")
|
||||
check "the selected day expands in place" "$day" 'id="paiva-2026-09-05"'
|
||||
check "the selected day expands in place" "$day" 'class="open"'
|
||||
check "and stays in the list rather than being lifted out" "$day" "kirjattu"
|
||||
check "links inside it keep the anchor" "$day" "#paiva-2026-09-05"
|
||||
|
||||
check "saving returns to the day, not the top" \
|
||||
# ---- the day list patches in place instead of navigating ----------------
|
||||
|
||||
dayp=$(curl -s -u ":$pass" -H 'Datastar-Request: true' "http://$addr/paiva?pvm=2026-09-05")
|
||||
check "opening a day patches the list" "$dayp" 'id="paivat"'
|
||||
refute "and returns a fragment, not a page" "$dayp" "<html"
|
||||
|
||||
check "picking a dish patches to the sides step" \
|
||||
"$(curl -s -u ":$pass" -H 'Datastar-Request: true' \
|
||||
"http://$addr/paiva?pvm=2026-09-05&ruoka=$ruoka")" "Tallenna"
|
||||
|
||||
check "saving from Datastar patches back" \
|
||||
"$(curl -s -u ":$pass" -H 'Datastar-Request: true' \
|
||||
-d "pvm=2026-09-04&ruoka=$ruoka" "http://$addr/kirjaa")" 'id="paivat"'
|
||||
|
||||
check "deleting from Datastar patches back" \
|
||||
"$(curl -s -u ":$pass" -H 'Datastar-Request: true' \
|
||||
-d "pvm=2026-09-04" "http://$addr/poista")" 'id="paivat"'
|
||||
|
||||
# Without the header it must still redirect, for no JavaScript.
|
||||
check "a plain save still redirects to the day" \
|
||||
"$(curl -s -o /dev/null -w '%{redirect_url}' -u ":$pass" \
|
||||
-d "pvm=2026-09-04&ruoka=$ruoka" "http://$addr/kirjaa")" "#paiva-2026-09-04"
|
||||
-d "pvm=2026-09-04&ruoka=$ruoka" "http://$addr/kirjaa")" "pvm=2026-09-04"
|
||||
|
||||
# Deleting a logged meal drops the row outright, so it asks first.
|
||||
saved=$(curl -s -u ":$pass" "http://$addr/?pvm=2026-09-05&poista=1")
|
||||
|
||||
Reference in New Issue
Block a user