Polish PWA gestures, transitions and nutrition averages
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 32s
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 32s
This commit is contained in:
parent
b19de6f9ea
commit
7288e56c02
16 changed files with 1019 additions and 245 deletions
|
|
@ -60,6 +60,7 @@ const settings = z
|
|||
exportDays: z.enum(["7", "30", "90", "all"]),
|
||||
exportMetrics: z.array(z.enum(metricKeys)).max(7).optional(),
|
||||
exportWeight: z.boolean().optional(),
|
||||
minimumAverageCalories: amount.optional(),
|
||||
})
|
||||
.strict();
|
||||
export const recordSchema = z
|
||||
|
|
|
|||
9
shared/navigation.js
Normal file
9
shared/navigation.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// Direction is the next tab (+1) or previous tab (-1). Vertical scrolling wins
|
||||
// unless a gesture has a clear horizontal intent; small jitter never navigates.
|
||||
export function swipeStep(dx, dy, elapsed, width) {
|
||||
if (Math.abs(dx) < Math.abs(dy) * 1.4) return 0;
|
||||
const distance = Math.abs(dx);
|
||||
const deliberate = distance >= Math.min(90, Math.max(55, width * 0.18));
|
||||
const flick = distance >= 36 && distance / Math.max(1, elapsed) >= 0.5;
|
||||
return deliberate || flick ? (dx < 0 ? 1 : -1) : 0;
|
||||
}
|
||||
39
shared/nutrition-trends.js
Normal file
39
shared/nutrition-trends.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { emptyNutrients, totalNutrients } from "./domain.js";
|
||||
|
||||
// The cutoff is a logging preference, not a nutritional recommendation.
|
||||
// A fixed kcal cutoff remains predictable even if a calorie goal is disabled.
|
||||
/**
|
||||
* @param {import("../src/types").Entry[]} entries
|
||||
* @param {string[]} dates
|
||||
* @param {number} minimumCalories
|
||||
*/
|
||||
export function nutritionSummary(entries, dates, minimumCalories) {
|
||||
/** @type {Map<string, import("../src/types").Entry[]>} */
|
||||
const grouped = new Map();
|
||||
for (const entry of entries) {
|
||||
const group = grouped.get(entry.date) || [];
|
||||
group.push(entry);
|
||||
grouped.set(entry.date, group);
|
||||
}
|
||||
const days = dates.map((date) => {
|
||||
const logs = grouped.get(date) || [];
|
||||
const nutrients = totalNutrients(logs);
|
||||
return {
|
||||
date,
|
||||
logged: logs.length > 0,
|
||||
included: logs.length > 0 && nutrients.calories >= minimumCalories,
|
||||
nutrients,
|
||||
};
|
||||
});
|
||||
const included = days.filter((day) => day.included);
|
||||
const average = emptyNutrients();
|
||||
for (const day of included)
|
||||
for (const key of Object.keys(average))
|
||||
average[key] += day.nutrients[key] / included.length;
|
||||
return {
|
||||
days,
|
||||
average,
|
||||
includedCount: included.length,
|
||||
excludedCount: days.filter((day) => day.logged && !day.included).length,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue