Food: the header's arrows go by week; days switch in place

- Dashboard: the arrows (and the left / right keys) move a week, the week
  strip picks the day. Switching fetches the page and swaps in its header and
  diary instead of loading everything again (back / forward work); a day is
  fetched ahead while the pointer rests on it.
- App: the arrows move a week, swiping sideways moves a day (1.1.6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-10-26 15:41:23 +02:00
parent eeca189b7f
commit 98b110dd56
7 changed files with 62 additions and 9 deletions

View file

@ -13,6 +13,11 @@ What changed in each published build of the app. `tool/publish.sh` shows the ent
- The band's data goes with the phone's time zone, so the dashboard reads its times right without a
setting.
## 1.1.6 — 2026-10-26
- Food: the arrows at the top go a week back / ahead; swiping sideways goes a day. The dashboard's arrows go
by week too.
## 1.1.5 — 2026-10-26
- Food: "All products" lists everything — My foods, the food database and products you kept first, then

View file

@ -92,7 +92,18 @@ class _FoodPageState extends State<FoodPage> {
label: Text(es.isEmpty ? 'Make a meal' : 'Make a meal (from this day’s entries)'),
),
];
return ListView(padding: const EdgeInsets.fromLTRB(12, 10, 12, 24), children: [
// the arrows go by week; a swipe sideways goes by day
return GestureDetector(
onHorizontalDragEnd: (e) {
final v = e.primaryVelocity ?? 0;
if (v.abs() < 300) return;
if (v > 0) {
setState(() => d = plus(d, -1));
} else if (daysBetween(today(), d) < ahead) {
setState(() => d = plus(d, 1));
}
},
child: ListView(padding: const EdgeInsets.fromLTRB(12, 10, 12, 24), children: [
if (wide)
Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Expanded(child: Column(children: head)),
@ -100,13 +111,14 @@ class _FoodPageState extends State<FoodPage> {
Expanded(child: Column(children: meals)),
])
else ...[...head, const SizedBox(height: 10), ...meals],
]);
]),
);
});
},
);
Widget _nav() => Row(children: [
IconButton(onPressed: () => setState(() => d = plus(d, -1)), icon: const Icon(Icons.chevron_left)),
IconButton(tooltip: 'Week before', onPressed: () => setState(() => d = plus(d, -7)), icon: const Icon(Icons.chevron_left)),
Expanded(
child: GestureDetector(
onTap: () => setState(() => d = today()),
@ -115,7 +127,8 @@ class _FoodPageState extends State<FoodPage> {
),
),
IconButton(
onPressed: daysBetween(today(), d) < ahead ? () => setState(() => d = plus(d, 1)) : null,
tooltip: 'Week after',
onPressed: daysBetween(today(), d) + 7 <= ahead ? () => setState(() => d = plus(d, 7)) : null,
icon: const Icon(Icons.chevron_right)),
]);

View file

@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.1.5+8
version: 1.1.6+10
environment:
sdk: ^3.12.2

View file

@ -106,12 +106,47 @@
}
async function refresh() {
ahead.clear(); // fetched before the change: stale now
const r = await fetch(location.href, { cache: "no-store" });
const fresh = new DOMParser().parseFromString(await r.text(), "text/html").querySelector(".fd");
if (fresh) document.querySelector(".fd").replaceWith(fresh);
}
const pageDay = () => document.querySelector(".fd-add")?.dataset.day || iso(new Date());
// Switching days (the week strip) and weeks (the header's arrows, the title = today): the page is fetched and
// its header + .fd swapped in, not loaded again whole; a day is fetched already while the pointer rests on it.
const ahead = new Map(); // url → [when, Promise of its HTML]
const fetchPage = (url) => {
const had = ahead.get(url);
if (had && Date.now() - had[0] < 30000) return had[1];
const p = fetch(url, { cache: "no-store" }).then((r) => r.ok ? r.text() : Promise.reject(new Error(r.status)));
ahead.set(url, [Date.now(), p]);
p.catch(() => ahead.delete(url));
return p;
};
const dayLink = (t) => document.querySelector(".fd-week") && t.closest?.(".fd-week a.fd-wd, .fd-head .cw-wrap a:not(.off)");
async function goDay(url, push) {
try {
const doc = new DOMParser().parseFromString(await fetchPage(url), "text/html");
const parts = [".fd-head", ".subhead", ".fd"];
if (!parts.every((c) => doc.querySelector(c) && document.querySelector(c))) throw new Error("not a day page");
closeEditor();
parts.forEach((c) => document.querySelector(c).replaceWith(doc.querySelector(c)));
document.title = doc.title;
const day = document.querySelector(".fd-add")?.dataset.day;
if (day) document.querySelectorAll("#fd-check input[name=day]").forEach((x) => { x.value = day; });
if (push) history.pushState({ fd: 1 }, "", url);
} catch (x) { location.href = url; } // anything odd: the plain way
}
document.addEventListener("click", (e) => {
const a = dayLink(e.target);
if (!a || e.button || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) return;
e.preventDefault();
goDay(a.href, true);
});
document.addEventListener("mouseover", (e) => { const a = dayLink(e.target); if (a) fetchPage(a.href); });
addEventListener("popstate", () => { if (document.querySelector(".fd-week")) goDay(location.href, false); });
// ---- shared: portions, units, a food's numbers ----------------------------------------------
const MEAS = /^(cup|oz|fl oz|tablespoon|tbsp|teaspoon|tsp|lb|g|ml|pint|quart|\d)/i;
const LABELS = { fiber: "fibre", sugar: "sugar", sat_fat: "sat. fat", sodium_mg: "sodium" };

View file

@ -6,7 +6,7 @@
<header class="head fd-head">
{{ nav_btns() }}
{{ title_block(title, center_href, current, prev_href, next_href, can_next=can_next,
prev_title="Day before", next_title="Day after", link_title="Today") }}
prev_title="Week before", next_title="Week after", link_title="Today") }}
{{ settings_btn("food") }}
</header>
{{ subline(sub) }}

View file

@ -221,8 +221,8 @@ def day(entries_of, totals_of, s, d, today, energy=None, activity=None, added_of
"tip": f"{round(k)} kcal · protein {round(v.get('protein') or 0)} g, carbs {round(v.get('carbs') or 0)} g, "
f"fat {round(v.get('fat') or 0)} g" if k else "nothing logged"})
burned = ((activity or {}).get("energy") or {}).get("total")
return {"day": d, "today": today, "prev": d - timedelta(days=1),
"next": d + timedelta(days=1) if d < today + timedelta(days=AHEAD) else None, "future": d > today,
return {"day": d, "today": today, "prev": d - timedelta(days=7), # the header's arrows: a week
"next": d + timedelta(days=7) if d + timedelta(days=7) <= today + timedelta(days=AHEAD) else None, "future": d > today,
"plan": plan(s, energy), "activity": activity, "balance": round(t["kcal"] - burned) if burned and rows else None, # nothing logged: no balance
"meals": meals, "yesterday": yesterday, "t": t, "n": len(rows), "ring": ring(t, tg["kcal"][0]), "bars": bars(t, tg), "strip": strip,
"week_kcal": round(sum((v.get("kcal") or 0) for v in wk.values())),

View file

@ -683,7 +683,7 @@
else if (e.key === "m") location.href = "/month";
else if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
const a = document.querySelector(e.key === "ArrowLeft" ? ".btn.prev" : ".btn.next");
if (a && !a.classList.contains("off")) location.href = a.href;
if (a && !a.classList.contains("off")) a.click(); // a page may handle it in place (food.js)
}
});
tick();