"use client"; import { RiFireLine as Flame, RiSubtractLine as Minus, RiAddLine as Plus } from "@remixicon/react"; import { useEffect, useRef, useState, useSyncExternalStore } from "react"; import type { Recipe } from "@/app/types"; import { RecipeDetail } from "./RecipeDetail"; const noopSubscribe = () => () => {}; /** RecipeDetail with an accessible servings stepper + Screen Wake Lock ("Cook mode") toggle. */ export function RecipeServings({ recipe }: { recipe: Recipe }) { const [servings, setServings] = useState(recipe.servings); const [cookMode, setCookMode] = useState(false); const wakeSupported = useSyncExternalStore(noopSubscribe, () => "wakeLock" in navigator, () => false); const wakeLockRef = useRef(null); useEffect(() => { if (!cookMode || !wakeSupported) { wakeLockRef.current?.release().catch(() => {}); wakeLockRef.current = null; return; } let cancelled = false; async function acquire() { try { const sentinel = await navigator.wakeLock.request("screen"); if (cancelled) { await sentinel.release(); return; } wakeLockRef.current = sentinel; } catch { // Battery saver or background tab can refuse wakeLock; fail gracefully. } } acquire(); const onVisibility = () => { if (document.visibilityState === "visible" && cookMode) acquire(); }; document.addEventListener("visibilitychange", onVisibility); return () => { cancelled = true; document.removeEventListener("visibilitychange", onVisibility); wakeLockRef.current?.release().catch(() => {}); wakeLockRef.current = null; }; }, [cookMode, wakeSupported]); return (
Scale servings
{servings}
Tap any ingredient or step below to check it off
{wakeSupported && ( )}
); }