Native-feel polish: autosaving settings, stacked sheets, desktop type scale
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 28s
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 28s
- Settings apply as they change; theme/accent preview instantly and a background sync no longer discards in-progress edits - Food journal stays open beneath edit/add/delete sheets - Toasts render in the top layer above open sheets, with an error tone - Follow the new day when the PWA resumes after midnight - Add-food sheet: day/time row, one-tap meal picker, blank nutrient fields - Library cards gain a Log action; compact rows on phones - Desktop type scale raised from 7-12px to 10-15px (desktop.css) - Hover styles limited to hover-capable devices; touch press dimming and no text selection on app chrome - Sheets slide opaque on the UIKit curve; drag-to-dismiss tracks 1:1, supports flicks and departs from the dragged position - Removed calorie bubbles fade out; no progress dot at 0 kcal - Friendly network/proxy error messages; fresh outbox check before update Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3c0d6560f1
commit
c3b9376508
16 changed files with 1043 additions and 290 deletions
11
README.md
11
README.md
|
|
@ -1,23 +1,24 @@
|
|||
# Calio
|
||||
|
||||
A single-user, self-hosted nutrition journal. PWA first, with a responsive desktop layout, light/dark/system themes, configurable accent colors, and no third-party analytics, fonts, or nutrition services. Dark mode uses neutral near-black and charcoal surfaces; choose a preset or custom accent under Settings → Look & feel, then save preferences. Accent preferences sync between devices and remain available offline.
|
||||
A single-user, self-hosted nutrition journal. PWA first, with a responsive desktop layout, light/dark/system themes, configurable accent colors, and no third-party analytics, fonts, or nutrition services. Dark mode uses neutral near-black and charcoal surfaces; choose a preset or custom accent under Settings → Look & feel; it applies immediately. Accent preferences sync between devices and remain available offline.
|
||||
|
||||
## Included
|
||||
|
||||
- Daily calorie vessel with colliding physics bubbles, week navigation, meal journal, editable entries, fractional servings. New bubbles drop from the top as calories increase.
|
||||
- Food names are optional: unnamed daily entries use the meal name and next available number, such as `Dinner 1`. The main Add food action suggests breakfast from 5–11am, lunch from 11am–4pm, dinner from 4–10pm and snacks overnight, using the device's local time. Meal-specific add buttons preserve their category; the selection remains editable.
|
||||
- Food entries include an editable local clock time, shown in the journal and all export formats. Existing entries without a time remain valid and show “Time not recorded” until you add one. Entries sort by time within each meal.
|
||||
- Saved foods and reusable plates. Logging a plate creates an atomic batch of independent food entries. Logs retain a nutrition snapshot when library foods change.
|
||||
- Saved foods and reusable plates; **Log** on a library card opens the food sheet pre-filled. Logging a plate creates an atomic batch of independent food entries. Logs retain a nutrition snapshot when library foods change.
|
||||
- Independently enabled calorie, protein, carbohydrate, fat, fiber, sugar and sodium goals.
|
||||
- Weight journal in lb or kg; internally stored in kg. Multiple weigh-ins are retained, with the latest measurement per day used in charts.
|
||||
- Dedicated Weight tab on desktop and mobile, with its own logging, graph and journal. Nutrition trends live under Library → Trends. Both support 7 / 30 / 90 / 365 day periods. Nutrition averages exclude empty and likely incomplete days: the initial cutoff is half the calorie target, adjustable under Settings → Nutrition averages (0 includes all logged days). Every nutrient uses the same qualifying days; faded bars and exports retain actual totals. This is a logging heuristic, so adjust it for your own routine. Saving preferences stores the cutoff in kcal independently of later goal changes.
|
||||
- Dedicated Weight tab on desktop and mobile, with its own logging, graph and journal. Nutrition trends live under Library → Trends. Both support 7 / 30 / 90 / 365 day periods. Nutrition averages exclude empty and likely incomplete days: the initial cutoff is half the calorie target, adjustable under Settings → Nutrition averages (0 includes all logged days). Every nutrient uses the same qualifying days; faded bars and exports retain actual totals. This is a logging heuristic, so adjust it for your own routine. Any settings change stores the cutoff in kcal, independently of later goal changes.
|
||||
- Settings save automatically as you change them: theme and accent switch instantly, and number fields commit after a short pause, on Return, or when you leave the field.
|
||||
- On phones, swipe left/right through Today → Library → Weight → Settings. Neighboring screens are already rendered and move together under your finger; settling uses a composited slide with no fade-to-blank delay. Every tab retains its own scroll position. Vertical scrolling, form controls, horizontal macro scrolling, and browser edge gestures remain independent. The calorie simulation pauses on other tabs. Pull down from a sheet header to dismiss it. System Reduce Motion disables these transitions.
|
||||
- Markdown, CSV and JSON export with date range, nutrient and weight selections. Markdown is designed for LLM analysis. Data is downloaded locally, never submitted to an LLM. Save preferences to remember the export format, range preset and selections.
|
||||
- Markdown, CSV and JSON export with date range, nutrient and weight selections. Markdown is designed for LLM analysis. Data is downloaded locally, never submitted to an LLM. Each download remembers the export format, range preset and selections for next time.
|
||||
- Password authentication, IndexedDB offline journal/outbox, a precached app shell, automatic foreground/reconnect sync, and explicit PWA update prompts.
|
||||
|
||||
### Phone layout
|
||||
|
||||
On phones, Today fills the available screen, including iPhone safe areas, with the calorie circle, readout, macros and navigation visible together. **Food journal** opens the selected day's meals in a separate scrollable sheet; adding, editing and removing entries from it uses the same offline journal. Desktop retains the side-by-side dashboard and meals. Compact screens use the date picker instead of the full week strip, and landscape arranges the circle beside the totals. If more than three nutrient goals are enabled, swipe the macro row horizontally to see the rest.
|
||||
On phones, Today fills the available screen, including iPhone safe areas, with the calorie circle, readout, macros and navigation visible together. **Food journal** opens the selected day's meals in a separate scrollable sheet; adding, editing and removing entries open on top of it, and you return to the journal afterwards. Desktop retains the side-by-side dashboard and meals. Compact screens use the date picker instead of the full week strip, and landscape arranges the circle beside the totals. If more than three nutrient goals are enabled, swipe the macro row horizontally to see the rest.
|
||||
|
||||
Phone controls use larger type, 44–56 px tap targets, and 51×31 px switches. Food entry uses full-width day/time/meal rows, explicitly constrained native input widths, and a sticky sheet header. Library, Weight and Settings scroll normally.
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ export function createBubbleWorld(initialCount = 0, random = Math.random) {
|
|||
});
|
||||
engine.gravity.scale = 0.00035;
|
||||
const balls = [];
|
||||
// Removed bubbles leave the simulation at once but fade out where they were.
|
||||
const fading = [];
|
||||
let target = initialCount;
|
||||
let spawnTime = 0;
|
||||
const walls = Array.from({ length: 72 }, (_, i) => {
|
||||
|
|
@ -82,6 +84,7 @@ export function createBubbleWorld(initialCount = 0, random = Math.random) {
|
|||
function seed(count) {
|
||||
for (const ball of balls) Composite.remove(engine.world, ball);
|
||||
balls.length = 0;
|
||||
fading.length = 0;
|
||||
target = Math.min(MAX_BUBBLES, Math.max(0, count));
|
||||
for (let i = 0; i < target; i++)
|
||||
add(packedPositions[i].x, packedPositions[i].y);
|
||||
|
|
@ -89,7 +92,16 @@ export function createBubbleWorld(initialCount = 0, random = Math.random) {
|
|||
seed(initialCount);
|
||||
function setTarget(count) {
|
||||
target = Math.min(MAX_BUBBLES, Math.max(0, count));
|
||||
while (balls.length > target) Composite.remove(engine.world, balls.pop());
|
||||
while (balls.length > target) {
|
||||
const ball = balls.pop();
|
||||
Composite.remove(engine.world, ball);
|
||||
fading.push({
|
||||
id: ball.id,
|
||||
x: ball.position.x,
|
||||
y: ball.position.y,
|
||||
life: 1,
|
||||
});
|
||||
}
|
||||
wake();
|
||||
}
|
||||
function gravity(x, y) {
|
||||
|
|
@ -102,6 +114,9 @@ export function createBubbleWorld(initialCount = 0, random = Math.random) {
|
|||
}
|
||||
function step(delta = 1000 / 60) {
|
||||
spawnTime += delta;
|
||||
for (const bubble of fading) bubble.life -= delta / 220;
|
||||
for (let i = fading.length - 1; i >= 0; i--)
|
||||
if (fading[i].life <= 0) fading.splice(i, 1);
|
||||
// Two 60 Hz frames per bubble, previously three: 50% more arrivals/second.
|
||||
if (balls.length < target && spawnTime >= 1000 / 30) {
|
||||
spawnTime = 0;
|
||||
|
|
@ -143,13 +158,16 @@ export function createBubbleWorld(initialCount = 0, random = Math.random) {
|
|||
return {
|
||||
engine,
|
||||
balls,
|
||||
fading,
|
||||
step,
|
||||
seed,
|
||||
setTarget,
|
||||
gravity,
|
||||
nudge,
|
||||
awake: () =>
|
||||
balls.length < target || balls.some((ball) => !ball.isSleeping),
|
||||
fading.length > 0 ||
|
||||
balls.length < target ||
|
||||
balls.some((ball) => !ball.isSleeping),
|
||||
dispose: () => {
|
||||
Composite.clear(engine.world, false);
|
||||
Engine.clear(engine);
|
||||
|
|
|
|||
124
src/App.tsx
124
src/App.tsx
|
|
@ -3,6 +3,7 @@ import {
|
|||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
|
|
@ -10,6 +11,7 @@ import {
|
|||
ArrowRight,
|
||||
ArrowUpRight,
|
||||
BookOpen,
|
||||
CalendarDays,
|
||||
Check,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
|
|
@ -40,6 +42,7 @@ import {
|
|||
deleteRecord,
|
||||
initStore,
|
||||
login,
|
||||
pendingChanges,
|
||||
sync,
|
||||
useJournal,
|
||||
useSyncStatus,
|
||||
|
|
@ -79,6 +82,7 @@ import { Presence } from "./Presence";
|
|||
import { useNavigation, type Page } from "./useNavigation";
|
||||
import { PageActivity } from "./PageActivity";
|
||||
import { useTiltResume } from "./useTilt";
|
||||
import { useFollowToday } from "./useToday";
|
||||
function PagePanel({
|
||||
name,
|
||||
page,
|
||||
|
|
@ -110,8 +114,52 @@ function PagePanel({
|
|||
);
|
||||
}
|
||||
|
||||
// A manual popover joins the top layer, so confirmations stay visible above
|
||||
// any open sheet instead of behind its backdrop.
|
||||
function Toast({
|
||||
text,
|
||||
error,
|
||||
dismiss,
|
||||
}: {
|
||||
text: string;
|
||||
error: boolean;
|
||||
dismiss: () => void;
|
||||
}) {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
const element = ref.current;
|
||||
if (!element?.showPopover) return;
|
||||
try {
|
||||
if (element.matches(":popover-open")) element.hidePopover();
|
||||
element.showPopover();
|
||||
} catch {
|
||||
// Unsupported browsers render it as a fixed element.
|
||||
}
|
||||
}, [text]);
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
popover="manual"
|
||||
className={"toast" + (error ? " toast-error" : "")}
|
||||
role={error ? "alert" : "status"}
|
||||
>
|
||||
{error ? <CloudOff size={17} /> : <Check size={17} />}
|
||||
<span>{text}</span>
|
||||
<button aria-label="Dismiss notification" onClick={dismiss}>
|
||||
<X size={15} />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type Editor =
|
||||
| { kind: "log"; meal: Meal; record?: JournalRecord<Entry> }
|
||||
| {
|
||||
kind: "log";
|
||||
meal: Meal;
|
||||
record?: JournalRecord<Entry>;
|
||||
template?: Food;
|
||||
tab?: "manual" | "saved" | "plates";
|
||||
}
|
||||
| { kind: "food"; record?: JournalRecord<Food> }
|
||||
| { kind: "plate"; record?: JournalRecord<Plate> }
|
||||
| { kind: "weight"; record?: JournalRecord<Weight> }
|
||||
|
|
@ -424,7 +472,7 @@ function Dashboard({
|
|||
if (e.target.value) setDate(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<ChevronRight size={16} />
|
||||
<CalendarDays size={18} />
|
||||
</button>
|
||||
<button
|
||||
className="primary desktop-add"
|
||||
|
|
@ -585,18 +633,9 @@ function Dashboard({
|
|||
<MealJournal
|
||||
dayEntries={dayEntries}
|
||||
settings={settings}
|
||||
add={(meal) => {
|
||||
closeJournal();
|
||||
add(meal);
|
||||
}}
|
||||
edit={(record) => {
|
||||
closeJournal();
|
||||
edit(record);
|
||||
}}
|
||||
remove={(record) => {
|
||||
closeJournal();
|
||||
remove(record);
|
||||
}}
|
||||
add={add}
|
||||
edit={edit}
|
||||
remove={remove}
|
||||
/>
|
||||
</Modal>
|
||||
)}
|
||||
|
|
@ -616,6 +655,8 @@ function Library({
|
|||
editFood,
|
||||
editPlate,
|
||||
log,
|
||||
logFood,
|
||||
logPlate,
|
||||
remove,
|
||||
trends,
|
||||
}: {
|
||||
|
|
@ -626,6 +667,8 @@ function Library({
|
|||
editFood: (r: JournalRecord<Food>) => void;
|
||||
editPlate: (r: JournalRecord<Plate>) => void;
|
||||
log: () => void;
|
||||
logFood: (food: Food) => void;
|
||||
logPlate: () => void;
|
||||
remove: (r: JournalRecord) => void;
|
||||
trends: ReactNode;
|
||||
}) {
|
||||
|
|
@ -744,6 +787,14 @@ function Library({
|
|||
</div>
|
||||
</div>
|
||||
<div className="library-card-actions">
|
||||
<button
|
||||
className="text-button log-action"
|
||||
aria-label={`Log ${r.data.name}`}
|
||||
onClick={() => logFood(r.data)}
|
||||
>
|
||||
<Plus size={15} />
|
||||
Log
|
||||
</button>
|
||||
<button
|
||||
className="text-button"
|
||||
onClick={() => editFood(r)}
|
||||
|
|
@ -786,6 +837,14 @@ function Library({
|
|||
</div>
|
||||
</div>
|
||||
<div className="library-card-actions">
|
||||
<button
|
||||
className="text-button log-action"
|
||||
aria-label={`Log ${r.data.name}`}
|
||||
onClick={logPlate}
|
||||
>
|
||||
<Plus size={15} />
|
||||
Log
|
||||
</button>
|
||||
<button
|
||||
className="text-button"
|
||||
onClick={() => editPlate(r)}
|
||||
|
|
@ -838,8 +897,10 @@ export function App() {
|
|||
);
|
||||
useTiltResume(ready && journal.unlocked);
|
||||
const [date, setDate] = useState(today());
|
||||
useFollowToday(setDate);
|
||||
const [editor, setEditor] = useState<Editor>(null);
|
||||
const [toast, setToast] = useState("");
|
||||
const [toastError, setToastError] = useState(false);
|
||||
const [deleting, setDeleting] = useState<JournalRecord | null>(null);
|
||||
const [reauth, setReauth] = useState(false);
|
||||
const [installEvent, setInstallEvent] = useState<InstallEvent | null>(null);
|
||||
|
|
@ -861,7 +922,10 @@ export function App() {
|
|||
[journal.records],
|
||||
);
|
||||
const close = useCallback(() => setEditor(null), []);
|
||||
const notify = useCallback((text: string) => setToast(text), []);
|
||||
const notify = useCallback((text: string, error = false) => {
|
||||
setToast(text);
|
||||
setToastError(error);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
initStore()
|
||||
.then(() => {
|
||||
|
|
@ -923,6 +987,7 @@ export function App() {
|
|||
.catch(() =>
|
||||
notify(
|
||||
"Offline app caching could not start. Check your browser storage settings.",
|
||||
true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -931,8 +996,8 @@ export function App() {
|
|||
}, [notify]);
|
||||
async function update() {
|
||||
await sync();
|
||||
if (journal.outbox.length) {
|
||||
notify("Sync your pending entries before updating.");
|
||||
if (pendingChanges()) {
|
||||
notify("Sync your pending entries before updating.", true);
|
||||
return;
|
||||
}
|
||||
navigator.serviceWorker.addEventListener(
|
||||
|
|
@ -1113,6 +1178,12 @@ export function App() {
|
|||
editFood={(record) => setEditor({ kind: "food", record })}
|
||||
editPlate={(record) => setEditor({ kind: "plate", record })}
|
||||
log={() => setEditor({ kind: "log", meal: suggestedMeal() })}
|
||||
logFood={(template) =>
|
||||
setEditor({ kind: "log", meal: suggestedMeal(), template })
|
||||
}
|
||||
logPlate={() =>
|
||||
setEditor({ kind: "log", meal: suggestedMeal(), tab: "plates" })
|
||||
}
|
||||
remove={setDeleting}
|
||||
trends={
|
||||
<Trends
|
||||
|
|
@ -1147,10 +1218,6 @@ export function App() {
|
|||
>
|
||||
{notices}
|
||||
<Settings
|
||||
key={
|
||||
recordsOf<SettingsData>(journal.records, "settings")[0]
|
||||
?.updatedAt || "initial"
|
||||
}
|
||||
settings={settings}
|
||||
records={journal.records}
|
||||
pending={journal.outbox.length}
|
||||
|
|
@ -1210,6 +1277,8 @@ export function App() {
|
|||
date={date}
|
||||
meal={editor.meal}
|
||||
existing={editor.record}
|
||||
template={editor.template}
|
||||
initialTab={editor.tab}
|
||||
foods={foods}
|
||||
plates={plates}
|
||||
notify={notify}
|
||||
|
|
@ -1270,7 +1339,7 @@ export function App() {
|
|||
setDeleting(null);
|
||||
notify("Item removed");
|
||||
} catch {
|
||||
notify("Could not remove this item. Please try again.");
|
||||
notify("Could not remove this item. Please try again.", true);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
|
@ -1285,16 +1354,7 @@ export function App() {
|
|||
{reauth && <SignIn reauth onCancel={() => setReauth(false)} />}
|
||||
</Presence>
|
||||
{toast && (
|
||||
<div className="toast" role="status">
|
||||
<Check size={17} />
|
||||
<span>{toast}</span>
|
||||
<button
|
||||
aria-label="Dismiss notification"
|
||||
onClick={() => setToast("")}
|
||||
>
|
||||
<X size={15} />
|
||||
</button>
|
||||
</div>
|
||||
<Toast text={toast} error={toastError} dismiss={() => setToast("")} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export function Presence({ children }: { children: ReactNode }) {
|
|||
}
|
||||
const timer = setTimeout(
|
||||
() => setRetained(false),
|
||||
matchMedia("(prefers-reduced-motion: reduce)").matches ? 0 : 190,
|
||||
matchMedia("(prefers-reduced-motion: reduce)").matches ? 0 : 250,
|
||||
);
|
||||
return () => clearTimeout(timer);
|
||||
}, [children, visible]);
|
||||
|
|
|
|||
366
src/Settings.tsx
366
src/Settings.tsx
|
|
@ -1,4 +1,4 @@
|
|||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState, type InputHTMLAttributes } from "react";
|
||||
import {
|
||||
Download,
|
||||
Check,
|
||||
|
|
@ -16,9 +16,86 @@ import type { JournalRecord, Metric, Settings as SettingsData } from "./types";
|
|||
import { metrics } from "./types";
|
||||
import { downloadExport, offsetDay, today } from "./utils";
|
||||
import { logout, saveRecord, sync, useSyncStatus } from "./store";
|
||||
import { accentPresets, DEFAULT_ACCENT } from "../shared/theme.js";
|
||||
import {
|
||||
accentPalette,
|
||||
accentPresets,
|
||||
DEFAULT_ACCENT,
|
||||
} from "../shared/theme.js";
|
||||
import { useTilt } from "./useTilt";
|
||||
|
||||
// Edits a number locally and commits once it is valid: after a short pause, on
|
||||
// blur, or on Enter. External changes (sync) apply only while it is not focused.
|
||||
function NumberField({
|
||||
value,
|
||||
min,
|
||||
max,
|
||||
exclusiveMin = false,
|
||||
onCommit,
|
||||
...props
|
||||
}: {
|
||||
value: number;
|
||||
min: number;
|
||||
max: number;
|
||||
exclusiveMin?: boolean;
|
||||
onCommit: (value: number) => void;
|
||||
} & Omit<
|
||||
InputHTMLAttributes<HTMLInputElement>,
|
||||
"value" | "min" | "max" | "onChange"
|
||||
>) {
|
||||
const [text, setText] = useState(String(value));
|
||||
const focused = useRef(false);
|
||||
const timer = useRef(0);
|
||||
const latest = useRef({ text, value, onCommit });
|
||||
latest.current = { text, value, onCommit };
|
||||
useEffect(() => {
|
||||
if (!focused.current) setText(String(value));
|
||||
}, [value]);
|
||||
const valid = (raw: string) => {
|
||||
const n = Number(raw);
|
||||
return (
|
||||
raw.trim() !== "" &&
|
||||
Number.isFinite(n) &&
|
||||
(exclusiveMin ? n > min : n >= min) &&
|
||||
n <= max
|
||||
);
|
||||
};
|
||||
const commit = (final: boolean) => {
|
||||
clearTimeout(timer.current);
|
||||
const { text: raw, value: current, onCommit: save } = latest.current;
|
||||
if (valid(raw)) {
|
||||
if (Number(raw) !== current) save(Number(raw));
|
||||
if (final) setText(String(Number(raw)));
|
||||
} else if (final) setText(String(current));
|
||||
};
|
||||
useEffect(() => () => commit(false), []);
|
||||
return (
|
||||
<input
|
||||
{...props}
|
||||
type="number"
|
||||
min={exclusiveMin ? undefined : min}
|
||||
max={max}
|
||||
value={text}
|
||||
aria-invalid={!valid(text) || undefined}
|
||||
onFocus={(event) => {
|
||||
focused.current = true;
|
||||
event.currentTarget.select();
|
||||
}}
|
||||
onChange={(event) => {
|
||||
setText(event.target.value);
|
||||
clearTimeout(timer.current);
|
||||
timer.current = window.setTimeout(() => commit(false), 700);
|
||||
}}
|
||||
onBlur={() => {
|
||||
focused.current = false;
|
||||
commit(true);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter") event.currentTarget.blur();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function Settings({
|
||||
settings,
|
||||
records,
|
||||
|
|
@ -32,18 +109,29 @@ export function Settings({
|
|||
records: JournalRecord[];
|
||||
pending: number;
|
||||
lastSync: string | null;
|
||||
notify: (text: string) => void;
|
||||
notify: (text: string, error?: boolean) => void;
|
||||
install: (() => void) | null;
|
||||
update: (() => void) | null;
|
||||
}) {
|
||||
const [draft, setDraft] = useState({
|
||||
...settings,
|
||||
minimumAverageCalories:
|
||||
settings.minimumAverageCalories ??
|
||||
Math.round(settings.goals.calories.target / 2),
|
||||
});
|
||||
const tilt = useTilt();
|
||||
const [busy, setBusy] = useState(false);
|
||||
// Latest settings, including saves still being written, so quick successive
|
||||
// changes build on each other instead of on a stale render.
|
||||
const current = useRef(settings);
|
||||
const received = useRef(settings);
|
||||
if (received.current !== settings) {
|
||||
received.current = settings;
|
||||
current.current = settings;
|
||||
}
|
||||
const cutoff =
|
||||
settings.minimumAverageCalories ??
|
||||
Math.round(settings.goals.calories.target / 2);
|
||||
const [accentPreview, setAccentPreview] = useState<string | null>(null);
|
||||
const accentTimer = useRef(0);
|
||||
const accent = (
|
||||
accentPreview ||
|
||||
settings.accentColor ||
|
||||
DEFAULT_ACCENT
|
||||
).toLowerCase();
|
||||
const [format, setFormat] = useState(settings.exportFormat);
|
||||
const [range, setRange] = useState(settings.exportDays);
|
||||
const [start, setStart] = useState(
|
||||
|
|
@ -62,10 +150,43 @@ export function Settings({
|
|||
);
|
||||
const [error, setError] = useState("");
|
||||
const status = useSyncStatus();
|
||||
// While dragging the custom color, preview it before the debounced save.
|
||||
useEffect(() => {
|
||||
if (!accentPreview) return;
|
||||
const dark = document.documentElement.dataset.theme === "dark";
|
||||
for (const [key, value] of Object.entries(
|
||||
accentPalette(accentPreview, dark),
|
||||
))
|
||||
document.documentElement.style.setProperty(key, value);
|
||||
}, [accentPreview]);
|
||||
// Preferences apply as soon as they change, like iOS Settings. The averages
|
||||
// cutoff is stored in kcal so later calorie-goal changes do not move it.
|
||||
function persist(change: Partial<SettingsData>) {
|
||||
const base = current.current;
|
||||
const next = {
|
||||
...base,
|
||||
minimumAverageCalories:
|
||||
base.minimumAverageCalories ??
|
||||
Math.round(base.goals.calories.target / 2),
|
||||
...change,
|
||||
};
|
||||
current.current = next;
|
||||
setError("");
|
||||
saveRecord("settings", next, "settings").catch(() =>
|
||||
setError("Could not save that change. Please try again."),
|
||||
);
|
||||
}
|
||||
const setGoal = (key: Metric, change: Partial<SettingsData["goals"][Metric]>) =>
|
||||
persist({
|
||||
goals: {
|
||||
...current.current.goals,
|
||||
[key]: { ...current.current.goals[key], ...change },
|
||||
},
|
||||
});
|
||||
const effectiveStart =
|
||||
range === "all"
|
||||
? records.reduce((value, r) => {
|
||||
const date = (r.data as { date?: string }).date;
|
||||
const date = !r.deleted && (r.data as { date?: string }).date;
|
||||
return date && date < value ? date : value;
|
||||
}, today())
|
||||
: start;
|
||||
|
|
@ -76,29 +197,6 @@ export function Settings({
|
|||
return date && date > value ? date : value;
|
||||
}, today())
|
||||
: end;
|
||||
async function save(event: React.FormEvent) {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError("");
|
||||
try {
|
||||
await saveRecord(
|
||||
"settings",
|
||||
{
|
||||
...draft,
|
||||
exportFormat: format,
|
||||
exportDays: range,
|
||||
exportMetrics: selected,
|
||||
exportWeight: includeWeight,
|
||||
},
|
||||
"settings",
|
||||
);
|
||||
notify("Your preferences are saved");
|
||||
} catch {
|
||||
setError("Could not save. Check that each goal is a positive number.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<div className="page-heading">
|
||||
|
|
@ -107,11 +205,11 @@ export function Settings({
|
|||
<h1>
|
||||
Settings<span>.</span>
|
||||
</h1>
|
||||
<p>Goals, appearance and exports.</p>
|
||||
<p>Goals, appearance and exports. Changes save automatically.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="settings-grid">
|
||||
<form className="card settings-card" onSubmit={save}>
|
||||
<section className="card settings-card">
|
||||
<div className="card-title">
|
||||
<div>
|
||||
<span className="eyebrow">FOCUS ON WHAT MATTERS</span>
|
||||
|
|
@ -133,47 +231,22 @@ export function Settings({
|
|||
<input
|
||||
className="switch"
|
||||
type="checkbox"
|
||||
checked={draft.goals[m.key].enabled}
|
||||
onChange={(e) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
goals: {
|
||||
...draft.goals,
|
||||
[m.key]: {
|
||||
...draft.goals[m.key],
|
||||
enabled: e.target.checked,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
role="switch"
|
||||
checked={settings.goals[m.key].enabled}
|
||||
onChange={(e) => setGoal(m.key, { enabled: e.target.checked })}
|
||||
/>
|
||||
<span>{m.label}</span>
|
||||
</label>
|
||||
<label className="unit-input goal-input">
|
||||
<input
|
||||
<NumberField
|
||||
aria-label={`${m.label} daily goal`}
|
||||
type="number"
|
||||
inputMode="decimal"
|
||||
step="any"
|
||||
min="0.1"
|
||||
max="100000"
|
||||
required
|
||||
value={draft.goals[m.key].target}
|
||||
onChange={(e) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
goals: {
|
||||
...draft.goals,
|
||||
[m.key]: {
|
||||
...draft.goals[m.key],
|
||||
target:
|
||||
e.target.value === ""
|
||||
? ("" as unknown as number)
|
||||
: +e.target.value,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
min={0}
|
||||
exclusiveMin
|
||||
max={100000}
|
||||
value={settings.goals[m.key].target}
|
||||
onCommit={(target) => setGoal(m.key, { target })}
|
||||
/>
|
||||
<span>{m.unit}</span>
|
||||
</label>
|
||||
|
|
@ -184,23 +257,15 @@ export function Settings({
|
|||
<label className="average-cutoff">
|
||||
Minimum calories for averages
|
||||
<span className="unit-input">
|
||||
<input
|
||||
<NumberField
|
||||
aria-label="Minimum calories for averages"
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
min="0"
|
||||
max="100000"
|
||||
min={0}
|
||||
max={100000}
|
||||
step="1"
|
||||
required
|
||||
value={draft.minimumAverageCalories}
|
||||
onChange={(event) =>
|
||||
setDraft({
|
||||
...draft,
|
||||
minimumAverageCalories:
|
||||
event.target.value === ""
|
||||
? ("" as unknown as number)
|
||||
: +event.target.value,
|
||||
})
|
||||
value={cutoff}
|
||||
onCommit={(value) =>
|
||||
persist({ minimumAverageCalories: Math.round(value) })
|
||||
}
|
||||
/>
|
||||
<span>kcal</span>
|
||||
|
|
@ -215,11 +280,70 @@ export function Settings({
|
|||
</div>
|
||||
<div className="settings-section">
|
||||
<h3>Look & feel</h3>
|
||||
<div className="segmented theme-control">
|
||||
{(
|
||||
[
|
||||
{ key: "light", icon: Sun },
|
||||
{ key: "dark", icon: Moon },
|
||||
{ key: "system", icon: Monitor },
|
||||
] as const
|
||||
).map(({ key, icon: Icon }) => (
|
||||
<button
|
||||
key={key}
|
||||
type="button"
|
||||
aria-pressed={settings.theme === key}
|
||||
className={settings.theme === key ? "active" : ""}
|
||||
onClick={() => persist({ theme: key })}
|
||||
>
|
||||
<Icon size={16} />
|
||||
{key[0].toUpperCase() + key.slice(1)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="accent-preference">
|
||||
<span className="field-caption">ACCENT COLOR</span>
|
||||
<div className="accent-swatches">
|
||||
{accentPresets.map((preset) => (
|
||||
<button
|
||||
type="button"
|
||||
key={preset.color}
|
||||
aria-label={`${preset.name} accent`}
|
||||
aria-pressed={accent === preset.color}
|
||||
onClick={() => {
|
||||
setAccentPreview(null);
|
||||
persist({ accentColor: preset.color });
|
||||
}}
|
||||
>
|
||||
<span style={{ background: preset.color }} />
|
||||
{accent === preset.color && <Check size={15} />}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<label className="custom-accent">
|
||||
<span>Custom color</span>
|
||||
<code>{accent.toUpperCase()}</code>
|
||||
<input
|
||||
aria-label="Custom accent color"
|
||||
type="color"
|
||||
value={accent}
|
||||
onChange={(e) => {
|
||||
const color = e.target.value;
|
||||
setAccentPreview(color);
|
||||
clearTimeout(accentTimer.current);
|
||||
accentTimer.current = window.setTimeout(() => {
|
||||
persist({ accentColor: color });
|
||||
setAccentPreview(null);
|
||||
}, 350);
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="preference-row" data-tilt-control>
|
||||
<label className="toggle-label">
|
||||
<input
|
||||
className="switch"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
checked={tilt.enabled}
|
||||
onChange={() => void tilt.toggleTilt()}
|
||||
/>
|
||||
|
|
@ -246,69 +370,13 @@ export function Settings({
|
|||
Allow motion
|
||||
</button>
|
||||
)}
|
||||
<div className="segmented theme-control">
|
||||
{(
|
||||
[
|
||||
{ key: "light", icon: Sun },
|
||||
{ key: "dark", icon: Moon },
|
||||
{ key: "system", icon: Monitor },
|
||||
] as const
|
||||
).map(({ key, icon: Icon }) => (
|
||||
<button
|
||||
key={key}
|
||||
type="button"
|
||||
className={draft.theme === key ? "active" : ""}
|
||||
onClick={() => setDraft({ ...draft, theme: key })}
|
||||
>
|
||||
<Icon size={16} />
|
||||
{key[0].toUpperCase() + key.slice(1)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="accent-preference">
|
||||
<span className="field-caption">ACCENT COLOR</span>
|
||||
<div className="accent-swatches">
|
||||
{accentPresets.map((preset) => (
|
||||
<button
|
||||
type="button"
|
||||
key={preset.color}
|
||||
aria-label={`${preset.name} accent`}
|
||||
aria-pressed={
|
||||
(draft.accentColor || DEFAULT_ACCENT).toLowerCase() ===
|
||||
preset.color
|
||||
}
|
||||
onClick={() =>
|
||||
setDraft({ ...draft, accentColor: preset.color })
|
||||
}
|
||||
>
|
||||
<span style={{ background: preset.color }} />
|
||||
{(draft.accentColor || DEFAULT_ACCENT).toLowerCase() ===
|
||||
preset.color && <Check size={15} />}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<label className="custom-accent">
|
||||
<span>Custom color</span>
|
||||
<code>
|
||||
{(draft.accentColor || DEFAULT_ACCENT).toUpperCase()}
|
||||
</code>
|
||||
<input
|
||||
aria-label="Custom accent color"
|
||||
type="color"
|
||||
value={draft.accentColor || DEFAULT_ACCENT}
|
||||
onChange={(e) =>
|
||||
setDraft({ ...draft, accentColor: e.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="preference-row">
|
||||
<label htmlFor="weight-unit">Weight unit</label>
|
||||
<select
|
||||
id="weight-unit"
|
||||
value={draft.unit}
|
||||
value={settings.unit}
|
||||
onChange={(e) =>
|
||||
setDraft({ ...draft, unit: e.target.value as "kg" | "lb" })
|
||||
persist({ unit: e.target.value as "kg" | "lb" })
|
||||
}
|
||||
>
|
||||
<option value="lb">Pounds (lb)</option>
|
||||
|
|
@ -321,11 +389,7 @@ export function Settings({
|
|||
{error}
|
||||
</p>
|
||||
)}
|
||||
<button className="primary wide" disabled={busy}>
|
||||
<Check size={18} />
|
||||
Save preferences
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
<div className="settings-stack">
|
||||
<section className="card settings-card">
|
||||
<div className="card-title">
|
||||
|
|
@ -441,6 +505,12 @@ export function Settings({
|
|||
format,
|
||||
pending,
|
||||
);
|
||||
persist({
|
||||
exportFormat: format,
|
||||
exportDays: range,
|
||||
exportMetrics: selected,
|
||||
exportWeight: includeWeight,
|
||||
});
|
||||
notify("Export downloaded");
|
||||
}}
|
||||
>
|
||||
|
|
@ -524,7 +594,7 @@ export function Settings({
|
|||
try {
|
||||
await logout();
|
||||
} catch (err) {
|
||||
notify((err as Error).message);
|
||||
notify((err as Error).message, true);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import {
|
|||
} from "./utils";
|
||||
import { nutritionSummary } from "../shared/nutrition-trends.js";
|
||||
import { Empty } from "./components";
|
||||
import { useFollowToday } from "./useToday";
|
||||
|
||||
export function Trends({
|
||||
records,
|
||||
|
|
@ -40,6 +41,7 @@ export function Trends({
|
|||
}) {
|
||||
const [period, setPeriod] = useState(7);
|
||||
const [end, setEnd] = useState(today());
|
||||
const now = useFollowToday(setEnd);
|
||||
const [metric, setMetric] = useState<Metric>("calories");
|
||||
const chartRef = useRef<HTMLDivElement>(null);
|
||||
const [chartWidth, setChartWidth] = useState(600);
|
||||
|
|
@ -152,13 +154,9 @@ export function Trends({
|
|||
<button
|
||||
className="icon-button"
|
||||
aria-label="Next period"
|
||||
disabled={end >= today()}
|
||||
disabled={end >= now}
|
||||
onClick={() =>
|
||||
setEnd(
|
||||
offsetDay(end, period) > today()
|
||||
? today()
|
||||
: offsetDay(end, period),
|
||||
)
|
||||
setEnd(offsetDay(end, period) > now ? now : offsetDay(end, period))
|
||||
}
|
||||
>
|
||||
<ChevronRight size={18} />
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { X, ArrowUpRight, Plus, Minus, Leaf } from "lucide-react";
|
|||
import { bubbleCount } from "../shared/bubble-physics.js";
|
||||
import { useBubblePhysics } from "./useBubblePhysics";
|
||||
import {
|
||||
meals,
|
||||
metrics,
|
||||
type Entry,
|
||||
type Food,
|
||||
|
|
@ -38,10 +39,27 @@ export function Modal({
|
|||
const closeRef = useRef(close);
|
||||
closeRef.current = close;
|
||||
const exiting = useExiting();
|
||||
const drag = useRef<{ y: number; distance: number } | null>(null);
|
||||
const drag = useRef<{
|
||||
y: number;
|
||||
distance: number;
|
||||
time: number;
|
||||
velocity: number;
|
||||
} | null>(null);
|
||||
const endDrag = (dismiss: boolean) => {
|
||||
drag.current = null;
|
||||
const dialog = ref.current;
|
||||
if (!dialog) return;
|
||||
dialog.classList.remove("sheet-dragging");
|
||||
// On dismissal the departure animation continues from the dragged position;
|
||||
// otherwise the sheet springs back.
|
||||
if (dismiss) close();
|
||||
else dialog.style.removeProperty("translate");
|
||||
};
|
||||
useEffect(() => {
|
||||
const dialog = ref.current!;
|
||||
dialog.showModal();
|
||||
if (matchMedia("(hover: hover) and (pointer: fine)").matches)
|
||||
dialog.querySelector<HTMLElement>("[data-autofocus]")?.focus();
|
||||
const listener = (event: Event) => {
|
||||
event.preventDefault();
|
||||
closeRef.current();
|
||||
|
|
@ -89,28 +107,41 @@ export function Modal({
|
|||
(event.target as HTMLElement).closest("button, input, select")
|
||||
)
|
||||
return;
|
||||
drag.current = { y: event.clientY, distance: 0 };
|
||||
drag.current = {
|
||||
y: event.clientY,
|
||||
distance: 0,
|
||||
time: event.timeStamp,
|
||||
velocity: 0,
|
||||
};
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
ref.current?.classList.add("sheet-dragging");
|
||||
}}
|
||||
onPointerMove={(event) => {
|
||||
if (!drag.current) return;
|
||||
drag.current.distance = Math.max(0, event.clientY - drag.current.y);
|
||||
const current = drag.current;
|
||||
if (!current) return;
|
||||
const distance = Math.max(0, event.clientY - current.y);
|
||||
const elapsed = event.timeStamp - current.time;
|
||||
if (elapsed > 0)
|
||||
current.velocity =
|
||||
0.8 * ((distance - current.distance) / elapsed) +
|
||||
0.2 * current.velocity;
|
||||
current.distance = distance;
|
||||
current.time = event.timeStamp;
|
||||
// The sheet tracks the finger 1:1, as UIKit sheets do.
|
||||
if (!matchMedia("(prefers-reduced-motion: reduce)").matches)
|
||||
ref.current?.style.setProperty(
|
||||
"translate",
|
||||
`0 ${Math.min(180, drag.current.distance * 0.65)}px`,
|
||||
);
|
||||
ref.current?.style.setProperty("translate", `0 ${distance}px`);
|
||||
}}
|
||||
onPointerUp={() => {
|
||||
const dismiss = (drag.current?.distance || 0) > 85;
|
||||
drag.current = null;
|
||||
ref.current?.style.removeProperty("translate");
|
||||
if (dismiss) close();
|
||||
}}
|
||||
onPointerCancel={() => {
|
||||
drag.current = null;
|
||||
ref.current?.style.removeProperty("translate");
|
||||
const current = drag.current;
|
||||
endDrag(
|
||||
Boolean(
|
||||
current &&
|
||||
(current.distance > 110 ||
|
||||
(current.distance > 24 && current.velocity > 0.45)),
|
||||
),
|
||||
);
|
||||
}}
|
||||
onPointerCancel={() => endDrag(false)}
|
||||
>
|
||||
<span className="sheet-grip" aria-hidden="true" />
|
||||
<div>
|
||||
|
|
@ -173,6 +204,7 @@ export function CalorieOrb({
|
|||
cy="160"
|
||||
r="145"
|
||||
className="orb-progress"
|
||||
opacity={enabled && value > 0 ? 1 : 0}
|
||||
strokeDasharray={`${enabled ? Math.min(value / goal, 1) * 911 : 0} 911`}
|
||||
transform="rotate(-90 160 160)"
|
||||
/>
|
||||
|
|
@ -226,7 +258,7 @@ export function NutrientFields({
|
|||
min="0"
|
||||
max="100000"
|
||||
step="any"
|
||||
required
|
||||
placeholder="0"
|
||||
value={nutrients[metric.key]}
|
||||
onChange={(e) =>
|
||||
set({
|
||||
|
|
@ -254,6 +286,8 @@ export function FoodEditor({
|
|||
foods,
|
||||
plates,
|
||||
mode = "log",
|
||||
template,
|
||||
initialTab = "manual",
|
||||
notify,
|
||||
}: {
|
||||
close: () => void;
|
||||
|
|
@ -263,17 +297,24 @@ export function FoodEditor({
|
|||
foods: JournalRecord<Food>[];
|
||||
plates: JournalRecord<Plate>[];
|
||||
mode?: "log" | "food";
|
||||
template?: Food;
|
||||
initialTab?: "manual" | "saved" | "plates";
|
||||
notify: (text: string) => void;
|
||||
}) {
|
||||
const initial = existing?.data;
|
||||
const initial = existing?.data || template;
|
||||
const { records } = useJournal();
|
||||
const [tab, setTab] = useState<"manual" | "saved" | "plates">("manual");
|
||||
const [tab, setTab] = useState(initialTab);
|
||||
const [name, setName] = useState(initial?.name || "");
|
||||
const [serving, setServing] = useState(initial?.serving || "1 serving");
|
||||
// New entries start blank (shown as a 0 placeholder) so typing never has to
|
||||
// clear a leading zero first; blanks are saved as 0.
|
||||
const [nutrients, setNutrients] = useState<Nutrients>(
|
||||
initial?.nutrients || (emptyNutrients() as Nutrients),
|
||||
initial?.nutrients ||
|
||||
(Object.fromEntries(
|
||||
Object.keys(emptyNutrients()).map((key) => [key, ""]),
|
||||
) as unknown as Nutrients),
|
||||
);
|
||||
const [quantity, setQuantity] = useState(
|
||||
const [quantity, setQuantity] = useState<number | "">(
|
||||
existing?.type === "entry" ? (initial as Entry).quantity : 1,
|
||||
);
|
||||
const [selectedMeal, setMeal] = useState<Meal>(
|
||||
|
|
@ -300,6 +341,7 @@ export function FoodEditor({
|
|||
)
|
||||
.map((r) => (r.data as Food).name),
|
||||
);
|
||||
const mealLabel = useId();
|
||||
const [saveFood, setSaveFood] = useState(false);
|
||||
const [search, setSearch] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
|
|
@ -311,10 +353,17 @@ export function FoodEditor({
|
|||
try {
|
||||
if (mode === "log" && (!selectedDate || (!existing && !time)))
|
||||
throw new Error("Choose an entry date and time.");
|
||||
if (mode === "log" && !(Number(quantity) > 0))
|
||||
throw new Error("Enter how many servings you had.");
|
||||
const food = {
|
||||
name: name.trim() || fallbackName,
|
||||
serving: serving.trim(),
|
||||
nutrients,
|
||||
nutrients: Object.fromEntries(
|
||||
Object.entries(nutrients).map(([key, value]) => [
|
||||
key,
|
||||
Number(value) || 0,
|
||||
]),
|
||||
) as Nutrients,
|
||||
};
|
||||
const items: Parameters<typeof putRecords>[0] = [
|
||||
{
|
||||
|
|
@ -328,7 +377,7 @@ export function FoodEditor({
|
|||
date: selectedDate,
|
||||
...(time ? { time } : {}),
|
||||
meal: selectedMeal,
|
||||
quantity,
|
||||
quantity: Number(quantity),
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
@ -427,17 +476,29 @@ export function FoodEditor({
|
|||
onChange={(e) => setTime(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Meal
|
||||
<select
|
||||
value={selectedMeal}
|
||||
onChange={(e) => setMeal(e.target.value as Meal)}
|
||||
<div className="meal-choice">
|
||||
<span className="field-label" id={mealLabel}>
|
||||
Meal
|
||||
</span>
|
||||
<div
|
||||
className="meal-picker"
|
||||
role="radiogroup"
|
||||
aria-labelledby={mealLabel}
|
||||
>
|
||||
{["Breakfast", "Lunch", "Dinner", "Snacks"].map((m) => (
|
||||
<option key={m}>{m}</option>
|
||||
{meals.map((m) => (
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
key={m}
|
||||
aria-checked={selectedMeal === m}
|
||||
className={selectedMeal === m ? "active" : ""}
|
||||
onClick={() => setMeal(m)}
|
||||
>
|
||||
{m === "Snacks" ? "Snack" : m}
|
||||
</button>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{tab !== "manual" ? (
|
||||
|
|
@ -519,7 +580,7 @@ export function FoodEditor({
|
|||
<label>
|
||||
Food name <span className="muted">(optional)</span>
|
||||
<input
|
||||
autoFocus
|
||||
data-autofocus
|
||||
maxLength={160}
|
||||
placeholder={fallbackName}
|
||||
value={name}
|
||||
|
|
@ -547,7 +608,9 @@ export function FoodEditor({
|
|||
step="any"
|
||||
required
|
||||
value={quantity}
|
||||
onChange={(e) => setQuantity(+e.target.value)}
|
||||
onChange={(e) =>
|
||||
setQuantity(e.target.value === "" ? "" : +e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
|
|
@ -579,7 +642,7 @@ export function FoodEditor({
|
|||
? "Save changes"
|
||||
: mode === "food"
|
||||
? "Save food"
|
||||
: `Add ${number(nutrients.calories * quantity)} kcal`}
|
||||
: `Add ${number((Number(nutrients.calories) || 0) * (Number(quantity) || 0))} kcal`}
|
||||
<Plus size={18} />
|
||||
</button>
|
||||
</form>
|
||||
|
|
@ -638,7 +701,7 @@ export function PlateEditor({
|
|||
Plate name
|
||||
<input
|
||||
required
|
||||
autoFocus
|
||||
data-autofocus
|
||||
maxLength={160}
|
||||
placeholder="e.g. My usual breakfast"
|
||||
value={name}
|
||||
|
|
@ -766,7 +829,7 @@ export function WeightEditor({
|
|||
<label>
|
||||
Weight ({unit})
|
||||
<input
|
||||
autoFocus
|
||||
data-autofocus
|
||||
type="number"
|
||||
inputMode="decimal"
|
||||
step="any"
|
||||
|
|
|
|||
316
src/desktop.css
Normal file
316
src/desktop.css
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
/* Desktop and tablet type scale. The original desktop ramp went down to 7px;
|
||||
these sizes keep captions at 10–12px and body copy at 13–15px. Phone sizes
|
||||
live in mobile.css, which is imported afterwards and takes precedence. */
|
||||
p {
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.small {
|
||||
font-size: 12px;
|
||||
}
|
||||
.eyebrow,
|
||||
.balance-card .eyebrow,
|
||||
.card-title .eyebrow,
|
||||
.sheet .eyebrow,
|
||||
.login-form > .eyebrow {
|
||||
font-size: 10px;
|
||||
letter-spacing: 1.3px;
|
||||
}
|
||||
.primary,
|
||||
.secondary,
|
||||
.danger-button {
|
||||
font-size: 14px;
|
||||
}
|
||||
.text-button {
|
||||
font-size: 14px;
|
||||
}
|
||||
.pill {
|
||||
font-size: 12px;
|
||||
}
|
||||
.balance-card .pill {
|
||||
font-size: 12px;
|
||||
}
|
||||
.tiny-badge {
|
||||
font-size: 10px;
|
||||
}
|
||||
.sidebar-caption {
|
||||
font-size: 10px;
|
||||
letter-spacing: 1.4px;
|
||||
}
|
||||
@media (min-width: 901px) {
|
||||
.sidebar nav > button {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
.breadcrumb {
|
||||
font-size: 13px;
|
||||
}
|
||||
.sync-indicator {
|
||||
font-size: 12px;
|
||||
}
|
||||
.profile-avatar {
|
||||
font-size: 13px;
|
||||
}
|
||||
.page-heading p {
|
||||
font-size: 14px;
|
||||
}
|
||||
.week-day > span {
|
||||
font-size: 11px;
|
||||
}
|
||||
.week-day strong {
|
||||
font-size: 15px;
|
||||
}
|
||||
.orb-number.orb-number-outside .eyebrow {
|
||||
font-size: 10px;
|
||||
}
|
||||
.orb-number.orb-number-outside strong {
|
||||
font-size: 46px;
|
||||
}
|
||||
.orb-number .orb-unit {
|
||||
font-size: 13px;
|
||||
}
|
||||
.calorie-summary > div {
|
||||
font-size: 12px;
|
||||
}
|
||||
.calorie-summary strong {
|
||||
font-size: 17px;
|
||||
}
|
||||
.macro-label {
|
||||
font-size: 12px;
|
||||
}
|
||||
.macro strong {
|
||||
font-size: 20px;
|
||||
}
|
||||
.macro > div > span {
|
||||
font-size: 12px;
|
||||
}
|
||||
.balance-footer {
|
||||
font-size: 12px;
|
||||
}
|
||||
.subtle-number {
|
||||
font-size: 12px;
|
||||
}
|
||||
.meal-heading h3 {
|
||||
font-size: 15px;
|
||||
}
|
||||
.meal-total {
|
||||
font-size: 14px;
|
||||
}
|
||||
.meal-total small {
|
||||
font-size: 11px;
|
||||
}
|
||||
.empty-meal {
|
||||
font-size: 13px;
|
||||
}
|
||||
.food-log-copy > strong {
|
||||
font-size: 14px;
|
||||
}
|
||||
.food-log-copy > small {
|
||||
font-size: 12px;
|
||||
}
|
||||
.entry-calories {
|
||||
font-size: 15px;
|
||||
}
|
||||
.entry-calories > small {
|
||||
font-size: 11px;
|
||||
}
|
||||
.library-prompt strong {
|
||||
font-size: 15px;
|
||||
}
|
||||
.library-prompt small {
|
||||
font-size: 12px;
|
||||
}
|
||||
.page-footnote {
|
||||
font-size: 12px;
|
||||
}
|
||||
.notice,
|
||||
.notice > button {
|
||||
font-size: 13px;
|
||||
}
|
||||
.toast {
|
||||
font-size: 14px;
|
||||
}
|
||||
.sheet-head p {
|
||||
font-size: 14px;
|
||||
}
|
||||
label {
|
||||
font-size: 13px;
|
||||
}
|
||||
input:not([type="checkbox"]),
|
||||
select,
|
||||
textarea {
|
||||
font-size: 14px;
|
||||
}
|
||||
.unit-input > span {
|
||||
font-size: 12px;
|
||||
}
|
||||
.section-caption {
|
||||
font-size: 13px;
|
||||
}
|
||||
.section-caption > span:last-child {
|
||||
font-size: 12px;
|
||||
}
|
||||
.nutrient-fields label {
|
||||
font-size: 12px;
|
||||
}
|
||||
.nutrient-fields label:first-child {
|
||||
font-size: 14px;
|
||||
}
|
||||
.check-row {
|
||||
font-size: 14px;
|
||||
}
|
||||
.error {
|
||||
font-size: 13px;
|
||||
}
|
||||
.picker-row strong {
|
||||
font-size: 15px;
|
||||
}
|
||||
.picker-row small {
|
||||
font-size: 12px;
|
||||
}
|
||||
.empty p {
|
||||
font-size: 14px;
|
||||
}
|
||||
.plate-item strong {
|
||||
font-size: 14px;
|
||||
}
|
||||
.plate-item small {
|
||||
font-size: 12px;
|
||||
}
|
||||
.segmented > button,
|
||||
.theme-control button,
|
||||
.sheet .segmented button {
|
||||
font-size: 13px;
|
||||
}
|
||||
.segmented > button > span {
|
||||
font-size: 11px;
|
||||
}
|
||||
.library-food-info p {
|
||||
font-size: 13px;
|
||||
}
|
||||
.library-food-info > strong > span {
|
||||
font-size: 13px;
|
||||
}
|
||||
.food-macros {
|
||||
font-size: 12px;
|
||||
}
|
||||
.library-card-actions .text-button {
|
||||
font-size: 13px;
|
||||
}
|
||||
.library-bottom {
|
||||
font-size: 13px;
|
||||
}
|
||||
.date-controls {
|
||||
font-size: 13px;
|
||||
}
|
||||
.chart-card .card-title select {
|
||||
font-size: 13px;
|
||||
max-width: 150px;
|
||||
}
|
||||
.stat-large > span {
|
||||
font-size: 13px;
|
||||
}
|
||||
.chart-grid-lines,
|
||||
.bar-slot > span,
|
||||
.goal-line > span {
|
||||
font-size: 11px;
|
||||
}
|
||||
.chart-note {
|
||||
font-size: 12px;
|
||||
}
|
||||
.weight-axis {
|
||||
font-size: 11px;
|
||||
}
|
||||
.weight-chart text {
|
||||
font-size: 12px;
|
||||
}
|
||||
.chart-card .empty p {
|
||||
font-size: 13px;
|
||||
}
|
||||
.row-copy strong {
|
||||
font-size: 15px;
|
||||
}
|
||||
.row-copy small {
|
||||
font-size: 12px;
|
||||
}
|
||||
.settings-card > .muted {
|
||||
font-size: 13px;
|
||||
}
|
||||
.goal-head {
|
||||
font-size: 11px;
|
||||
}
|
||||
.toggle-label {
|
||||
font-size: 14px;
|
||||
}
|
||||
.goal-input input:not([type="checkbox"]),
|
||||
.settings-card .goal-input input {
|
||||
font-size: 14px;
|
||||
}
|
||||
.goal-input > span {
|
||||
font-size: 12px;
|
||||
}
|
||||
.settings-section h3 {
|
||||
font-size: 15px;
|
||||
}
|
||||
.custom-accent > code {
|
||||
font-size: 12px;
|
||||
}
|
||||
.preference-row,
|
||||
.preference-row select {
|
||||
font-size: 14px;
|
||||
}
|
||||
.field-caption {
|
||||
font-size: 11px;
|
||||
}
|
||||
.settings-card .small {
|
||||
font-size: 12px;
|
||||
}
|
||||
.export-options .check-row {
|
||||
font-size: 13px;
|
||||
}
|
||||
.status-detail strong {
|
||||
font-size: 14px;
|
||||
}
|
||||
.status-detail small {
|
||||
font-size: 12px;
|
||||
}
|
||||
.install-tip {
|
||||
font-size: 13px;
|
||||
}
|
||||
.account-row > div {
|
||||
font-size: 13px;
|
||||
}
|
||||
.account-row small {
|
||||
font-size: 11px;
|
||||
}
|
||||
.account-row .text-button {
|
||||
font-size: 13px;
|
||||
}
|
||||
.login-copy p {
|
||||
font-size: 15px;
|
||||
}
|
||||
.art-label {
|
||||
font-size: 13px;
|
||||
}
|
||||
.login-footer {
|
||||
font-size: 10px;
|
||||
}
|
||||
.login-form > p {
|
||||
font-size: 14px;
|
||||
}
|
||||
.login-note {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* Switches sized like macOS toggles; phones use the 51×31 iOS size. */
|
||||
.switch {
|
||||
width: 36px;
|
||||
height: 21px;
|
||||
}
|
||||
.switch:after {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
}
|
||||
.switch:checked:after {
|
||||
transform: translateX(15px);
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import React from "react";
|
|||
import { createRoot } from "react-dom/client";
|
||||
import { App } from "./App";
|
||||
import "./styles.css";
|
||||
import "./desktop.css";
|
||||
import "./mobile.css";
|
||||
import "./motion.css";
|
||||
import "./pager.css";
|
||||
|
|
|
|||
|
|
@ -164,6 +164,7 @@
|
|||
}
|
||||
.toast {
|
||||
font-size: 15px;
|
||||
left: 50%;
|
||||
bottom: calc(var(--mobile-nav-height) + 12px);
|
||||
padding: 14px 18px;
|
||||
}
|
||||
|
|
@ -502,11 +503,20 @@
|
|||
white-space: normal;
|
||||
}
|
||||
.sheet .entry-details {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 14px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 14px 12px;
|
||||
}
|
||||
.sheet .entry-details > label:first-child {
|
||||
grid-column: auto;
|
||||
.sheet .entry-details input {
|
||||
font-size: 17px;
|
||||
padding-inline: 12px;
|
||||
}
|
||||
.field-label {
|
||||
font-size: 16px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.meal-picker > button {
|
||||
min-height: 44px;
|
||||
font-size: 15px;
|
||||
}
|
||||
.sheet label {
|
||||
font-size: 16px;
|
||||
|
|
@ -694,12 +704,16 @@
|
|||
font-size: 12px;
|
||||
}
|
||||
.accent-swatches {
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
gap: 4px;
|
||||
}
|
||||
.accent-swatches > button {
|
||||
flex: 0 1 44px;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
height: auto;
|
||||
min-width: 34px;
|
||||
aspect-ratio: 1;
|
||||
}
|
||||
.custom-accent {
|
||||
font-size: 16px;
|
||||
|
|
@ -732,17 +746,41 @@
|
|||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 16px;
|
||||
}
|
||||
/* Compact rows: name, serving and nutrition beside the avatar. */
|
||||
.library-card {
|
||||
padding: 20px;
|
||||
display: grid;
|
||||
grid-template-columns: 44px minmax(0, 1fr);
|
||||
column-gap: 14px;
|
||||
padding: 16px 16px 6px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
.library-card > .food-avatar {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 13px;
|
||||
}
|
||||
.library-food-info h3 {
|
||||
font-size: 20px;
|
||||
font-size: 18px;
|
||||
line-height: 1.3;
|
||||
margin-top: 0;
|
||||
}
|
||||
.library-food-info p {
|
||||
font-size: 15px;
|
||||
line-height: 1.4;
|
||||
margin: 2px 0 8px;
|
||||
min-height: 0;
|
||||
}
|
||||
.library-food-info > strong {
|
||||
font-size: 22px;
|
||||
}
|
||||
.food-macros {
|
||||
font-size: 14px;
|
||||
margin: 6px 0 12px;
|
||||
}
|
||||
.library-card-actions {
|
||||
grid-column: 1 / -1;
|
||||
padding-top: 2px;
|
||||
gap: 22px;
|
||||
}
|
||||
.library-card-actions .text-button {
|
||||
font-size: 15px;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,10 @@ button {
|
|||
}
|
||||
.sheet[open] {
|
||||
animation: sheet-arrive 260ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
|
||||
transition: translate 160ms ease-out;
|
||||
transition: translate 320ms cubic-bezier(0.32, 0.72, 0, 1);
|
||||
}
|
||||
.sheet[open].sheet-dragging {
|
||||
transition: none;
|
||||
}
|
||||
.sheet[open]::backdrop {
|
||||
background: #08090d88;
|
||||
|
|
@ -73,6 +76,13 @@ button {
|
|||
.icon-button:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
.toast[popover] {
|
||||
top: auto;
|
||||
right: auto;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
overflow: visible;
|
||||
}
|
||||
.toast {
|
||||
animation: toast-arrive 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
|
||||
}
|
||||
|
|
@ -138,25 +148,32 @@ button {
|
|||
background: var(--muted);
|
||||
opacity: 0.4;
|
||||
}
|
||||
/* Opaque slide on the UIKit sheet curve; no cross-fade. */
|
||||
.sheet[open] {
|
||||
animation-name: mobile-sheet-arrive;
|
||||
animation: mobile-sheet-arrive 420ms cubic-bezier(0.32, 0.72, 0, 1) both;
|
||||
}
|
||||
.sheet[open].sheet-exiting {
|
||||
animation-name: mobile-sheet-depart;
|
||||
animation: mobile-sheet-depart 240ms cubic-bezier(0.4, 0, 0.9, 0.6) both;
|
||||
}
|
||||
.sheet[open]::backdrop {
|
||||
animation-duration: 320ms;
|
||||
}
|
||||
.sheet[open].sheet-exiting::backdrop {
|
||||
animation-duration: 240ms;
|
||||
}
|
||||
@keyframes mobile-sheet-arrive {
|
||||
from {
|
||||
opacity: 0.5;
|
||||
transform: translateY(100%);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
@keyframes mobile-sheet-depart {
|
||||
from {
|
||||
transform: translateY(0);
|
||||
}
|
||||
to {
|
||||
opacity: 0.5;
|
||||
transform: translateY(100%);
|
||||
}
|
||||
}
|
||||
|
|
@ -174,3 +191,47 @@ button {
|
|||
scroll-behavior: auto !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* Touch devices: dim pressed controls as UIKit does, and keep long-presses on
|
||||
app chrome from selecting text or opening the callout menu. */
|
||||
.toast-error > svg {
|
||||
color: var(--danger);
|
||||
}
|
||||
@media (hover: none) {
|
||||
.app-shell,
|
||||
.sheet {
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
-webkit-touch-callout: none;
|
||||
}
|
||||
.app-shell input,
|
||||
.app-shell textarea,
|
||||
.sheet input,
|
||||
.sheet textarea {
|
||||
-webkit-user-select: text;
|
||||
user-select: text;
|
||||
}
|
||||
.food-log-copy,
|
||||
.picker-row,
|
||||
.week-day,
|
||||
.empty-meal,
|
||||
.mobile-journal-button,
|
||||
.text-button,
|
||||
.library-prompt,
|
||||
.meal-picker > button,
|
||||
.sync-indicator {
|
||||
transition: opacity 120ms ease;
|
||||
}
|
||||
.food-log-copy:active,
|
||||
.picker-row:active,
|
||||
.week-day:active,
|
||||
.empty-meal:active,
|
||||
.mobile-journal-button:active,
|
||||
.text-button:active,
|
||||
.library-prompt:active,
|
||||
.meal-picker > button:active,
|
||||
.sync-indicator:active {
|
||||
opacity: 0.55;
|
||||
transition-duration: 0ms;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
32
src/store.ts
32
src/store.ts
|
|
@ -44,6 +44,7 @@ const subscribeSync = (fn: () => void) => {
|
|||
syncListeners.delete(fn);
|
||||
};
|
||||
};
|
||||
export const pendingChanges = () => snapshot.outbox.length;
|
||||
export const useJournal = () => useSyncExternalStore(subscribe, () => snapshot);
|
||||
export const useSyncStatus = () =>
|
||||
useSyncExternalStore(subscribeSync, () => syncState);
|
||||
|
|
@ -101,15 +102,30 @@ export const saveRecord = (type: RecordType, data: unknown, id?: string) =>
|
|||
export const deleteRecord = (record: JournalRecord) =>
|
||||
putRecords([{ ...record, deleted: true }]);
|
||||
export async function api(path: string, body?: unknown) {
|
||||
const response = await fetch("/api" + path, {
|
||||
method: body === undefined ? "GET" : "POST",
|
||||
headers: { "Content-Type": "application/json", "X-Calio-Request": "1" },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
signal: AbortSignal.timeout(15000),
|
||||
});
|
||||
const data = await response.json();
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetch("/api" + path, {
|
||||
method: body === undefined ? "GET" : "POST",
|
||||
headers: { "Content-Type": "application/json", "X-Calio-Request": "1" },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
signal: AbortSignal.timeout(15000),
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
(error as Error).name === "TimeoutError"
|
||||
? "The Calio server took too long to respond."
|
||||
: "Couldn’t reach the Calio server.",
|
||||
);
|
||||
}
|
||||
// A reverse proxy can answer with an HTML error page; never show its parse error.
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
const error = new Error(data.error || "Unable to connect") as Error & {
|
||||
const error = new Error(
|
||||
data.error ||
|
||||
(response.status >= 500
|
||||
? "The Calio server is unavailable right now."
|
||||
: "Unable to connect"),
|
||||
) as Error & {
|
||||
status: number;
|
||||
};
|
||||
error.status = response.status;
|
||||
|
|
|
|||
128
src/styles.css
128
src/styles.css
|
|
@ -177,18 +177,22 @@ p {
|
|||
color: var(--on-accent);
|
||||
background: var(--accent);
|
||||
}
|
||||
.primary:hover:not(:disabled) {
|
||||
background: var(--accent-dark);
|
||||
color: var(--on-accent-hover);
|
||||
transform: translateY(-1px);
|
||||
@media (hover: hover) {
|
||||
.primary:hover:not(:disabled) {
|
||||
background: var(--accent-dark);
|
||||
color: var(--on-accent-hover);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
}
|
||||
.secondary {
|
||||
border: 1px solid var(--line);
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
}
|
||||
.secondary:hover {
|
||||
background: var(--surface-soft);
|
||||
@media (hover: hover) {
|
||||
.secondary:hover {
|
||||
background: var(--surface-soft);
|
||||
}
|
||||
}
|
||||
.danger-button {
|
||||
background: var(--danger);
|
||||
|
|
@ -207,9 +211,11 @@ p {
|
|||
color: var(--muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.icon-button:hover:not(:disabled) {
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent-text);
|
||||
@media (hover: hover) {
|
||||
.icon-button:hover:not(:disabled) {
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent-text);
|
||||
}
|
||||
}
|
||||
.text-button {
|
||||
color: var(--accent-text);
|
||||
|
|
@ -220,8 +226,10 @@ p {
|
|||
font-weight: 550;
|
||||
min-height: 36px;
|
||||
}
|
||||
.text-button:hover {
|
||||
text-decoration: underline;
|
||||
@media (hover: hover) {
|
||||
.text-button:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
.card {
|
||||
background: var(--surface);
|
||||
|
|
@ -335,8 +343,10 @@ p {
|
|||
color: var(--accent-text);
|
||||
font-weight: 600;
|
||||
}
|
||||
.sidebar nav > button:hover {
|
||||
color: var(--accent-text);
|
||||
@media (hover: hover) {
|
||||
.sidebar nav > button:hover {
|
||||
color: var(--accent-text);
|
||||
}
|
||||
}
|
||||
.nav-dot {
|
||||
margin-left: auto;
|
||||
|
|
@ -793,11 +803,15 @@ main {
|
|||
.empty-meal svg {
|
||||
opacity: 0;
|
||||
}
|
||||
.empty-meal:hover {
|
||||
color: var(--accent-text);
|
||||
@media (hover: hover) {
|
||||
.empty-meal:hover {
|
||||
color: var(--accent-text);
|
||||
}
|
||||
}
|
||||
.empty-meal:hover svg {
|
||||
opacity: 1;
|
||||
@media (hover: hover) {
|
||||
.empty-meal:hover svg {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.food-log-row {
|
||||
display: flex;
|
||||
|
|
@ -840,9 +854,11 @@ main {
|
|||
height: 32px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
.delete-entry:hover {
|
||||
color: var(--danger) !important;
|
||||
opacity: 1;
|
||||
@media (hover: hover) {
|
||||
.delete-entry:hover {
|
||||
color: var(--danger) !important;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.library-prompt {
|
||||
padding: 22px;
|
||||
|
|
@ -856,8 +872,10 @@ main {
|
|||
width: 100%;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
.library-prompt:hover {
|
||||
border-color: var(--accent);
|
||||
@media (hover: hover) {
|
||||
.library-prompt:hover {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
}
|
||||
.prompt-icon {
|
||||
width: 40px;
|
||||
|
|
@ -1066,7 +1084,46 @@ textarea {
|
|||
margin-bottom: 18px;
|
||||
}
|
||||
.entry-details {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.meal-choice {
|
||||
grid-column: 1 / -1;
|
||||
min-width: 0;
|
||||
}
|
||||
.field-label {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.meal-picker {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 2px;
|
||||
margin-top: 8px;
|
||||
padding: 3px;
|
||||
border-radius: 11px;
|
||||
background: var(--surface-soft);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.meal-picker > button {
|
||||
min-width: 0;
|
||||
min-height: 36px;
|
||||
padding: 6px 4px;
|
||||
border-radius: 8px;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
transition:
|
||||
background-color 180ms ease,
|
||||
color 180ms ease;
|
||||
}
|
||||
.meal-picker > button.active {
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent-text);
|
||||
font-weight: 600;
|
||||
}
|
||||
.unit-input {
|
||||
display: flex;
|
||||
|
|
@ -1177,8 +1234,10 @@ textarea {
|
|||
color: var(--muted);
|
||||
margin-top: 6px;
|
||||
}
|
||||
.picker-row:hover {
|
||||
color: var(--accent-text);
|
||||
@media (hover: hover) {
|
||||
.picker-row:hover {
|
||||
color: var(--accent-text);
|
||||
}
|
||||
}
|
||||
.empty {
|
||||
padding: 55px 20px;
|
||||
|
|
@ -1366,14 +1425,20 @@ textarea {
|
|||
.library-card-actions {
|
||||
border-top: 1px solid var(--line);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 18px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
.library-card-actions > .icon-button {
|
||||
margin-left: auto;
|
||||
}
|
||||
.library-card-actions .text-button {
|
||||
font-size: 10px;
|
||||
}
|
||||
.danger-hover:hover {
|
||||
color: var(--danger) !important;
|
||||
@media (hover: hover) {
|
||||
.danger-hover:hover {
|
||||
color: var(--danger) !important;
|
||||
}
|
||||
}
|
||||
.library-empty {
|
||||
min-height: 370px;
|
||||
|
|
@ -2545,12 +2610,7 @@ textarea {
|
|||
.form-row {
|
||||
gap: 12px;
|
||||
}
|
||||
.entry-details {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.entry-details > label:first-child {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.sheet .picker-row {
|
||||
min-height: 64px;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,19 @@ export function useBubblePhysics(count: number) {
|
|||
);
|
||||
context.fill();
|
||||
}
|
||||
for (const bubble of simulation.fading) {
|
||||
context.globalAlpha =
|
||||
Math.max(0, bubble.life) * (0.72 + (bubble.id % 4) * 0.08);
|
||||
context.beginPath();
|
||||
context.arc(
|
||||
bubble.x,
|
||||
bubble.y,
|
||||
DRAW_BUBBLE_RADIUS * (0.7 + 0.3 * Math.max(0, bubble.life)),
|
||||
0,
|
||||
Math.PI * 2,
|
||||
);
|
||||
context.fill();
|
||||
}
|
||||
context.globalAlpha = 1;
|
||||
element.dataset.bubbles = String(simulation.balls.length);
|
||||
element.dataset.gravityX = simulation.engine.gravity.x.toFixed(3);
|
||||
|
|
|
|||
37
src/useToday.ts
Normal file
37
src/useToday.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { useEffect, useRef, useState } from "react";
|
||||
import { today } from "./utils";
|
||||
|
||||
// Installed PWAs stay in memory for days. Re-check the local date whenever the
|
||||
// app returns to the foreground, and once a minute while it is open.
|
||||
export function useToday() {
|
||||
const [value, setValue] = useState(today);
|
||||
useEffect(() => {
|
||||
const check = () => {
|
||||
if (!document.hidden) setValue(today());
|
||||
};
|
||||
const timer = setInterval(check, 60000);
|
||||
document.addEventListener("visibilitychange", check);
|
||||
window.addEventListener("focus", check);
|
||||
return () => {
|
||||
clearInterval(timer);
|
||||
document.removeEventListener("visibilitychange", check);
|
||||
window.removeEventListener("focus", check);
|
||||
};
|
||||
}, []);
|
||||
return value;
|
||||
}
|
||||
|
||||
// Keeps a date that was following "today" on the new day, while leaving a day
|
||||
// the person picked deliberately alone.
|
||||
export function useFollowToday(
|
||||
setDate: (update: (date: string) => string) => void,
|
||||
) {
|
||||
const current = useToday();
|
||||
const previous = useRef(current);
|
||||
useEffect(() => {
|
||||
const before = previous.current;
|
||||
previous.current = current;
|
||||
if (before !== current) setDate((d) => (d === before ? current : d));
|
||||
}, [current, setDate]);
|
||||
return current;
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
// Development-only browser regression probe. Run on an unlocked localhost preview
|
||||
// with Runtime.evaluate (awaitPromise: true). It changes navigation and draft input
|
||||
// only, restores the draft, and never saves or deletes journal records.
|
||||
// only. Settings autosave, so the cutoff it edits is saved and then restored;
|
||||
// it never deletes journal records.
|
||||
(async () => {
|
||||
const checks = {};
|
||||
const pause = (ms = 380) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
|
@ -58,7 +59,7 @@
|
|||
checks.lastTabDoesNotWrap = page() === 'Settings';
|
||||
await nav('Weight');
|
||||
await nav('Settings');
|
||||
checks.unsavedPreferencesSurviveNavigation = cutoff.value === '987';
|
||||
checks.preferenceEditsSurviveNavigation = cutoff.value === '987';
|
||||
changeValue(original);
|
||||
visible('.bottom-nav button').find(e => e.textContent.trim() === 'Library').click();
|
||||
visible('.bottom-nav button').find(e => e.textContent.trim() === 'Weight').click();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue