Polish PWA gestures, transitions and nutrition averages
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 32s

This commit is contained in:
Elijah 2026-10-22 09:16:52 -07:00
parent b19de6f9ea
commit 7288e56c02
16 changed files with 1019 additions and 245 deletions

View file

@ -1,4 +1,4 @@
import { useEffect, useRef, useState, type ReactNode } from "react";
import { useEffect, useId, useRef, useState, type ReactNode } from "react";
import { X, ArrowUpRight, Plus, Minus, Leaf } from "lucide-react";
import { bubbleCount } from "../shared/bubble-physics.js";
import { useBubblePhysics } from "./useBubblePhysics";
@ -17,6 +17,10 @@ import { emptyNutrients } from "../shared/domain.js";
import { saveRecord, putRecords, useJournal } from "./store";
import { localTime, nextFoodName } from "../shared/entry.js";
import { displayDate, number, today, weightValue } from "./utils";
import { useExiting } from "./Presence";
let sheetLocks = 0;
let previousBodyOverflow = "";
export function Modal({
title,
@ -30,24 +34,39 @@ export function Modal({
children: ReactNode;
}) {
const ref = useRef<HTMLDialogElement>(null);
const titleId = useId();
const closeRef = useRef(close);
closeRef.current = close;
const exiting = useExiting();
const drag = useRef<{ y: number; distance: number } | null>(null);
useEffect(() => {
const dialog = ref.current!;
dialog.showModal();
const listener = (event: Event) => {
event.preventDefault();
close();
closeRef.current();
};
dialog.addEventListener("cancel", listener);
return () => {
dialog.removeEventListener("cancel", listener);
dialog.close();
};
}, [close]);
}, []);
useEffect(() => {
if (!ref.current) return;
if (sheetLocks++ === 0) previousBodyOverflow = document.body.style.overflow;
document.body.style.overflow = "hidden";
return () => {
if (--sheetLocks === 0)
document.body.style.overflow = previousBodyOverflow;
};
}, []);
return (
<dialog
ref={ref}
className="sheet"
aria-labelledby="sheet-title"
className={"sheet" + (exiting ? " sheet-exiting" : "")}
inert={exiting}
aria-labelledby={titleId}
onClick={(event) => {
if (event.target === event.currentTarget) {
const r = event.currentTarget.getBoundingClientRect();
@ -61,10 +80,42 @@ export function Modal({
}
}}
>
<div className="sheet-head">
<div
className="sheet-head"
onPointerDown={(event) => {
if (
event.pointerType !== "touch" ||
!event.isPrimary ||
(event.target as HTMLElement).closest("button, input, select")
)
return;
drag.current = { y: event.clientY, distance: 0 };
event.currentTarget.setPointerCapture(event.pointerId);
}}
onPointerMove={(event) => {
if (!drag.current) return;
drag.current.distance = Math.max(0, event.clientY - drag.current.y);
if (!matchMedia("(prefers-reduced-motion: reduce)").matches)
ref.current?.style.setProperty(
"translate",
`0 ${Math.min(180, drag.current.distance * 0.65)}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");
}}
>
<span className="sheet-grip" aria-hidden="true" />
<div>
<span className="eyebrow">A LITTLE EVERYDAY CARE</span>
<h2 id="sheet-title">{title}</h2>
<h2 id={titleId}>{title}</h2>
{subtitle && <p>{subtitle}</p>}
</div>
<button
@ -390,7 +441,7 @@ export function FoodEditor({
</div>
)}
{tab !== "manual" ? (
<div className="picker">
<div className="picker panel-arrive" key={tab}>
<input
type="search"
placeholder={
@ -464,7 +515,7 @@ export function FoodEditor({
)}
</div>
) : (
<form onSubmit={submit}>
<form className="panel-arrive" onSubmit={submit}>
<label>
Food name <span className="muted">(optional)</span>
<input