Extensive UI changes
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
This commit is contained in:
parent
6fc0a01c56
commit
ddea7fc512
16 changed files with 675 additions and 493 deletions
|
|
@ -1,13 +1,5 @@
|
|||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import {
|
||||
X,
|
||||
ArrowUpRight,
|
||||
Plus,
|
||||
Minus,
|
||||
Leaf,
|
||||
Smartphone,
|
||||
RotateCcw,
|
||||
} from "lucide-react";
|
||||
import { X, ArrowUpRight, Plus, Minus, Leaf } from "lucide-react";
|
||||
import { bubbleCount } from "../shared/bubble-physics.js";
|
||||
import { useBubblePhysics } from "./useBubblePhysics";
|
||||
import {
|
||||
|
|
@ -22,7 +14,8 @@ import {
|
|||
type Weight,
|
||||
} from "./types";
|
||||
import { emptyNutrients } from "../shared/domain.js";
|
||||
import { saveRecord, putRecords } from "./store";
|
||||
import { saveRecord, putRecords, useJournal } from "./store";
|
||||
import { localTime, nextFoodName } from "../shared/entry.js";
|
||||
import { displayDate, number, today, weightValue } from "./utils";
|
||||
|
||||
export function Modal({
|
||||
|
|
@ -91,15 +84,12 @@ export function CalorieOrb({
|
|||
goal,
|
||||
enabled,
|
||||
small = false,
|
||||
interactive = true,
|
||||
}: {
|
||||
value: number;
|
||||
goal: number;
|
||||
enabled: boolean;
|
||||
small?: boolean;
|
||||
interactive?: boolean;
|
||||
}) {
|
||||
const ratio = enabled ? Math.min(value / goal, 1) : Math.min(value / 2500, 1);
|
||||
const physics = useBubblePhysics(bubbleCount(value, goal, enabled));
|
||||
const readout = (
|
||||
<>
|
||||
|
|
@ -141,55 +131,8 @@ export function CalorieOrb({
|
|||
ref={physics.canvas}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{!small && ratio < 0.85 && (
|
||||
<div
|
||||
className={"orb-number " + (ratio > 0.47 ? "orb-number-high" : "")}
|
||||
>
|
||||
{readout}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{!small && ratio >= 0.85 && (
|
||||
<div className="orb-number orb-number-outside">{readout}</div>
|
||||
)}
|
||||
{interactive && !small && (
|
||||
<>
|
||||
<div className="orb-motion-controls">
|
||||
<button
|
||||
disabled={physics.reduced}
|
||||
aria-pressed={physics.enabled}
|
||||
onClick={() => void physics.toggleTilt()}
|
||||
>
|
||||
<Smartphone size={12} />
|
||||
{physics.reduced
|
||||
? "Reduced motion"
|
||||
: physics.motion === "on"
|
||||
? "Tilt enabled"
|
||||
: physics.motion === "waiting"
|
||||
? "Waiting for tilt…"
|
||||
: physics.enabled
|
||||
? "Turn tilt off"
|
||||
: "Enable tilt"}
|
||||
</button>
|
||||
<span />
|
||||
<button disabled={physics.reduced} onClick={physics.nudge}>
|
||||
<RotateCcw size={12} />
|
||||
Give a nudge
|
||||
</button>
|
||||
</div>
|
||||
{physics.motion === "denied" && (
|
||||
<p className="motion-help" role="status">
|
||||
Motion access was not granted. You can allow it in your browser’s
|
||||
website settings.
|
||||
</p>
|
||||
)}
|
||||
{physics.motion === "unavailable" && (
|
||||
<p className="motion-help" role="status">
|
||||
No tilt data yet. Falling bubbles still work on this device.
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{!small && <div className="orb-number orb-number-outside">{readout}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -272,6 +215,7 @@ export function FoodEditor({
|
|||
notify: (text: string) => void;
|
||||
}) {
|
||||
const initial = existing?.data;
|
||||
const { records } = useJournal();
|
||||
const [tab, setTab] = useState<"manual" | "saved" | "plates">("manual");
|
||||
const [name, setName] = useState(initial?.name || "");
|
||||
const [serving, setServing] = useState(initial?.serving || "1 serving");
|
||||
|
|
@ -287,6 +231,24 @@ export function FoodEditor({
|
|||
const [selectedDate, setDate] = useState(
|
||||
existing?.type === "entry" ? (initial as Entry).date : date,
|
||||
);
|
||||
const [time, setTime] = useState(
|
||||
existing?.type === "entry" ? (initial as Entry).time || "" : localTime(),
|
||||
);
|
||||
const fallbackName = nextFoodName(
|
||||
mode === "food" ? "Food" : selectedMeal,
|
||||
records
|
||||
.filter(
|
||||
(r) =>
|
||||
!r.deleted &&
|
||||
r.id !== existing?.id &&
|
||||
(mode === "food"
|
||||
? r.type === "food"
|
||||
: r.type === "entry" &&
|
||||
(r.data as Entry).date === selectedDate &&
|
||||
(r.data as Entry).meal === selectedMeal),
|
||||
)
|
||||
.map((r) => (r.data as Food).name),
|
||||
);
|
||||
const [saveFood, setSaveFood] = useState(false);
|
||||
const [search, setSearch] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
|
|
@ -296,7 +258,13 @@ export function FoodEditor({
|
|||
setBusy(true);
|
||||
setError("");
|
||||
try {
|
||||
const food = { name: name.trim(), serving: serving.trim(), nutrients };
|
||||
if (mode === "log" && (!selectedDate || (!existing && !time)))
|
||||
throw new Error("Choose an entry date and time.");
|
||||
const food = {
|
||||
name: name.trim() || fallbackName,
|
||||
serving: serving.trim(),
|
||||
nutrients,
|
||||
};
|
||||
const items: Parameters<typeof putRecords>[0] = [
|
||||
{
|
||||
type: mode === "food" ? "food" : "entry",
|
||||
|
|
@ -304,7 +272,13 @@ export function FoodEditor({
|
|||
data:
|
||||
mode === "food"
|
||||
? food
|
||||
: { ...food, date: selectedDate, meal: selectedMeal, quantity },
|
||||
: {
|
||||
...food,
|
||||
date: selectedDate,
|
||||
...(time ? { time } : {}),
|
||||
meal: selectedMeal,
|
||||
quantity,
|
||||
},
|
||||
},
|
||||
];
|
||||
if (saveFood && mode === "log") items.push({ type: "food", data: food });
|
||||
|
|
@ -327,10 +301,12 @@ export function FoodEditor({
|
|||
setBusy(true);
|
||||
setError("");
|
||||
try {
|
||||
if (!selectedDate || !time)
|
||||
throw new Error("Choose an entry date and time.");
|
||||
await putRecords(
|
||||
plate.items.map((item) => ({
|
||||
type: "entry",
|
||||
data: { ...item, date: selectedDate, meal: selectedMeal },
|
||||
data: { ...item, date: selectedDate, time, meal: selectedMeal },
|
||||
})),
|
||||
);
|
||||
notify(`${plate.name} added to your day`);
|
||||
|
|
@ -379,7 +355,7 @@ export function FoodEditor({
|
|||
</div>
|
||||
)}
|
||||
{mode === "log" && (
|
||||
<div className="form-row">
|
||||
<div className="form-row entry-details">
|
||||
<label>
|
||||
Day
|
||||
<input
|
||||
|
|
@ -390,6 +366,16 @@ export function FoodEditor({
|
|||
onChange={(e) => setDate(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Time
|
||||
<input
|
||||
aria-label="Entry time"
|
||||
type="time"
|
||||
required={!existing}
|
||||
value={time}
|
||||
onChange={(e) => setTime(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Meal
|
||||
<select
|
||||
|
|
@ -446,7 +432,7 @@ export function FoodEditor({
|
|||
)
|
||||
.map((r) => (
|
||||
<button
|
||||
disabled={busy || !selectedDate}
|
||||
disabled={busy || !selectedDate || !time}
|
||||
className="picker-row"
|
||||
key={r.id}
|
||||
onClick={() => void addPlate(r.data)}
|
||||
|
|
@ -480,12 +466,11 @@ export function FoodEditor({
|
|||
) : (
|
||||
<form onSubmit={submit}>
|
||||
<label>
|
||||
Food name
|
||||
Food name <span className="muted">(optional)</span>
|
||||
<input
|
||||
autoFocus
|
||||
required
|
||||
maxLength={160}
|
||||
placeholder="e.g. Greek yogurt & berries"
|
||||
placeholder={fallbackName}
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue