From 184d28cddc86a59d19178d6c74596c6994ce909c Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 15:38:14 +0000 Subject: [PATCH 01/14] [cook-plan] Highlight the current stage, pair trays, autocomplete foods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Five changes to the cook planner, all aimed at following a roast from the middle of the timeline rather than the top of the page. **Which stage you're up to.** "In progress" was never the right signal — a turkey is in progress for two hours and so is everything that went in after it, so half the timeline lit up at once. The stop the cook is *up to* is the last instruction whose time has come: that one gets a solid band running the full width of the page, the one after it gets a quieter outline, and the clock scrolls to the band whenever the stage changes. **Two columns on a wide screen.** Longer plans flow into two columns at 1024px and up, filling the left column before the right so the times still read top-to-bottom then across. **Food autocomplete.** A catalogue of ~55 roast dishes (foods.js) backs a datalist on the name field. Naming a dish it knows fills in the cook type and timings; editing one offers them on a button instead of overwriting what is already there. **Editable oven and shelf.** The timeline's Edit panel now carries oven, shelf and hob alongside the cook start, and the item dialog gained a shelf picker. Hand-picked placements are allocated first so the automatic ones route around them. **Tray-aware pairing.** A shelf holds two half-shelf dishes, so which two matters: potatoes and parsnips want the same heat and the same fat and can share one big tray, a crumble next to them cannot. Shelves are now scored by what is already on them, a dish that only fits beside a bad neighbour goes to the combi instead, and the timeline says which dishes share a tray. Two bugs found on the way, both needed for the manual placements to be safe: conflict detection filtered on `_s.cookTime`, which is never set, so all three checks silently found nothing; and nothing checked a single shelf's capacity, only the oven's total, so three dishes could pile onto one shelf of a half-empty oven. Co-Authored-By: Claude Opus 5 --- cook-plan/appliances.js | 143 ++++++++++++++++------ cook-plan/clock.js | 52 +++++++- cook-plan/conflicts.js | 41 +++++-- cook-plan/db.js | 2 + cook-plan/events.js | 5 + cook-plan/foods.js | 175 ++++++++++++++++++++++++++ cook-plan/item-modal.js | 158 +++++++++++++++++++++--- cook-plan/render-schedule.js | 230 +++++++++++++++++++++++++++-------- cook-plan/share-link.js | 5 +- cook-plan/style.css | 225 ++++++++++++++++++++++++++++++++-- 10 files changed, 909 insertions(+), 127 deletions(-) create mode 100644 cook-plan/foods.js diff --git a/cook-plan/appliances.js b/cook-plan/appliances.js index 7587523..20b6314 100644 --- a/cook-plan/appliances.js +++ b/cook-plan/appliances.js @@ -4,6 +4,7 @@ import { state } from './state.js'; import { COOK_TYPE_MAP, COMBI_COOLDOWN } from './constants.js'; +import { lookupFood, pairScore, sharesTray } from './foods.js'; export function applianceConfig() { const a = state.appliances || {}; @@ -14,6 +15,17 @@ export function applianceConfig() { }; } +// A hand-picked shelf, as a number, or null for "let the planner decide". +// Out-of-range values (a 2-shelf plan opened with the oven set to 1 shelf) +// fall back to automatic rather than pinning to a shelf that isn't there. +export function shelfPrefOf(item, numShelves) { + const raw = item?.shelfPref; + if (raw === undefined || raw === null || raw === '' || raw === 'auto') return null; + const n = parseInt(raw, 10); + if (!Number.isFinite(n) || n < 1 || n > numShelves) return null; + return n; +} + export function assignAppliances(items) { // Sort by cookStart for deterministic assignment const sorted = [...items].sort((a, b) => a._s.cookStart - b._s.cookStart); @@ -44,14 +56,29 @@ export function assignAppliances(items) { return max; } - // First shelf number that can fit `needed` more slots, or null. - function firstFreeShelf(usage, start, end, excludeId, needed, numShelves, slotsPerShelf) { + // Which shelf to use for a dish that needs `needed` slots. + // + // Any shelf with room will do as far as capacity goes, so the deciding factor + // is what is already on it: a half-shelf of parsnips next to a half-shelf of + // potatoes is one tray and one lot of basting, while parsnips next to a + // crumble is two. Shelves are scored by their worst neighbour — one bad + // pairing is enough to spoil the tray — and an empty shelf scores a neutral + // 0, so a good pairing beats an empty shelf and a bad one loses to it. + // + // Returns {shelf, score} or null when the dish doesn't fit anywhere. + function bestShelf(usage, start, end, excludeId, needed, numShelves, slotsPerShelf, food) { + let best = null; for (let shelf = 1; shelf <= numShelves; shelf++) { - if (slotsOnShelf(usage, shelf, start, end, excludeId) + needed <= slotsPerShelf) { - return shelf; - } + if (slotsOnShelf(usage, shelf, start, end, excludeId) + needed > slotsPerShelf) continue; + const mates = usage.filter(u => + u.itemId !== excludeId && u.shelf === shelf && u.start < end && u.end > start + ); + const score = mates.length === 0 + ? 0 + : Math.min(...mates.map(u => pairScore(food, u.food))); + if (best === null || score > best.score) best = { shelf, score }; } - return null; + return best; } function combiModeAt(start, end, excludeId) { @@ -83,11 +110,21 @@ export function assignAppliances(items) { const cfg = applianceConfig(); - for (const item of sorted) { + // Hand-picked appliances and shelves are placed first so the automatic + // choices route around them rather than the other way about — an override is + // only worth making if the rest of the plan respects it. + const isPinned = (item) => + (item.appliancePref && item.appliancePref !== 'auto') || + shelfPrefOf(item, cfg.mainOvenShelves) !== null; + const order = [...sorted.filter(isPinned), ...sorted.filter(it => !isPinned(it))]; + + for (const item of order) { const { cookStart, cookEnd } = item._s; const slots = item.shelfSlots || 1; const pref = item.appliancePref || 'auto'; const ct = COOK_TYPE_MAP[item.cookType]; + const food = lookupFood(item.name); + item._trayMates = []; if (!ct) { item._appliance = null; continue; } if (ct.resource === 'none') { @@ -127,7 +164,7 @@ export function assignAppliances(items) { const existingMode = combiModeAt(cookStart, cookEnd, item.id); const combiFree = (existingMode === null); // microwave needs the combi entirely free if (cooldownOk && combiFree) { - combiUsage.push({ start: cookStart, end: cookEnd, mode: 'microwave', shelf: 1, slots: 1, itemId: item.id }); + combiUsage.push({ start: cookStart, end: cookEnd, mode: 'microwave', shelf: 1, slots: 1, itemId: item.id, food }); item._appliance = 'combi-mw'; item._shelf = 1; } else { @@ -138,45 +175,73 @@ export function assignAppliances(items) { } if (ct.resource === 'oven') { - const tryCombi = pref === 'combi' && cfg.hasCombi; + const tryCombi = pref === 'combi' || pref === 'auto'; const tryMain = pref === 'main' || pref === 'auto'; + const pinnedShelf = shelfPrefOf(item, cfg.mainOvenShelves); - let assigned = false; - - if (tryMain) { - // Main oven: cfg.mainOvenShelves shelves x 2 slots each - const shelf = firstFreeShelf(mainOvenUsage, cookStart, cookEnd, item.id, slots, cfg.mainOvenShelves, 2); - if (shelf !== null) { - mainOvenUsage.push({ start: cookStart, end: cookEnd, shelf, slots, itemId: item.id }); - item._appliance = 'main'; - item._shelf = shelf; - assigned = true; - } - } + const takeMain = (shelf, pinned) => { + mainOvenUsage.push({ start: cookStart, end: cookEnd, shelf, slots, itemId: item.id, food }); + item._appliance = 'main'; + item._shelf = shelf; + if (pinned) item._shelfPinned = true; + }; + const takeCombi = () => { + combiUsage.push({ start: cookStart, end: cookEnd, mode: 'oven', shelf: 1, slots, itemId: item.id, food }); + item._appliance = 'combi'; + item._shelf = 1; + }; - if (!assigned && (tryCombi || (pref === 'auto' && cfg.hasCombi))) { - const existingMode = combiModeAt(cookStart, cookEnd, item.id); - if (existingMode === null || existingMode === 'oven') { - // Combi oven: 1 shelf x 2 slots - const shelf = firstFreeShelf(combiUsage, cookStart, cookEnd, item.id, slots, 1, 2); - if (shelf !== null) { - combiUsage.push({ start: cookStart, end: cookEnd, mode: 'oven', shelf: 1, slots, itemId: item.id }); - item._appliance = 'combi'; - item._shelf = 1; - assigned = true; - } - } + if (tryMain && pinnedShelf !== null) { + // A hand-picked shelf is honoured even when it overfills. Overruling + // the planner is the whole point of the override, and the capacity + // sweep in conflicts.js will say so if it doesn't fit. + takeMain(pinnedShelf, true); + continue; } - if (!assigned) { - // Overflow: assign to main oven anyway (conflict will be detected) - const shelf = firstFreeShelf(mainOvenUsage, cookStart, cookEnd, item.id, slots, cfg.mainOvenShelves, 2) ?? 1; - mainOvenUsage.push({ start: cookStart, end: cookEnd, shelf, slots, itemId: item.id }); - item._appliance = 'main'; - item._shelf = shelf; + const mainOpt = tryMain + ? bestShelf(mainOvenUsage, cookStart, cookEnd, item.id, slots, cfg.mainOvenShelves, 2, food) + : null; + + // The combi counts as a second oven here, and room in it beats a bad + // neighbour in the main one: a crumble that only fits beside the + // potatoes is better off on its own in the combi than sharing their + // shelf. Ties go to the main oven, which is what "main oven first" means. + const combiMode = combiModeAt(cookStart, cookEnd, item.id); + const combiOpt = (tryCombi && cfg.hasCombi && (combiMode === null || combiMode === 'oven')) + ? bestShelf(combiUsage, cookStart, cookEnd, item.id, slots, 1, 2, food) + : null; + + if (mainOpt && (!combiOpt || mainOpt.score >= combiOpt.score)) { + takeMain(mainOpt.shelf, false); + } else if (combiOpt) { + takeCombi(); + } else { + // Nowhere fits: into the main oven anyway, and conflicts.js will say so. + takeMain(1, false); } } } + annotateTrayMates(sorted, mainOvenUsage); + annotateTrayMates(sorted, combiUsage); + return sorted; } + +// Note, on each dish, which of its shelf-mates it could genuinely go in one +// tray with. Only pairings the catalogue actually recommends get a mention — +// two things landing on the same shelf is not by itself advice worth printing. +function annotateTrayMates(items, usage) { + const byId = new Map(items.map(it => [it.id, it])); + for (const u of usage) { + const item = byId.get(u.itemId); + if (!item || u.mode === 'microwave') continue; + const mates = usage.filter(o => + o.itemId !== u.itemId && o.shelf === u.shelf && o.start < u.end && o.end > u.start + && sharesTray(u.food, o.food) + ); + const names = mates.map(o => byId.get(o.itemId)?.name).filter(Boolean); + if (names.length) item._trayMates = [...new Set(names)]; + } +} diff --git a/cook-plan/clock.js b/cook-plan/clock.js index 6222c0b..b0a69bd 100644 --- a/cook-plan/clock.js +++ b/cook-plan/clock.js @@ -8,6 +8,9 @@ import { escHtml, formatCountdown, formatTime, nowMins } from './utils.js'; let clockInterval = null; let chimesFired = new Set(); let nextDayOffset = 0; // 1440 if the schedule is for the next calendar day +// Which timeline stop is the current one, so a change of stage can be brought +// into view. Null means "not looked yet" rather than "nothing is active". +let lastStageKey = null; // In-memory notification stack — never persisted. When a chime fires we push // the event so the user can see what triggered the sound when they tab back in. @@ -141,6 +144,7 @@ function playChime(type) { export function startClock(events) { initChimes(events); + lastStageKey = null; updateClock(events); clockInterval = setInterval(() => updateClock(events), 1000); } @@ -193,7 +197,7 @@ function updateClock(events) { // Update past/active classes on grouped timeline rows // Each row may contain .tl-tracker elements that map back to original events - const tlRows = document.querySelectorAll('.tl-event'); + const tlRows = [...document.querySelectorAll('.tl-event')]; tlRows.forEach(row => { const trackers = row.querySelectorAll('.tl-tracker'); const rowEvents = [...trackers].map(el => @@ -206,5 +210,51 @@ function updateClock(events) { row.classList.toggle('tl-active', isActive && !isPast); }); + markCurrentStage(tlRows, nowM); + // Update appliance slots (re-render just slot bars would need full re-render; skip for perf) } + +// Which stop the cook has got to. +// +// "In progress" is no help on its own: a turkey is in progress for two hours, +// and so is everything that went in after it, which is how you end up with +// half the timeline lit at once. The stage you are *up to* is the last +// instruction whose time has come — that one gets the band, the one after it +// gets a quieter outline, and the rest are history or still to come. Before +// anything has started the first stop is both. +function markCurrentStage(rows, nowM) { + let current = null; + let next = null; + for (const row of rows) { + const time = Number(row.dataset.time); + if (!Number.isFinite(time)) continue; + if (time <= nowM) current = row; + else if (!next) next = row; + } + if (!current) current = next; + + for (const row of rows) { + row.classList.toggle('tl-current', row === current); + row.classList.toggle('tl-next', row === next && row !== current); + } + + revealStage(current); +} + +// The timeline is long and the cook is somewhere in the middle of it, so the +// current stage is scrolled to rather than waited for. Only a *change* of stage +// moves the page — otherwise every tick would drag the view back and there +// would be no reading ahead. +function revealStage(row) { + const key = row?.dataset.time ?? null; + if (key === lastStageKey) return; + const firstLook = lastStageKey === null; + lastStageKey = key; + if (!row) return; + const still = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches; + row.scrollIntoView({ + block: 'center', + behavior: (firstLook || still) ? 'auto' : 'smooth', + }); +} diff --git a/cook-plan/conflicts.js b/cook-plan/conflicts.js index 16c88ad..feca5b7 100644 --- a/cook-plan/conflicts.js +++ b/cook-plan/conflicts.js @@ -38,33 +38,54 @@ export function detectConflicts(items) { const cfg = applianceConfig(); const maxSlots = cfg.mainOvenShelves * 2; const ovenItems = items.filter(i => - COOK_TYPE_MAP[i.cookType]?.resource === 'oven' && i._appliance === 'main' && i._s.cookTime > 0 + COOK_TYPE_MAP[i.cookType]?.resource === 'oven' && i._appliance === 'main' && i.cookTime > 0 ); - const usage = ovenItems.map(i => ({ + const describe = (id) => { + const it = ovenItems.find(i => i.id === id); + return it ? `"${it.name}" (${it.shelfSlots||1} slot${(it.shelfSlots||1)>1?'s':''})` : id; + }; + const toUsage = (arr) => arr.map(i => ({ start: i._s.cookStart, end: i._s.cookEnd, slots: i.shelfSlots || 1, itemId: i.id, })); - const over = sweepConflicts(usage, maxSlots); + + const over = sweepConflicts(toUsage(ovenItems), maxSlots); const seen = new Set(); for (const { time, slots, itemIds } of over) { const key = [...itemIds].sort().join(','); if (seen.has(key)) continue; seen.add(key); - const names = itemIds.map(id => { - const it = ovenItems.find(i => i.id === id); - return it ? `"${it.name}" (${it.shelfSlots||1} slot${(it.shelfSlots||1)>1?'s':''})` : id; - }); conflicts.push({ type: 'oven', - message: `Main oven overcapacity at ${formatTime(time)}: ${names.join(', ')} = ${slots}/${maxSlots} slots.`, + message: `Main oven overcapacity at ${formatTime(time)}: ${itemIds.map(describe).join(', ')} = ${slots}/${maxSlots} slots.`, itemIds, }); } + + // A shelf holds two slots however much room the oven has overall, so an + // oven that is only half full can still have a shelf with three things on + // it — by a hand-picked shelf that doesn't fit, or by the allocator having + // nowhere left to put something. Neither shows up in the total above. + const shelfSeen = new Set(); + for (let shelf = 1; shelf <= cfg.mainOvenShelves; shelf++) { + const onShelf = ovenItems.filter(i => (i._shelf ?? 1) === shelf); + if (onShelf.length < 2) continue; + for (const { time, slots, itemIds } of sweepConflicts(toUsage(onShelf), 2)) { + const key = shelf + ':' + [...itemIds].sort().join(','); + if (shelfSeen.has(key)) continue; + shelfSeen.add(key); + conflicts.push({ + type: 'oven-shelf', + message: `Main oven shelf ${shelf} overcapacity at ${formatTime(time)}: ${itemIds.map(describe).join(', ')} = ${slots}/2 slots. Move one to another shelf.`, + itemIds, + }); + } + } } function checkCombiConflicts() { const combiItems = items.filter(i => - (i._appliance === 'combi' || i._appliance === 'combi-mw') && i._s.cookTime > 0 + (i._appliance === 'combi' || i._appliance === 'combi-mw') && i.cookTime > 0 ); const ovenItems = combiItems.filter(i => i._appliance === 'combi'); const mwItems = combiItems.filter(i => i._appliance === 'combi-mw'); @@ -148,7 +169,7 @@ export function detectConflicts(items) { function checkHobConflicts() { const hobItems = items.filter(i => - COOK_TYPE_MAP[i.cookType]?.resource === 'hob' && i._s.cookTime > 0 + COOK_TYPE_MAP[i.cookType]?.resource === 'hob' && i.cookTime > 0 ); // Check all time slices where more than 5 items are on hobs const events = []; diff --git a/cook-plan/db.js b/cook-plan/db.js index 2d4572a..d425f1a 100644 --- a/cook-plan/db.js +++ b/cook-plan/db.js @@ -45,6 +45,7 @@ function itemToDoc(item) { cookType: item.cookType || 'oven', shelfSlots: item.shelfSlots ?? 1, appliancePref: item.appliancePref || 'auto', + shelfPref: item.shelfPref ?? null, prepTime: item.prepTime || 0, cookTime: item.cookTime || 0, setTime: item.setTime || 0, @@ -61,6 +62,7 @@ function itemFromDoc(doc) { cookType: doc.cookType || 'oven', shelfSlots: doc.shelfSlots ?? 1, appliancePref: doc.appliancePref || 'auto', + shelfPref: doc.shelfPref ?? null, prepTime: doc.prepTime || 0, cookTime: doc.cookTime || 0, setTime: doc.setTime || 0, diff --git a/cook-plan/events.js b/cook-plan/events.js index b62d4ba..f8445d3 100644 --- a/cook-plan/events.js +++ b/cook-plan/events.js @@ -58,6 +58,11 @@ export function buildEvents(items, serveTime) { applianceKey: appKey, applianceLabel: appLabel, shelfInfo: item._shelf ?? null, + // Dishes already on this shelf that this one could genuinely go in a + // single tray with (see foods.js). Carried separately from `sub` so the + // merged-event formatting below doesn't have to parse it back out. + trayMates: item._trayMates || [], + shelfPinned: !!item._shelfPinned, ct, }); events.push({ diff --git a/cook-plan/foods.js b/cook-plan/foods.js new file mode 100644 index 0000000..68d7366 --- /dev/null +++ b/cook-plan/foods.js @@ -0,0 +1,175 @@ +// ============================================= +// Cook Planner — foods.js +// +// A small catalogue of the things that actually turn up at a roast, with the +// timings most recipes agree on. Two jobs: +// +// 1. Autocomplete. Typing "parsn" offers "Parsnips" and, with it, a cook type +// and a set of times — the tedious part of adding a dish. +// 2. Tray pairing. The main oven's shelves hold two half-shelf slots each, so +// something has to decide which two dishes end up side by side. Potatoes and +// parsnips want the same heat and the same fat and can go in one big tray; +// a crumble next to salmon is a worse idea. `pairScore` is what the shelf +// allocator in appliances.js consults to make that call. +// +// `family` groups things that are interchangeable on a tray. `heat` stands in +// for an oven temperature the planner doesn't otherwise model — hot is roughly +// 200°C+, mid 180–190°C, low 150–170°C. `tray` says whether a dish is loose on +// a baking tray ('open', so it can share one) or sealed in its own dish or tin +// ('dish' — happy to share a shelf, but never a tray). +// ============================================= + +// name, cookType, prep, cook, rest, slots, family, heat, tray +const RAW = [ + // ── Big roasts ── + ['Turkey', 'oven', 20, 180, 30, 2, 'poultry', 'mid', 'dish'], + ['Turkey crown', 'oven', 15, 120, 25, 2, 'poultry', 'mid', 'dish'], + ['Roast chicken', 'oven', 10, 90, 15, 2, 'poultry', 'mid', 'dish'], + ['Chicken thighs', 'oven', 5, 45, 5, 1, 'poultry', 'mid', 'open'], + ['Roast duck', 'oven', 15, 120, 20, 2, 'poultry', 'mid', 'dish'], + ['Roast goose', 'oven', 20, 150, 30, 2, 'poultry', 'mid', 'dish'], + ['Beef joint', 'oven', 15, 90, 25, 2, 'red-meat', 'hot', 'dish'], + ['Rib of beef', 'oven', 20, 120, 30, 2, 'red-meat', 'hot', 'dish'], + ['Leg of lamb', 'oven', 15, 105, 25, 2, 'red-meat', 'mid', 'dish'], + ['Shoulder of lamb', 'oven', 15, 240, 30, 2, 'red-meat', 'low', 'dish'], + ['Pork loin', 'oven', 15, 100, 20, 2, 'red-meat', 'mid', 'dish'], + ['Pork belly', 'oven', 20, 150, 15, 2, 'red-meat', 'low', 'dish'], + ['Gammon joint', 'oven', 15, 120, 15, 2, 'red-meat', 'mid', 'dish'], + ['Beef Wellington', 'oven', 30, 40, 15, 2, 'pastry', 'hot', 'dish'], + ['Nut roast', 'oven', 20, 50, 10, 1, 'veg-bake', 'mid', 'dish'], + + // ── Roast veg: the tray-sharers ── + ['Roast potatoes', 'oven', 20, 55, 0, 2, 'root-veg', 'hot', 'open'], + ['Hasselback potatoes', 'oven', 20, 60, 0, 2, 'root-veg', 'hot', 'open'], + ['Parsnips', 'oven', 10, 40, 0, 1, 'root-veg', 'hot', 'open'], + ['Honey-roast carrots', 'oven', 10, 35, 0, 1, 'root-veg', 'hot', 'open'], + ['Roast swede', 'oven', 10, 45, 0, 1, 'root-veg', 'hot', 'open'], + ['Roast beetroot', 'oven', 10, 50, 0, 1, 'root-veg', 'hot', 'open'], + ['Sweet potatoes', 'oven', 10, 40, 0, 1, 'root-veg', 'hot', 'open'], + ['Roast veg medley', 'oven', 15, 40, 0, 2, 'root-veg', 'hot', 'open'], + ['Roast onions', 'oven', 5, 35, 0, 1, 'allium', 'hot', 'open'], + ['Roast shallots', 'oven', 5, 30, 0, 1, 'allium', 'hot', 'open'], + ['Roast leeks', 'oven', 5, 30, 0, 1, 'allium', 'mid', 'open'], + ['Roast sprouts', 'oven', 8, 25, 0, 1, 'brassica', 'hot', 'open'], + ['Roast cauliflower', 'oven', 8, 30, 0, 1, 'brassica', 'hot', 'open'], + ['Roast broccoli', 'oven', 5, 20, 0, 1, 'brassica', 'hot', 'open'], + + // ── Trimmings ── + ['Pigs in blankets', 'oven', 10, 30, 0, 1, 'sausage', 'mid', 'open'], + ['Pork sausages', 'oven', 2, 30, 0, 1, 'sausage', 'mid', 'open'], + ['Stuffing balls', 'oven', 10, 30, 0, 1, 'stuffing', 'mid', 'open'], + ['Sage & onion stuffing','oven', 10, 35, 0, 1, 'stuffing', 'mid', 'dish'], + ['Yorkshire puddings', 'oven', 10, 22, 0, 1, 'batter', 'hot', 'dish'], + ['Toad in the hole', 'oven', 15, 40, 0, 2, 'batter', 'hot', 'dish'], + ['Pork crackling', 'oven', 5, 25, 0, 1, 'red-meat', 'hot', 'open'], + ['Cauliflower cheese', 'oven', 20, 30, 5, 2, 'veg-bake', 'mid', 'dish'], + ['Dauphinoise potatoes', 'oven', 20, 75, 10, 2, 'veg-bake', 'mid', 'dish'], + ['Bread rolls', 'oven', 2, 10, 0, 1, 'bread', 'hot', 'open'], + ['Garlic bread', 'oven', 2, 15, 0, 1, 'bread', 'hot', 'open'], + ['Salmon fillets', 'oven', 5, 20, 5, 1, 'fish', 'mid', 'open'], + + // ── Hob ── + ['Mashed potatoes', 'boil', 15, 20, 0, 1, 'root-veg', 'mid', 'open'], + ['Boiled potatoes', 'boil', 10, 20, 0, 1, 'root-veg', 'mid', 'open'], + ['Brussels sprouts', 'boil', 10, 8, 0, 1, 'brassica', 'mid', 'open'], + ['Carrots', 'boil', 5, 15, 0, 1, 'root-veg', 'mid', 'open'], + ['Green beans', 'boil', 3, 6, 0, 1, 'brassica', 'mid', 'open'], + ['Garden peas', 'boil', 2, 5, 0, 1, 'brassica', 'mid', 'open'], + ['Cauliflower', 'boil', 5, 10, 0, 1, 'brassica', 'mid', 'open'], + ['Broccoli', 'boil', 3, 6, 0, 1, 'brassica', 'mid', 'open'], + ['Red cabbage', 'pan', 10, 45, 0, 1, 'brassica', 'mid', 'dish'], + ['Gravy', 'pan', 5, 15, 0, 1, 'sauce', 'mid', 'dish'], + ['Bread sauce', 'pan', 5, 15, 0, 1, 'sauce', 'mid', 'dish'], + ['Cranberry sauce', 'pan', 5, 10, 0, 1, 'sauce', 'mid', 'dish'], + + // ── Pudding ── + ['Apple crumble', 'oven', 20, 40, 10, 2, 'dessert', 'mid', 'dish'], + ['Apple pie', 'oven', 15, 45, 10, 2, 'dessert', 'mid', 'dish'], + ['Christmas pudding', 'boil', 5, 120, 0, 1, 'dessert', 'mid', 'dish'], + ['Mince pies', 'oven', 2, 18, 0, 1, 'dessert', 'mid', 'open'], +]; + +export const FOODS = RAW.map( + ([name, cookType, prepTime, cookTime, setTime, shelfSlots, family, heat, tray]) => ({ + name, cookType, prepTime, cookTime, setTime, shelfSlots, family, heat, tray, + }) +); + +export const FOOD_NAMES = FOODS.map(f => f.name); + +const BY_KEY = new Map(FOODS.map(f => [normalise(f.name), f])); + +function normalise(name) { + return String(name || '') + .toLowerCase() + .replace(/&/g, 'and') + .replace(/[^a-z0-9]+/g, ' ') + .trim(); +} + +// An exact (if punctuation-insensitive) hit only. Suggesting times for a dish +// the cook didn't name is worse than suggesting nothing: "Roast potatoes" must +// not quietly answer for "Potato salad". +export function lookupFood(name) { + return BY_KEY.get(normalise(name)) || null; +} + +// The tray-pairing model. +// +// Families that roast alike, so swapping one for the other on a tray changes +// nothing that matters. +const AFFINITY_GROUPS = [ + ['root-veg', 'allium', 'brassica'], // all go in hot fat and come out together + ['sausage', 'stuffing'], // the trimmings tray + ['bread', 'pastry'], +]; + +const HEAT_INDEX = { low: 0, mid: 1, hot: 2 }; + +// Flavours that shouldn't meet in the same fat, whatever their temperatures say. +function clashes(a, b) { + const sweet = f => f.family === 'dessert'; + if (sweet(a) !== sweet(b)) return true; // pudding beside the meat + const fish = f => f.family === 'fish'; + const strong = f => ['sausage', 'stuffing', 'red-meat', 'allium'].includes(f.family); + if ((fish(a) && strong(b)) || (fish(b) && strong(a))) return true; + return false; +} + +function sameGroup(a, b) { + return AFFINITY_GROUPS.some(g => g.includes(a.family) && g.includes(b.family)); +} + +// How well two dishes sit next to each other on one shelf. +// +// +3 the same thing, near enough — one big tray (potatoes + parsnips) +// +2 different but cooked alike (parsnips + roast onions) +// 0 no opinion: unknown dish, or each sealed in its own dish +// -2 wants a markedly different oven temperature +// -3 shouldn't share the fat at all +// +// Anything above 0 is a nudge towards putting them together; anything below is +// a reason to use the other shelf first. `null` inputs (a dish not in the +// catalogue) score 0 — an unknown is no reason to shuffle the oven around. +export function pairScore(a, b) { + if (!a || !b) return 0; + if (clashes(a, b)) return -3; + + const heatGap = Math.abs((HEAT_INDEX[a.heat] ?? 1) - (HEAT_INDEX[b.heat] ?? 1)); + if (heatGap >= 2) return -2; + + // Each in its own dish or tin: they can share the shelf, but there is no tray + // to share, so neither one is a reason to prefer this shelf over an empty one. + if (a.tray !== 'open' || b.tray !== 'open') return 0; + + if (a.family === b.family) return heatGap === 0 ? 3 : 2; + if (sameGroup(a, b)) return heatGap === 0 ? 2 : 1; + return 0; +} + +// Would these two actually go in one tray together? Used for the "share a tray" +// note on the timeline, which should only appear when it's genuinely useful +// advice rather than whenever two things happen to land on the same shelf. +export function sharesTray(a, b) { + return pairScore(a, b) >= 2; +} diff --git a/cook-plan/item-modal.js b/cook-plan/item-modal.js index 66c8272..4ed0b91 100644 --- a/cook-plan/item-modal.js +++ b/cook-plan/item-modal.js @@ -5,6 +5,8 @@ import { state, saveItem, nextOrder } from './state.js'; import { COOK_TYPES, COOK_TYPE_MAP } from './constants.js'; import { escHtml, slotsLabel, uid } from './utils.js'; +import { FOOD_NAMES, lookupFood } from './foods.js'; +import { applianceConfig } from './appliances.js'; import { removeItem } from './render-input.js'; import { renderCurrentView } from './router.js'; @@ -18,16 +20,24 @@ export function openItemModal(editId) { const item = editId ? state.items.find(i => i.id === editId) : null; title.textContent = item ? `Edit: ${item.name}` : 'Add Food Item'; + const cfg = applianceConfig(); const defCookType = item?.cookType || 'oven'; const defSlots = item?.shelfSlots || 1; + const defShelf = item?.shelfPref ?? 'auto'; const showSlots = (ct) => COOK_TYPE_MAP[ct]?.resource === 'oven' || COOK_TYPE_MAP[ct]?.resource === 'combi'; + const showShelf = (ct) => COOK_TYPE_MAP[ct]?.resource === 'oven' && cfg.mainOvenShelves > 1; body.innerHTML = `
- + + ${FOOD_NAMES.map(n => ``).join('')} + +
@@ -56,7 +66,7 @@ export function openItemModal(editId) {
-
+
+
+ + + Auto puts dishes that share a tray well on the same shelf +
+
@@ -126,32 +149,118 @@ export function openItemModal(editId) { backdropClickBound = true; } + // ── Which fields the cook has had a hand in ── + // A dish being edited arrives with times somebody chose, so none of them are + // ours to overwrite. On a new item every timing field is still a default and + // can be filled in from the catalogue the moment the name matches something. + const touched = new Set(item ? ['cookType', 'times', 'slots'] : []); + + function syncVisibility(cookType) { + const resource = COOK_TYPE_MAP[cookType]?.resource; + document.getElementById('fg-slots').style.display = (resource === 'oven' || resource === 'combi') ? '' : 'none'; + document.getElementById('fg-appliance-pref').style.display = (resource === 'oven') ? '' : 'none'; + document.getElementById('fg-shelf-pref').style.display = (resource === 'oven' && cfg.mainOvenShelves > 1) ? '' : 'none'; + document.getElementById('fg-hob-pref').style.display = (resource === 'hob') ? '' : 'none'; + } + + function selectCookType(ct) { + document.querySelectorAll('.cook-type-btn').forEach(b => + b.classList.toggle('selected', b.dataset.cookType === ct)); + document.getElementById('if-cook-type').value = ct; + syncVisibility(ct); + } + + function setSlots(n) { + document.getElementById('if-slots').value = n; + document.getElementById('slot-label').textContent = slotsLabel(n); + document.querySelectorAll('.sv-slot').forEach(el => { + el.classList.toggle('filled', parseInt(el.dataset.slot) <= n); + }); + } + + function applyFood(food) { + selectCookType(food.cookType); + setSlots(food.shelfSlots); + document.getElementById('if-prep').value = food.prepTime; + document.getElementById('if-cook').value = food.cookTime; + document.getElementById('if-set').value = food.setTime; + } + + // Does the form already say what the catalogue would say? + function matchesFood(food) { + return document.getElementById('if-cook-type').value === food.cookType + && Number(document.getElementById('if-prep').value) === food.prepTime + && Number(document.getElementById('if-cook').value) === food.cookTime + && Number(document.getElementById('if-set').value) === food.setTime; + } + + const suggestEl = document.getElementById('if-suggest'); + + function refreshSuggestion({ autoApply }) { + const food = lookupFood(document.getElementById('if-name').value); + if (!food) { suggestEl.hidden = true; suggestEl.innerHTML = ''; return; } + + // Nothing has been typed over yet, so fill it in rather than asking. + if (autoApply && touched.size === 0) { + applyFood(food); + suggestEl.hidden = false; + suggestEl.innerHTML = + `✓ Typical times for ${escHtml(food.name)} filled in — change anything you like.`; + return; + } + + if (matchesFood(food)) { suggestEl.hidden = true; suggestEl.innerHTML = ''; return; } + + suggestEl.hidden = false; + suggestEl.innerHTML = ` + + ${escHtml(summarise(food))} + `; + } + + document.getElementById('if-name').addEventListener('input', () => refreshSuggestion({ autoApply: true })); + // Picking from the datalist fires `change` in some browsers without an + // `input` event, so both are listened for. + document.getElementById('if-name').addEventListener('change', () => refreshSuggestion({ autoApply: true })); + + suggestEl.addEventListener('click', (e) => { + if (!e.target.closest('#btn-apply-food')) return; + const food = lookupFood(document.getElementById('if-name').value); + if (!food) return; + applyFood(food); + refreshSuggestion({ autoApply: false }); + }); + // Cook type selection document.getElementById('cook-type-grid').addEventListener('click', e => { const btn = e.target.closest('.cook-type-btn'); if (!btn) return; - const ct = btn.dataset.cookType; - document.querySelectorAll('.cook-type-btn').forEach(b => b.classList.remove('selected')); - btn.classList.add('selected'); - document.getElementById('if-cook-type').value = ct; - const resource = COOK_TYPE_MAP[ct]?.resource; - document.getElementById('fg-slots').style.display = (resource === 'oven' || resource === 'combi') ? '' : 'none'; - document.getElementById('fg-appliance-pref').style.display = (resource === 'oven') ? '' : 'none'; - document.getElementById('fg-hob-pref').style.display = (resource === 'hob') ? '' : 'none'; + touched.add('cookType'); + selectCookType(btn.dataset.cookType); + refreshSuggestion({ autoApply: false }); }); // Slot picker document.getElementById('slot-visual').addEventListener('click', e => { const slotEl = e.target.closest('.sv-slot'); if (!slotEl) return; - const n = parseInt(slotEl.dataset.slot); - document.getElementById('if-slots').value = n; - document.getElementById('slot-label').textContent = slotsLabel(n); - document.querySelectorAll('.sv-slot').forEach(el => { - el.classList.toggle('filled', parseInt(el.dataset.slot) <= n); - }); + touched.add('slots'); + setSlots(parseInt(slotEl.dataset.slot)); }); + for (const id of ['if-prep', 'if-cook', 'if-set']) { + document.getElementById(id).addEventListener('input', () => { + touched.add('times'); + refreshSuggestion({ autoApply: false }); + }); + } + + // An existing dish whose name is in the catalogue gets the offer straight + // away, so the preset is one click from an edit too. + refreshSuggestion({ autoApply: false }); + // Form submit document.getElementById('item-form').addEventListener('submit', e => { e.preventDefault(); @@ -165,6 +274,8 @@ export function openItemModal(editId) { : resource === 'hob' ? (document.getElementById('if-hob-pref')?.value || 'auto') : 'auto'; + const shelfPrefRaw = document.getElementById('if-shelf-pref')?.value || 'auto'; + const shelfPref = (resource === 'oven' && shelfPrefRaw !== 'auto') ? shelfPrefRaw : null; const prepTime = parseInt(document.getElementById('if-prep').value) || 0; const cookTime = parseInt(document.getElementById('if-cook').value) || 0; const setTime = parseInt(document.getElementById('if-set').value) || 0; @@ -173,10 +284,10 @@ export function openItemModal(editId) { // alone so a second device editing a different dish doesn't lose its edit. let saved; if (item) { - saved = Object.assign(item, { name, cookType, shelfSlots, appliancePref, prepTime, cookTime, setTime }); + saved = Object.assign(item, { name, cookType, shelfSlots, appliancePref, shelfPref, prepTime, cookTime, setTime }); } else { saved = { - id: uid(), name, cookType, shelfSlots, appliancePref, + id: uid(), name, cookType, shelfSlots, appliancePref, shelfPref, prepTime, cookTime, setTime, overrideCookStart: null, order: nextOrder(), createdAt: Date.now(), }; @@ -194,6 +305,15 @@ export function openItemModal(editId) { }); } +function summarise(food) { + const ct = COOK_TYPE_MAP[food.cookType]; + const parts = [ct ? ct.label : food.cookType]; + if (food.prepTime) parts.push(`prep ${food.prepTime}m`); + if (food.cookTime) parts.push(`cook ${food.cookTime}m`); + if (food.setTime) parts.push(`rest ${food.setTime}m`); + return parts.join(' · '); +} + export function closeModal() { const dialog = document.getElementById('item-dialog'); if (dialog?.open) dialog.close(); diff --git a/cook-plan/render-schedule.js b/cook-plan/render-schedule.js index d267ab6..3732403 100644 --- a/cook-plan/render-schedule.js +++ b/cook-plan/render-schedule.js @@ -6,7 +6,7 @@ import { state, saveItem, resetState, setView } from './state.js'; import { EV_TYPE_CHIP } from './constants.js'; import { escHtml, formatTime, formatDuration, nowMins } from './utils.js'; import { applianceConfig } from './appliances.js'; -import { applianceLabel, mergedLabel, mergedSub } from './events.js'; +import { applianceLabel, mergedLabel, mergedSub, joinNames } from './events.js'; import { computeSchedule } from './schedule.js'; import { startClock, stopClock, getNextDayOffset, dismissNotification, clearNotifications, renderNotifications } from './clock.js'; import { toggleWakeLock, releaseWakeLock } from './wake-lock.js'; @@ -15,22 +15,26 @@ import { renderHeader, bindHeader } from './header.js'; import { buildShareLink } from './share-link.js'; import { exportJSON } from './render-input.js'; +// Below this many stops, two columns would leave one of them nearly empty. +const TWO_COLUMN_MIN_GROUPS = 6; + export function renderScheduleView() { stopClock(); const { items, conflicts, events } = computeSchedule(); + const groups = groupEvents(events); const app = document.getElementById('app'); app.innerHTML = `
- ${renderHeader('')} + ${renderHeader('')}
- +
--:--:-- @@ -63,7 +67,7 @@ export function renderScheduleView() {

Timeline

-
+
${renderTimeline(events, items)}
@@ -73,10 +77,10 @@ export function renderScheduleView() {
@@ -95,7 +99,7 @@ export function renderConflicts(conflicts) {
${conflicts.map(c => `
- \u26a0\ufe0f Conflict + ⚠️ Conflict
${escHtml(c.message)}
`).join('')} @@ -103,19 +107,23 @@ export function renderConflicts(conflicts) { `; } -export function renderTimeline(events, items) { - const nextDayOffset = getNextDayOffset(); - const nowM = nowMins() - nextDayOffset; - - // Group events by time +// Events sharing a clock time are one stop on the timeline. +function groupEvents(events) { const groups = []; for (const ev of events) { const last = groups[groups.length - 1]; if (last && last.time === ev.time) last.events.push(ev); else groups.push({ time: ev.time, events: [ev] }); } + return groups; +} + +export function renderTimeline(events, items) { + const nextDayOffset = getNextDayOffset(); + const nowM = nowMins() - nextDayOffset; + const cfg = applianceConfig(); - return groups.map(group => { + return groupEvents(events).map(group => { const isServeGroup = group.events.some(ev => ev.type === 'serve'); // A group is past if ALL events in it are past const isPast = group.events.every(ev => ev.endTime < nowM); @@ -144,25 +152,22 @@ export function renderTimeline(events, items) { const names = evs.map(e => e.itemName).filter(Boolean); const label = mergedLabel(type, evs, names); const sub = mergedSub(type, evs); + const tray = trayNote(evs); - // Override inputs (one per event in this cluster that canOverride) + // One panel of manual adjustments per overridable event in this cluster const overridable = evs.filter(e => e.canOverride && e.itemId); - const overrideHtml = overridable.map(ev => { + const editHtml = overridable.map(ev => { const item = items.find(i => i.id === ev.itemId); - const override = item?.overrideCookStart || ''; - const namePrefix = evs.length > 1 ? `${escHtml(ev.itemName)}: ` : ''; - return ` -
- - - ${override ? `` : ''} -
- `; + const namePrefix = evs.length > 1 ? `${escHtml(ev.itemName)}` : ''; + return `
+ ${namePrefix} + ${editFields(ev, item, cfg)} +
`; }).join(''); // Edit toggle: only present when at least one event in the cluster can be overridden const editBtn = overridable.length > 0 - ? `` + ? `` : ''; // Hidden trackers so the clock updater can find each original event @@ -177,14 +182,19 @@ export function renderTimeline(events, items) { ${editBtn}
${escHtml(label)}
${sub ? `
${escHtml(sub)}
` : ''} - ${overrideHtml} + ${tray ? `
🍲 ${escHtml(tray)}
` : ''} + ${editHtml ? `
${editHtml}
` : ''}
`; }).join(''); return ` -
-
${formatTime(group.time)}
+
+
+ ${formatTime(group.time)} + Now + Next +
${evRows}
@@ -192,6 +202,90 @@ export function renderTimeline(events, items) { }).join(''); } +// Tray advice for a step, printed only where the catalogue actually recommends +// the pairing — so it reads as advice rather than as a description of where +// things happened to land. Two dishes going in at the same moment are told to +// share one tray; a dish whose partner is already in (or still to come) is told +// what it is sharing with, which is the cue to use a big tray and leave room. +function trayNote(evs) { + const inCluster = new Set(evs.map(e => e.itemName)); + const together = new Set(); + const apart = new Set(); + for (const ev of evs) { + for (const mate of ev.trayMates || []) { + if (inCluster.has(mate)) { + together.add(ev.itemName); + together.add(mate); + } else { + apart.add(mate); + } + } + } + if (together.size >= 2) { + const also = apart.size ? ` (and ${joinNames([...apart])})` : ''; + return `One tray: ${joinNames([...together])}${also}`; + } + if (apart.size) return `Shares a tray with ${joinNames([...apart])}`; + return null; +} + +// The manual adjustments for a single dish: when it goes in, and where. +function editFields(ev, item, cfg) { + const resource = ev.ct?.resource; + const override = item?.overrideCookStart || ''; + const fields = [` + `]; + + if (resource === 'oven') { + const pref = item?.appliancePref || 'auto'; + fields.push(` + `); + + if (cfg.mainOvenShelves > 1) { + const shelfPref = item?.shelfPref ? String(item.shelfPref) : 'auto'; + fields.push(` + `); + } + } + + if (resource === 'hob') { + const pref = item?.appliancePref || 'auto'; + fields.push(` + `); + } + + return fields.join(''); +} + export function renderApplianceSummary(items) { const cfg = applianceConfig(); const nextDayOffset = getNextDayOffset(); @@ -217,17 +311,25 @@ export function renderApplianceSummary(items) { return html + '
'; } + // Shelf is called out here too, so a hand-picked one is verifiable at a + // glance; a pin marks the ones the cook chose rather than the planner. + function ovenLine(i) { + const shelf = cfg.mainOvenShelves > 1 && i._shelf + ? `Shelf ${i._shelf}${i._shelfPinned ? ' 📌' : ''} · ` : ''; + return `${escHtml(i.name)}: ${shelf}${formatTime(i._s.cookStart)}–${formatTime(i._s.cookEnd)}`; + } + return `

Appliances

Main Oven
-
${cfg.mainOvenShelves * 2} slots (${cfg.mainOvenShelves} shelf${cfg.mainOvenShelves > 1 ? ' \u00d7 2' : ''})
+
${cfg.mainOvenShelves * 2} slots (${cfg.mainOvenShelves} shelf${cfg.mainOvenShelves > 1 ? ' × 2' : ''})
${slotBar(mainUsed, cfg.mainOvenShelves * 2)}
${ovenItems.length === 0 ? 'Nothing scheduled' : - ovenItems.map(i => `${escHtml(i.name)}: ${formatTime(i._s.cookStart)}\u2013${formatTime(i._s.cookEnd)}`).join('')} + ovenItems.map(ovenLine).join('')}
${cfg.hasCombi ? ` @@ -237,7 +339,7 @@ export function renderApplianceSummary(items) { ${slotBar(combiUsed, 2)}
${combiItems.length === 0 ? 'Nothing scheduled' : - combiItems.map(i => `${escHtml(i.name)} (${i._appliance === 'combi' ? 'oven' : 'MW'}): ${formatTime(i._s.cookStart)}\u2013${formatTime(i._s.cookEnd)}`).join('')} + combiItems.map(i => `${escHtml(i.name)} (${i._appliance === 'combi' ? 'oven' : 'MW'}): ${formatTime(i._s.cookStart)}–${formatTime(i._s.cookEnd)}`).join('')}
` : ''}
@@ -251,7 +353,7 @@ export function renderApplianceSummary(items) {
${hobItems.length === 0 ? 'Nothing scheduled' : - hobItems.map(i => `${escHtml(i.name)} (${applianceLabel(i._appliance, null)}): ${formatTime(i._s.cookStart)}\u2013${formatTime(i._s.cookEnd)}`).join('')} + hobItems.map(i => `${escHtml(i.name)} (${applianceLabel(i._appliance, null)}): ${formatTime(i._s.cookStart)}–${formatTime(i._s.cookEnd)}`).join('')}
@@ -259,6 +361,46 @@ export function renderApplianceSummary(items) { `; } +// Read the adjustment panel back onto the items. Returns true when something +// actually changed, i.e. when the schedule needs recomputing. +function commitEdits(subEvent) { + let changed = false; + + const setField = (selector, apply) => { + subEvent.querySelectorAll(selector).forEach(input => { + const item = state.items.find(i => i.id === input.dataset.id); + if (!item) return; + if (apply(item, input.value)) { + saveItem(item); + changed = true; + } + }); + }; + + setField('.override-input', (item, value) => { + const next = value || null; + if ((item.overrideCookStart || null) === next) return false; + item.overrideCookStart = next; + return true; + }); + + setField('.tl-appl-input', (item, value) => { + const next = value || 'auto'; + if ((item.appliancePref || 'auto') === next) return false; + item.appliancePref = next; + return true; + }); + + setField('.tl-shelf-input', (item, value) => { + const next = value === 'auto' ? null : value; + if ((item.shelfPref ?? null) === next) return false; + item.shelfPref = next; + return true; + }); + + return changed; +} + export function bindScheduleEvents(items, events) { bindHeader(); @@ -292,7 +434,7 @@ export function bindScheduleEvents(items, events) { try { await navigator.clipboard.writeText(link); const btn = document.getElementById('btn-share'); - if (btn) { btn.textContent = '\u2705 Copied!'; setTimeout(() => { if (btn) btn.textContent = '\ud83d\udccb Copy link'; }, 2000); } + if (btn) { btn.textContent = '✅ Copied!'; setTimeout(() => { if (btn) btn.textContent = '📋 Copy link'; }, 2000); } } catch { // Clipboard blocked (e.g. insecure context) — surface the link to copy by hand. prompt('Copy this URL to share:', link); @@ -304,7 +446,7 @@ export function bindScheduleEvents(items, events) { document.getElementById('wake-lock-btn')?.addEventListener('click', toggleWakeLock); - // Edit / save toggle for override inputs (commits on save click) + // Edit / save toggle for the adjustment panel (commits on save click) document.getElementById('timeline')?.addEventListener('click', e => { const editBtn = e.target.closest('.tl-edit'); if (editBtn) { @@ -313,23 +455,11 @@ export function bindScheduleEvents(items, events) { const editing = subEvent.classList.toggle('editing'); if (editing) { editBtn.innerHTML = '💾 Save'; - editBtn.setAttribute('aria-label', 'Save cook start'); + editBtn.setAttribute('aria-label', 'Save changes'); // Focus the first input so the user can pick a time straight away subEvent.querySelector('.override-input')?.focus(); - } else { - // Commit any changed values then re-render the schedule - let changed = false; - subEvent.querySelectorAll('.override-input').forEach(inp => { - const id = inp.dataset.id; - const item = state.items.find(i => i.id === id); - const newVal = inp.value || null; - if (item && (item.overrideCookStart || null) !== newVal) { - item.overrideCookStart = newVal; - saveItem(item); - changed = true; - } - }); - if (changed) renderScheduleView(); + } else if (commitEdits(subEvent)) { + renderScheduleView(); } return; } diff --git a/cook-plan/share-link.js b/cook-plan/share-link.js index 1c1c755..4aabb3e 100644 --- a/cook-plan/share-link.js +++ b/cook-plan/share-link.js @@ -9,7 +9,8 @@ // Two layers of compression keep the hash short and readable: // 1. KEYS: every JSON key is the first letter of its property name. Where two // properties share an initial we fall back to two letters (cookType/cookTime -// → ct/co; shelfSlots/setTime → sh/se; hasCombi/hobCount → ha/ho). +// → ct/co; shelfSlots/setTime → sh/se; hasCombi/hobCount → ha/ho; +// shelfPref → sp). // 2. VALUES: anything equal to its default — null, 0, the documented default // string — is omitted on encode and refilled on decode. // @@ -27,6 +28,7 @@ function compactItem(item) { if (item.cookType && item.cookType !== 'oven') out.ct = item.cookType; if (item.shelfSlots && item.shelfSlots !== 1) out.sh = item.shelfSlots; if (item.appliancePref && item.appliancePref !== 'auto') out.a = item.appliancePref; + if (item.shelfPref) out.sp = item.shelfPref; if (item.prepTime) out.p = item.prepTime; if (item.cookTime) out.co = item.cookTime; if (item.setTime) out.se = item.setTime; @@ -41,6 +43,7 @@ function expandItem(c) { cookType: c.ct || 'oven', shelfSlots: c.sh ?? 1, appliancePref: c.a || 'auto', + shelfPref: c.sp ?? null, prepTime: c.p || 0, cookTime: c.co || 0, setTime: c.se || 0, diff --git a/cook-plan/style.css b/cook-plan/style.css index 0d85865..7bb38f6 100644 --- a/cook-plan/style.css +++ b/cook-plan/style.css @@ -14,6 +14,9 @@ --accent-glow: rgba(234, 88, 12, 0.2); --amber: #f59e0b; --amber-soft: #fef3c7; + /* The solid band behind whichever stage is happening right now. */ + --now-bg: #ffe8d1; + --now-sub: #9a3412; --bg: #fafafa; --bg-card: #ffffff; @@ -50,6 +53,8 @@ --accent-soft: #431407; --accent-glow: rgba(234, 88, 12, 0.3); --amber-soft: #451a03; + --now-bg: #3d1709; + --now-sub: #fdba74; --bg: #0a0a0a; --bg-card: #171717; @@ -809,6 +814,7 @@ button { align-items: flex-start; padding-block: var(--space-sm); position: relative; + isolation: isolate; & .tl-time { font-size: 0.8125rem; @@ -820,6 +826,21 @@ button { line-height: 1.4; } + /* Both labels are rendered on every stop; CSS alone decides which stop + shows which, so the clock moves the highlight by toggling a class and + nothing else. */ + & .tl-stage { + display: none; + margin-top: 0.1875rem; + padding: 0 0.25rem; + border-radius: 0.1875rem; + font-family: inherit; + font-size: 0.625rem; + font-weight: 700; + letter-spacing: 0.08em; + text-transform: uppercase; + } + & .tl-dot { display: flex; align-items: flex-start; @@ -890,7 +911,7 @@ button { } & .tl-sub-event.editing .tl-override { - display: flex; + display: block; } & .tl-chip { @@ -938,19 +959,58 @@ button { color: var(--text-2); margin-top: 0.125rem; } + & .tl-tray { + font-size: 0.8125rem; + color: var(--now-sub); + margin-top: 0.125rem; + } & .tl-override { display: none; - align-items: center; - gap: var(--space-sm); - margin-top: var(--space-xs); + margin-top: var(--space-sm); + padding: var(--space-sm); + background: var(--bg-card); + border: 1px solid var(--border); + border-radius: var(--radius); - & label { + & .tl-edit-row { + display: flex; + flex-wrap: wrap; + gap: var(--space-sm); + align-items: flex-end; + } + & .tl-edit-row + .tl-edit-row { + margin-top: var(--space-sm); + padding-top: var(--space-sm); + border-top: 1px dashed var(--border); + } + & .override-name { + flex-basis: 100%; font-size: 0.75rem; + font-weight: 600; + color: var(--text-2); + } + & .tl-field { + display: flex; + flex-direction: column; + gap: 0.125rem; + font-size: 0.6875rem; + font-weight: 600; + letter-spacing: 0.04em; + text-transform: uppercase; color: var(--text-3); } - & input[type='time'] { + & .tl-field-control { + display: flex; + align-items: center; + gap: 0.25rem; + } + & input[type='time'], + & select { font-size: 0.8125rem; - padding: 0.125rem 0.375rem; + font-weight: 400; + letter-spacing: normal; + text-transform: none; + padding: 0.1875rem 0.375rem; border: 1px solid var(--border); border-radius: 0.25rem; background: var(--bg); @@ -978,6 +1038,8 @@ button { } } + /* Mid-cook: a dish is in the oven. Several stops are in this state at once + for most of a roast, so it stays quiet — it is not where the cook is up to. */ &.tl-active { & .tl-dot span { background: var(--accent); @@ -990,6 +1052,73 @@ button { } } + /* The stage the cook is up to: one solid band running the full width of the + page. The cook is somewhere down the timeline rather than at the top of the + screen, so this has to be findable without reading any of the other stops. + The band is a pseudo-element, not a background on the row, so it can bleed + past the container's gutters without dragging the time column and dots out + of line with every other stop. */ + &.tl-current { + opacity: 1; /* outranks .tl-past, which a passed stop still carries */ + + &::after { + content: ''; + position: absolute; + inset-block: 0; + inset-inline: calc(var(--space-lg) * -1); + z-index: -1; + background: var(--now-bg); + border-left: 4px solid var(--accent); + } + & .tl-time { + color: var(--text); + } + & .tl-stage-now { + display: block; + background: var(--accent); + color: #fff; + } + & .tl-dot span { + background: var(--accent); + box-shadow: 0 0 0 4px + color-mix(in srgb, var(--accent) 25%, transparent); + } + & .tl-label { + color: var(--accent); + font-weight: 700; + font-size: 1rem; + } + & .tl-sub-event { + border-left-color: var(--accent); + } + & .tl-chip { + background: var(--accent); + border-color: var(--accent); + color: #fff; + } + } + + /* What comes next: outlined rather than filled, so there is never a question + which of the two is happening now. */ + &.tl-next { + &::after { + content: ''; + position: absolute; + inset-block: 0; + inset-inline: calc(var(--space-lg) * -1); + z-index: -1; + border-left: 4px solid color-mix(in srgb, var(--accent) 35%, transparent); + background: color-mix(in srgb, var(--now-bg) 45%, transparent); + } + & .tl-stage-next { + display: block; + background: transparent; + border: 1px solid var(--accent); + color: var(--accent); + padding: 0 0.1875rem; + } + } + &.tl-serve { & .tl-dot span { background: var(--amber); @@ -1012,6 +1141,65 @@ button { } } +/* The band bleeds by one gutter, so it reaches the screen edge on a phone. + There it would look like a card with its corners sliced off, so the radius + only arrives once the container has margins of its own to sit inside. */ +@media (min-width: 640px) { + .tl-event.tl-current::after, + .tl-event.tl-next::after { + inset-inline: calc(var(--space-xl) * -1); + border-radius: var(--radius); + } +} + +/* Two columns once there is room for them. Multi-column flow fills the left + column before the right, so the timeline still reads top-to-bottom then + across — the one arrangement that doesn't scramble a sequence of times. + Applied only to longer plans (see TWO_COLUMN_MIN_GROUPS): splitting five + stops leaves one column looking abandoned. */ +@media (min-width: 1024px) { + #view-schedule .container:has(.timeline-2col) { + max-width: 68rem; + } + + .timeline-2col { + /* The single-column timeline is a flex column, and multi-column layout has + no effect on a flex container — it has to go back to being a block. */ + display: block; + columns: 2; + column-gap: var(--space-3xl); + + /* The single full-height spine only ever covers the first column, so each + stop draws its own short segment instead; stacked, they join up. */ + &::before { + display: none; + } + + & .tl-event { + break-inside: avoid; + + &::before { + content: ''; + position: absolute; + left: 3.75rem; + top: 0; + bottom: 0; + width: 2px; + z-index: -1; + background: var(--border); + } + + /* Inside a column the band stops short of the gutter, so the two + columns' highlights can never run into each other. */ + &.tl-current::after, + &.tl-next::after { + inset-inline: calc(var(--space-sm) * -1); + border-radius: var(--radius); + } + } + } +} + /* Appliance summary */ .appliance-section { & h2 { @@ -1227,6 +1415,20 @@ dialog[open] { } /* Slot picker */ +/* Autocomplete follow-up: the catalogue's timings, offered or just applied. */ +.food-suggest { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: var(--space-sm); + margin-top: var(--space-sm); + + & .food-suggest-note { + font-size: 0.75rem; + color: var(--text-2); + } +} + .slot-picker { display: flex; align-items: center; @@ -1349,4 +1551,13 @@ dialog[open] { .tl-event.tl-past { opacity: 1; } + + /* A printed plan is read off the worktop over the whole cook, so "now" is + whenever you happen to look at it — the highlight would be a lie by the + time the ink is dry. */ + .tl-event.tl-current::after, + .tl-event.tl-next::after, + .tl-stage { + display: none !important; + } } From dc3fded11eb427e58e4daa0e61c9b14810f3ede3 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 16:11:08 +0000 Subject: [PATCH 02/14] [cook-plan] Sound one chime per moment, not one per event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The end of a cook is not one event, it is a dozen landing on the same minute: every dish ready, several out of the oven, and serve. Each got its own bell, and because each bell builds its own AudioContext — which starts counting from whenever it was constructed — fifteen two-second tones went off a few milliseconds apart. That came out as a ragged run of bongs rather than a chime. Measured on an eight-dish plan: 15 chimes between .164 and .204 of the same second. Events due on a tick are now collected, all marked as fired as before, and sounded once. The leader is chosen by significance (serve, then out of the oven, then in, prep, rest, ready), so serve still gets its two-note fanfare and is never drowned by the things that merely finished alongside it. The notification stack had the same split: fifteen cards for one instant, enough to push everything earlier in the cook past the twenty-card cap. A moment now posts one notification, led by the same event, with the others folded into its sub-line (three named, then a count). Co-Authored-By: Claude Opus 5 --- cook-plan/clock.js | 65 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/cook-plan/clock.js b/cook-plan/clock.js index b0a69bd..a8e8ad5 100644 --- a/cook-plan/clock.js +++ b/cook-plan/clock.js @@ -17,20 +17,31 @@ let lastStageKey = null; let notifications = []; const MAX_NOTIFICATIONS = 20; -function addNotification(ev) { - const id = chimeKey(ev); +// How many of a moment's other events to name before giving up and counting. +const NOTIFICATION_DETAIL = 3; + +// One notification per moment, led by its most significant event. The rest are +// folded into the sub-line: fifteen separate cards for "serve" would bury +// everything earlier in the stack under a single instant. +function addNotification(lead, all) { + const id = chimeKey(lead); if (notifications.some(n => n.id === id)) return; + + const others = all.filter(ev => ev !== lead).map(ev => ev.label); + const extra = others.length > NOTIFICATION_DETAIL + ? [...others.slice(0, NOTIFICATION_DETAIL), `+${others.length - NOTIFICATION_DETAIL} more`] + : others; + notifications.unshift({ id, - label: ev.label, - sub: ev.sub, - type: ev.type, - time: ev.time, + label: lead.label, + sub: [lead.sub, ...extra].filter(Boolean).join(' \u00b7 ') || null, + type: lead.type, + time: lead.time, }); if (notifications.length > MAX_NOTIFICATIONS) { notifications = notifications.slice(0, MAX_NOTIFICATIONS); } - renderNotifications(); } export function dismissNotification(id) { @@ -77,6 +88,20 @@ function chimeKey(ev) { return `${ev.time}:${ev.type}:${ev.itemId || ''}`; } +// Which event speaks for a moment, most significant first. The end of a cook +// is a dozen events on one minute -- every dish ready, several out of the oven, +// and serve -- and they are one moment, not a dozen. Only the leader is +// sounded, so SERVE wins over the things that merely finished with it. +const CHIME_PRIORITY = ['serve', 'cook_end', 'cook_start', 'prep', 'set', 'ready']; + +function leadEvent(evs) { + for (const type of CHIME_PRIORITY) { + const match = evs.find(ev => ev.type === type); + if (match) return match; + } + return evs[0]; +} + // Pre-seed so past events (and events right now on first load) don't trigger export function initChimes(events) { const nowM = nowMins() - nextDayOffset; @@ -163,16 +188,24 @@ function updateClock(events) { const nowS = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds(); const nowM = Math.floor(nowS / 60) - nextDayOffset; // adjusted for next-day schedules - // Fire chimes for events whose time has just been reached + // Fire a chime for events whose time has just been reached. Every one of them + // is marked as fired, but they share a single bell: a bell per event meant a + // dozen overlapping two-second tones at the end of a cook, each in its own + // AudioContext and so each starting a few milliseconds apart -- which came + // out as a ragged run of bongs rather than one chime. + const due = []; for (const ev of events) { - if (ev.time === nowM) { - const key = chimeKey(ev); - if (!chimesFired.has(key)) { - chimesFired.add(key); - playChime(ev.type); - addNotification(ev); - } - } + if (ev.time !== nowM) continue; + const key = chimeKey(ev); + if (chimesFired.has(key)) continue; + chimesFired.add(key); + due.push(ev); + } + if (due.length > 0) { + const lead = leadEvent(due); + playChime(lead.type); + addNotification(lead, due); + renderNotifications(); } clockTimeEl.textContent = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', second: '2-digit' }); From 7dc4a6a7e92bfe60e38416e5c014d0e7e7724b99 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 21:21:55 +0000 Subject: [PATCH 03/14] [cook-plan] Keep the combi free for the microwave where there's a choice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The combi is an oven or a microwave on demand, and the planner knew that — what it didn't do was take the microwave into account when handing out oven space. Dishes were placed in clock order, so a tray of parsnips could park itself in the combi at quarter past and the red cabbage would find the only microwave in the kitchen busy being an oven. Tray pairing made this more likely: a dish that scored well beside something already in the combi would choose it over an empty shelf in the main oven. Microwave dishes are now placed first, because they have exactly one home while an oven dish has two, and an oven dish will route around a booking that is already there. The preference is soft: a tray with nowhere else at all to go still takes the combi, and drops the booking it displaces rather than leaving it holding a slot it can no longer use — which would push the next tray out of the combi too. The clash itself now reads as one message per microwave dish rather than one per pair, and says what is tying the combi up and until when, instead of describing the device as though being dual-mode were the problem. Co-Authored-By: Claude Opus 5 --- cook-plan/appliances.js | 64 +++++++++++++++++++++++++++++++++--- cook-plan/conflicts.js | 72 ++++++++++++++++++++--------------------- 2 files changed, 95 insertions(+), 41 deletions(-) diff --git a/cook-plan/appliances.js b/cook-plan/appliances.js index 20b6314..53289a8 100644 --- a/cook-plan/appliances.js +++ b/cook-plan/appliances.js @@ -81,6 +81,34 @@ export function assignAppliances(items) { return best; } + // Microwave reservations, with the cooldown pad in front of them. The combi + // is either thing on demand -- what it cannot be is both at once, and it + // needs a few minutes off the heat before it will microwave. So an oven dish + // that runs up to (or over) a microwave slot is what makes the two + // incompatible; the device being dual-mode is not the problem. + function combiOvenBlocked(start, end, excludeId) { + return clashingMicrowave(start, end, excludeId).length > 0; + } + + // The shelf with the most room, for when a dish fits nowhere and has to go + // somewhere anyway -- a smaller pile-up makes for a clearer conflict. + function emptiestShelf(usage, start, end, excludeId, numShelves) { + let best = 1, most = -1; + for (let shelf = 1; shelf <= numShelves; shelf++) { + const free = 2 - slotsOnShelf(usage, shelf, start, end, excludeId); + if (free > most) { most = free; best = shelf; } + } + return best; + } + + // Microwave bookings that an oven run over [start, end) cannot live with. + function clashingMicrowave(start, end, excludeId) { + return combiUsage.filter(u => + u.itemId !== excludeId && u.mode === 'microwave' && + start < u.end && end + COMBI_COOLDOWN > u.start + ); + } + function combiModeAt(start, end, excludeId) { // Returns 'oven', 'microwave', or null (free) const overlapping = combiUsage.filter(u => @@ -116,7 +144,18 @@ export function assignAppliances(items) { const isPinned = (item) => (item.appliancePref && item.appliancePref !== 'auto') || shelfPrefOf(item, cfg.mainOvenShelves) !== null; - const order = [...sorted.filter(isPinned), ...sorted.filter(it => !isPinned(it))]; + + // A microwave dish has exactly one home. An oven dish has two and can route + // around a reservation -- but only around one that is already there, so the + // microwave gets its slot first. Taken in clock order instead, a tray of + // parsnips parks itself in the combi at quarter past and the red cabbage + // finds the only microwave in the kitchen busy being an oven. + const needsMicrowave = (item) => COOK_TYPE_MAP[item.cookType]?.resource === 'combi'; + const order = [ + ...sorted.filter(isPinned), + ...sorted.filter(it => !isPinned(it) && needsMicrowave(it)), + ...sorted.filter(it => !isPinned(it) && !needsMicrowave(it)), + ]; for (const item of order) { const { cookStart, cookEnd } = item._s; @@ -207,18 +246,35 @@ export function assignAppliances(items) { // neighbour in the main one: a crumble that only fits beside the // potatoes is better off on its own in the combi than sharing their // shelf. Ties go to the main oven, which is what "main oven first" means. - const combiMode = combiModeAt(cookStart, cookEnd, item.id); - const combiOpt = (tryCombi && cfg.hasCombi && (combiMode === null || combiMode === 'oven')) + const combiOpt = (tryCombi && cfg.hasCombi && !combiOvenBlocked(cookStart, cookEnd, item.id)) ? bestShelf(combiUsage, cookStart, cookEnd, item.id, slots, 1, 2, food) : null; + // Last resort, worked out before anything is placed: would the combi take + // this dish if the microwave bookings in the way were given up? + const displaced = tryCombi && cfg.hasCombi + ? clashingMicrowave(cookStart, cookEnd, item.id) : []; + const forcedOpt = displaced.length > 0 + ? bestShelf(combiUsage.filter(u => !displaced.includes(u)), + cookStart, cookEnd, item.id, slots, 1, 2, food) + : null; + if (mainOpt && (!combiOpt || mainOpt.score >= combiOpt.score)) { takeMain(mainOpt.shelf, false); } else if (combiOpt) { takeCombi(); + } else if (forcedOpt) { + // Nothing fits politely. Keeping the combi clear for a microwave dish is + // a preference, not a rule: a tray with nowhere at all to go takes the + // combi anyway. That makes the combi an oven for the window, so the + // booking it displaces is dropped rather than left holding a slot it + // can no longer use -- otherwise it would push the next tray out too. + // conflicts.js reports which microwave dish lost its slot. + for (const u of displaced) combiUsage.splice(combiUsage.indexOf(u), 1); + takeCombi(); } else { // Nowhere fits: into the main oven anyway, and conflicts.js will say so. - takeMain(1, false); + takeMain(emptiestShelf(mainOvenUsage, cookStart, cookEnd, item.id, cfg.mainOvenShelves), false); } } } diff --git a/cook-plan/conflicts.js b/cook-plan/conflicts.js index feca5b7..ec6d1d4 100644 --- a/cook-plan/conflicts.js +++ b/cook-plan/conflicts.js @@ -125,48 +125,46 @@ export function detectConflicts(items) { itemIds, }); } - // Mode conflicts and cooldown -- still pair-wise since mode is per-item - for (let i = 0; i < combiItems.length; i++) { - for (let j = i + 1; j < combiItems.length; j++) { - const a = combiItems[i], b = combiItems[j]; - const overlapStart = Math.max(a._s.cookStart, b._s.cookStart); - const overlapEnd = Math.min(a._s.cookEnd, b._s.cookEnd); - const modeA = a._appliance === 'combi' ? 'oven' : 'microwave'; - const modeB = b._appliance === 'combi' ? 'oven' : 'microwave'; + // Mode clashes, reported per microwave dish rather than per pair. Three + // trays sharing the combi oven is one problem, not three, and the combi + // being dual-mode is not the problem at all -- what the cook needs to know + // is what is tying it up and that something has to give. + for (const mw of mwItems) { + const overlapping = ovenItems.filter(o => + o._s.cookStart < mw._s.cookEnd && o._s.cookEnd > mw._s.cookStart + ); + const tooSoon = ovenItems.filter(o => + o._s.cookEnd <= mw._s.cookStart + && mw._s.cookStart - o._s.cookEnd < COMBI_COOLDOWN + ); - if (overlapEnd > overlapStart && modeA !== modeB) { - conflicts.push({ - type: 'combi-mode', - message: `Combi mode conflict: "${a.name}" needs it as ${modeA} but "${b.name}" needs it as ${modeB} during ${formatTime(overlapStart)}\u2013${formatTime(overlapEnd)}.`, - itemIds: [a.id, b.id], - }); - } - - // Cooldown: oven ends, then microwave starts - if (modeA === 'oven' && modeB === 'microwave' && a._s.cookEnd <= b._s.cookStart) { - const gap = b._s.cookStart - a._s.cookEnd; - if (gap < COMBI_COOLDOWN) { - conflicts.push({ - type: 'combi-cooldown', - message: `Combi needs ${COMBI_COOLDOWN}m cooldown before microwave use. "${a.name}" (oven) ends ${formatTime(a._s.cookEnd)}, "${b.name}" (microwave) starts ${formatTime(b._s.cookStart)} \u2014 only ${gap}m gap.`, - itemIds: [a.id, b.id], - }); - } - } - if (modeB === 'oven' && modeA === 'microwave' && b._s.cookEnd <= a._s.cookStart) { - const gap = a._s.cookStart - b._s.cookEnd; - if (gap < COMBI_COOLDOWN) { - conflicts.push({ - type: 'combi-cooldown', - message: `Combi needs ${COMBI_COOLDOWN}m cooldown before microwave use. "${b.name}" (oven) ends ${formatTime(b._s.cookEnd)}, "${a.name}" (microwave) starts ${formatTime(a._s.cookStart)} \u2014 only ${gap}m gap.`, - itemIds: [a.id, b.id], - }); - } - } + if (overlapping.length > 0) { + const until = formatTime(Math.max(...overlapping.map(o => o._s.cookEnd))); + conflicts.push({ + type: 'combi-mode', + message: `Combi is in use as an oven until ${until} (${names(overlapping)}), ` + + `so it can't microwave "${mw.name}" at ${formatTime(mw._s.cookStart)}. ` + + `Move a dish to the main oven, or cook "${mw.name}" another way.`, + itemIds: [mw.id, ...overlapping.map(o => o.id)], + }); + } else if (tooSoon.length > 0) { + const last = tooSoon.reduce((a, b) => (b._s.cookEnd > a._s.cookEnd ? b : a)); + const gap = mw._s.cookStart - last._s.cookEnd; + conflicts.push({ + type: 'combi-cooldown', + message: `Combi needs ${COMBI_COOLDOWN}m to cool down before it will microwave. ` + + `"${last.name}" comes out at ${formatTime(last._s.cookEnd)} and ` + + `"${mw.name}" wants it at ${formatTime(mw._s.cookStart)} \u2014 only ${gap}m gap.`, + itemIds: [mw.id, last.id], + }); } } } + function names(arr) { + return arr.map(i => `"${i.name}"`).join(', '); + } + function checkHobConflicts() { const hobItems = items.filter(i => COOK_TYPE_MAP[i.cookType]?.resource === 'hob' && i.cookTime > 0 From d0a9a94b5d75c24e5428e32c677eb1b522d726cc Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 21:22:05 +0000 Subject: [PATCH 04/14] [cook-plan] Add a simulated clock for trying the plan at any time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A cook plan is only interesting at the times it describes, which makes it awkward to check: the stage band, the chimes, the countdown and the next-up panel all do their work at half past three and nowhere else. The stopwatch button on the schedule, between Edit and the cog, opens a fake clock — scrub to any point in the cook, step between stages, or let it run at 10x or 60x and watch the timeline work. Everything that asks the time now asks sim-clock.js rather than Date, so one setting moves the whole app at once instead of just the readout. Simulated time is derived from real time (an anchor pair and a rate) rather than counted up, so a missed tick or a backgrounded tab can't make it drift. An amber pill sits above the page the whole time it is on, because a clock that lies should never be mistaken for one that doesn't; nothing is persisted, so a reload is always back to the real time. Two things only the fake clock could reach: - The "this plan must be tomorrow's" offset was decided when the schedule was built and never revisited, so scrubbing back into the cook left every comparison a day out and nothing responded. It now follows the clock. - Setting a time and pausing it is one gesture but two changes, and each sounded the moment it landed on. One landing, one chime. Co-Authored-By: Claude Opus 5 --- cook-plan/clock.js | 40 ++++++- cook-plan/index.html | 20 ++++ cook-plan/render-schedule.js | 10 +- cook-plan/schedule.js | 9 +- cook-plan/sim-clock.js | 89 +++++++++++++++ cook-plan/sim-dialog.js | 203 +++++++++++++++++++++++++++++++++++ cook-plan/style.css | 154 ++++++++++++++++++++++++++ cook-plan/utils.js | 13 ++- icons/stopwatch.svg | 7 ++ 9 files changed, 533 insertions(+), 12 deletions(-) create mode 100644 cook-plan/sim-clock.js create mode 100644 cook-plan/sim-dialog.js create mode 100644 icons/stopwatch.svg diff --git a/cook-plan/clock.js b/cook-plan/clock.js index a8e8ad5..465fda7 100644 --- a/cook-plan/clock.js +++ b/cook-plan/clock.js @@ -3,14 +3,21 @@ // ============================================= import { escHtml, formatCountdown, formatTime, nowMins } from './utils.js'; +import { now as clockNow } from './sim-clock.js'; // Module-private state let clockInterval = null; let chimesFired = new Set(); +// The events the running clock is ticking against, kept so the simulated clock +// can resync without the caller having to hand them back. +let currentEvents = []; let nextDayOffset = 0; // 1440 if the schedule is for the next calendar day // Which timeline stop is the current one, so a change of stage can be brought // into view. Null means "not looked yet" rather than "nothing is active". let lastStageKey = null; +// The minute the clock was last resynced to, so that two changes landing on the +// same minute don't sound its chime twice. +let lastSyncMinute = null; // In-memory notification stack — never persisted. When a chime fires we push // the event so the user can see what triggered the sound when they tab back in. @@ -84,6 +91,16 @@ export function setNextDayOffset(val) { nextDayOffset = val; } +// Whether the plan belongs to tomorrow rather than today: if every event is +// more than an hour in the past, the cook must be the next day's. It lives +// here rather than in computeSchedule because the simulated clock can change +// the answer without the schedule itself changing at all -- scrubbing back to +// lunchtime makes a plan that was "tomorrow's" today's again. +export function syncDayOffset(events) { + const last = events.reduce((m, ev) => Math.max(m, ev.endTime ?? ev.time), 0); + nextDayOffset = nowMins() > last + 60 ? 1440 : 0; +} + function chimeKey(ev) { return `${ev.time}:${ev.type}:${ev.itemId || ''}`; } @@ -168,8 +185,11 @@ function playChime(type) { } export function startClock(events) { + currentEvents = events; + syncDayOffset(events); initChimes(events); lastStageKey = null; + lastSyncMinute = null; updateClock(events); clockInterval = setInterval(() => updateClock(events), 1000); } @@ -178,13 +198,31 @@ export function stopClock() { if (clockInterval) { clearInterval(clockInterval); clockInterval = null; } } +// The simulated clock has moved. Everything before the new now counts as done +// -- otherwise scrubbing back and forth would replay every chime on the way -- +// but *strictly* before, so that landing on a moment still sounds it. Stepping +// a minute at a time through a cook to hear what it does is the whole point. +// +// Landing on the same minute twice does not, though: one gesture can set the +// time and then pause it, and two bells for one landing is the complaint this +// app has already had once. +export function resyncClock() { + syncDayOffset(currentEvents); + const nowM = nowMins() - nextDayOffset; + const cutoff = nowM === lastSyncMinute ? nowM + 1 : nowM; + lastSyncMinute = nowM; + chimesFired = new Set(currentEvents.filter(ev => ev.time < cutoff).map(chimeKey)); + lastStageKey = null; + if (document.getElementById('clock-time')) updateClock(currentEvents); +} + function updateClock(events) { const clockTimeEl = document.getElementById('clock-time'); const clockDateEl = document.getElementById('clock-date'); const clockNextEl = document.getElementById('clock-next'); if (!clockTimeEl) { stopClock(); return; } - const now = new Date(); + const now = clockNow(); const nowS = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds(); const nowM = Math.floor(nowS / 60) - nextDayOffset; // adjusted for next-day schedules diff --git a/cook-plan/index.html b/cook-plan/index.html index 680e77c..ad11159 100644 --- a/cook-plan/index.html +++ b/cook-plan/index.html @@ -41,6 +41,26 @@

Sync

+ + +
+

Simulate the clock

+ +
+
+
+ + + + diff --git a/cook-plan/render-schedule.js b/cook-plan/render-schedule.js index 3732403..6f3875d 100644 --- a/cook-plan/render-schedule.js +++ b/cook-plan/render-schedule.js @@ -12,6 +12,7 @@ import { startClock, stopClock, getNextDayOffset, dismissNotification, clearNoti import { toggleWakeLock, releaseWakeLock } from './wake-lock.js'; import { showInputView } from './router.js'; import { renderHeader, bindHeader } from './header.js'; +import { initSimUI } from './sim-dialog.js'; import { buildShareLink } from './share-link.js'; import { exportJSON } from './render-input.js'; @@ -27,7 +28,12 @@ export function renderScheduleView() { app.innerHTML = `
- ${renderHeader('')} + ${renderHeader(` + + + `)}
@@ -89,6 +95,8 @@ export function renderScheduleView() { bindScheduleEvents(items, events); startClock(events); + // After startClock, so the simulate controls act on a clock that is running. + initSimUI(events); // Re-paint any notifications that survived the re-render (e.g. after toggling // an override). The notification stack itself is module-private to clock.js. renderNotifications(); diff --git a/cook-plan/schedule.js b/cook-plan/schedule.js index f374f3f..414be58 100644 --- a/cook-plan/schedule.js +++ b/cook-plan/schedule.js @@ -3,11 +3,11 @@ // ============================================= import { state } from './state.js'; -import { parseTime, nowMins } from './utils.js'; +import { parseTime } from './utils.js'; import { assignAppliances } from './appliances.js'; import { detectConflicts } from './conflicts.js'; import { buildEvents } from './events.js'; -import { setNextDayOffset } from './clock.js'; +import { syncDayOffset } from './clock.js'; export function computeSchedule() { const target = parseTime(state.targetTime); @@ -53,10 +53,7 @@ export function computeSchedule() { const serveTime = Math.max(baseServe, lastFinish); const events = buildEvents(assigned, serveTime); - // If every scheduled event is more than 60 minutes in the past, the schedule - // must be for the next calendar day -- offset all "now" comparisons by +1 day. - const maxEventTime = events.reduce((m, ev) => Math.max(m, ev.endTime ?? ev.time), 0); - setNextDayOffset(nowMins() > maxEventTime + 60 ? 1440 : 0); + syncDayOffset(events); return { items: assigned, conflicts, events }; } diff --git a/cook-plan/sim-clock.js b/cook-plan/sim-clock.js new file mode 100644 index 0000000..7af1060 --- /dev/null +++ b/cook-plan/sim-clock.js @@ -0,0 +1,89 @@ +// ============================================= +// Cook Planner — sim-clock.js +// +// A fake clock, so the timeline can be watched at half past without standing +// in the kitchen until half past. Everything in the app that asks the time +// asks here, which is what makes one setting move the whole thing at once: the +// countdown, the current-stage band, the chimes and the next-up panel. +// +// Simulated time is *derived* from real time rather than counted up, so a +// missed tick or a backgrounded tab can't make it drift: an anchor pair (the +// real clock when it was set, the simulated second-of-day it was set to) and a +// rate are enough to work out the answer at any later moment. Pausing drops +// the real term and leaves the anchor. +// ============================================= + +const listeners = new Set(); + +let anchorReal = 0; // Date.now() when the simulated time was last set +let anchorSim = null; // second-of-day it was set to; null means the real clock +let rate = 1; // simulated seconds per real second +let paused = false; + +const DAY = 86400; + +export function isSimulated() { return anchorSim !== null; } +export function getRate() { return rate; } +export function isPaused() { return paused; } + +export function nowSecsOfDay() { + if (anchorSim === null) return realSecsOfDay(); + if (paused) return anchorSim; + return anchorSim + (Date.now() - anchorReal) / 1000 * rate; +} + +// A real Date carrying the simulated time of day, so every existing caller — +// toLocaleTimeString, getHours() — keeps working untouched. +export function now() { + if (anchorSim === null) return new Date(); + const midnight = new Date(); + midnight.setHours(0, 0, 0, 0); + return new Date(midnight.getTime() + nowSecsOfDay() * 1000); +} + +function realSecsOfDay() { + const d = new Date(); + return d.getHours() * 3600 + d.getMinutes() * 60 + d.getSeconds(); +} + +// Re-anchoring on every change is what keeps `rate` honest: without it the +// seconds already elapsed would be re-counted at the new rate. +function reanchor(simSecs) { + anchorSim = ((simSecs % DAY) + DAY) % DAY; + anchorReal = Date.now(); +} + +export function setSimSecs(secs) { reanchor(secs); emit(); } +export function setSimMins(mins) { setSimSecs(mins * 60); } +export function nudgeMins(delta) { setSimSecs(nowSecsOfDay() + delta * 60); } + +export function setRate(r) { + reanchor(nowSecsOfDay()); + rate = r; + paused = false; + emit(); +} + +// Pausing (or nudging) while the real clock is in charge is itself a request to +// simulate — it freezes wherever the real clock had got to. +export function setPaused(p) { + reanchor(nowSecsOfDay()); + paused = p; + emit(); +} + +export function useRealClock() { + anchorSim = null; + paused = false; + rate = 1; + emit(); +} + +export function onSimChange(fn) { + listeners.add(fn); + return () => listeners.delete(fn); +} + +function emit() { + for (const fn of listeners) fn(); +} diff --git a/cook-plan/sim-dialog.js b/cook-plan/sim-dialog.js new file mode 100644 index 0000000..e13902a --- /dev/null +++ b/cook-plan/sim-dialog.js @@ -0,0 +1,203 @@ +// ============================================= +// Cook Planner — sim-dialog.js +// +// The controls for the fake clock: scrub to any point in the cook, step +// between stages, or let it run fast and watch the timeline work. +// +// Nothing here knows what the simulated time *does* -- it only sets it, and +// the rest of the app reacts because it reads the clock through sim-clock.js. +// ============================================= + +import { formatTime } from './utils.js'; +import { + nowSecsOfDay, isSimulated, isPaused, getRate, + setSimMins, nudgeMins, setRate, setPaused, useRealClock, onSimChange, +} from './sim-clock.js'; +import { resyncClock } from './clock.js'; + +const RATES = [1, 10, 60]; +const NUDGES = [-30, -5, -1, 1, 5, 30]; +const PAD = 20; // minutes of slack either side of the cook on the scrubber + +let events = []; +let ticker = null; +let dragging = false; +let wired = false; + +// Called on every render of the schedule view: the cog and the simulate button +// are new elements each time, while the dialog and the status pill live in +// index.html and are wired once. +export function initSimUI(evs) { + events = evs || []; + document.getElementById('btn-simulate')?.addEventListener('click', openSimDialog); + if (!wired) { + wired = true; + document.getElementById('sim-bar-open')?.addEventListener('click', openSimDialog); + document.getElementById('sim-bar-exit')?.addEventListener('click', useRealClock); + const dialog = document.getElementById('sim-dialog'); + document.getElementById('sim-close')?.addEventListener('click', () => dialog.close()); + dialog?.addEventListener('click', (e) => { if (e.target === dialog) dialog.close(); }); + dialog?.addEventListener('close', () => { + clearInterval(ticker); + ticker = null; + }); + // One subscription drives everything downstream of a time change: the clock + // and timeline resync, and both readouts repaint. + onSimChange(() => { resyncClock(); paintBar(); paintDialog(); }); + } + paintBar(); +} + +function eventTimes() { + return [...new Set(events.map(ev => ev.time).filter(Number.isFinite))].sort((a, b) => a - b); +} + +function span() { + const times = eventTimes(); + if (times.length === 0) return { min: 0, max: 1439 }; + return { + min: Math.max(0, times[0] - PAD), + max: Math.min(1439, times[times.length - 1] + PAD), + }; +} + +export function openSimDialog() { + const dialog = document.getElementById('sim-dialog'); + const body = document.getElementById('sim-body'); + if (!dialog || !body) return; + + const { min, max } = span(); + body.innerHTML = ` +
+ --:--:-- + +
+ + +
${formatTime(min)}${formatTime(max)}
+ +
+ ${NUDGES.map(n => ``).join('')} +
+ +
+ + +
+ +
+ + ${RATES.map(r => ``).join('')} +
+ +
+ + + +
+ +

Everything reads this clock, so the countdown, the + highlighted stage and the chimes all follow it. Scrubbing pauses; pick a + speed to let it run. Nothing here is saved — reload and the real clock + is back.

+ `; + + const range = document.getElementById('sim-range'); + // Grabbing the scrubber pauses, or a 60x clock would drag itself out from + // under the thumb. + range.addEventListener('pointerdown', () => { dragging = true; setPaused(true); }); + range.addEventListener('keydown', () => setPaused(true)); + window.addEventListener('pointerup', () => { dragging = false; }, { once: false }); + range.addEventListener('input', () => setSimMins(Number(range.value))); + + body.querySelectorAll('[data-nudge]').forEach(btn => + btn.addEventListener('click', () => nudgeMins(Number(btn.dataset.nudge)))); + + body.querySelectorAll('[data-rate]').forEach(btn => + btn.addEventListener('click', () => { + if (btn.dataset.rate === 'pause') setPaused(!isPaused() || !isSimulated()); + else setRate(Number(btn.dataset.rate)); + })); + + document.getElementById('sim-prev').addEventListener('click', () => step(-1)); + document.getElementById('sim-next').addEventListener('click', () => step(1)); + document.getElementById('sim-jump-start').addEventListener('click', () => jumpTo(eventTimes()[0])); + document.getElementById('sim-jump-serve').addEventListener('click', () => { + const t = eventTimes(); + jumpTo(t[t.length - 1]); + }); + document.getElementById('sim-real').addEventListener('click', () => { + useRealClock(); + dialog.close(); + }); + + paintDialog(); + clearInterval(ticker); + // A running clock has to repaint itself; 200ms is smooth without being busy. + ticker = setInterval(paintDialog, 200); + dialog.showModal(); +} + +// Land on the whole minute of a stage, paused, so the moment can be looked at. +function jumpTo(mins) { + if (!Number.isFinite(mins)) return; + setSimMins(mins); + setPaused(true); +} + +function step(dir) { + const times = eventTimes(); + if (times.length === 0) return; + const nowM = Math.floor(nowSecsOfDay() / 60); + const target = dir > 0 + ? times.find(t => t > nowM) + : [...times].reverse().find(t => t < nowM); + jumpTo(target ?? (dir > 0 ? times[times.length - 1] : times[0])); +} + +function stateLabel() { + if (!isSimulated()) return 'real clock'; + if (isPaused()) return 'paused'; + return `running ${getRate()}×`; +} + +function clockText(secs) { + const s = Math.floor(((secs % 86400) + 86400) % 86400); + return [s / 3600, (s % 3600) / 60, s % 60] + .map(n => String(Math.floor(n)).padStart(2, '0')).join(':'); +} + +function paintDialog() { + const timeEl = document.getElementById('sim-readout-time'); + if (!timeEl) return; + const secs = nowSecsOfDay(); + timeEl.textContent = clockText(secs); + document.getElementById('sim-readout-state').textContent = stateLabel(); + + const range = document.getElementById('sim-range'); + if (range && !dragging) range.value = String(Math.round(secs / 60)); + + const rate = isSimulated() && !isPaused() ? String(getRate()) : null; + document.querySelectorAll('#sim-dialog [data-rate]').forEach(btn => { + const isPauseBtn = btn.dataset.rate === 'pause'; + btn.classList.toggle('active', + isPauseBtn ? (isSimulated() && isPaused()) : btn.dataset.rate === rate); + }); +} + +// The pill that sits above the page whenever the clock is a lie. It is the only +// thing on screen that says so, so it stays put while the timeline scrolls. +function paintBar() { + const bar = document.getElementById('sim-bar'); + document.body.classList.toggle('simulating', isSimulated()); + if (!bar) return; + bar.hidden = !isSimulated(); + if (!isSimulated()) return; + document.getElementById('sim-bar-time').textContent = clockText(nowSecsOfDay()); + document.getElementById('sim-bar-rate').textContent = isPaused() ? 'paused' : `${getRate()}×`; +} + +// While the clock is running the pill has to keep up with it. +setInterval(() => { if (isSimulated()) paintBar(); }, 500); diff --git a/cook-plan/style.css b/cook-plan/style.css index 7bb38f6..5e01e2c 100644 --- a/cook-plan/style.css +++ b/cook-plan/style.css @@ -1490,6 +1490,160 @@ dialog[open] { mask-image: url(/icons/settings.svg); } +.icon-stopwatch { + width: 1.25rem; + height: 1.25rem; + -webkit-mask-image: url(/icons/stopwatch.svg); + mask-image: url(/icons/stopwatch.svg); +} + +/* ---- Simulated clock ---- */ +/* The pill, pinned above everything, is the only thing that says the time on + screen is made up -- so it stays visible however far the timeline scrolls, + and it is loud enough not to be read as part of the plan. */ +.sim-bar { + position: fixed; + z-index: 50; + left: 50%; + bottom: var(--space-lg); + transform: translateX(-50%); + display: flex; + align-items: stretch; + max-width: calc(100vw - var(--space-lg) * 2); + background: var(--amber); + color: #1c1310; + border-radius: 999px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); + font-size: 0.8125rem; + + & button { + background: transparent; + border: none; + cursor: pointer; + color: inherit; + font: inherit; + padding: var(--space-sm) var(--space-md); + border-radius: 999px; + &:hover { background: rgba(0, 0, 0, 0.12); } + } + + & .sim-bar-main { + display: flex; + align-items: center; + gap: var(--space-sm); + min-width: 0; + } + + & strong { + font-family: ui-monospace, monospace; + font-variant-numeric: tabular-nums; + } + + & .sim-bar-exit { + font-size: 1.125rem; + line-height: 1; + padding-inline: var(--space-md); + } +} + +/* A running simulation gets a pulse; a paused one sits still. */ +.sim-bar-dot { + width: 0.5rem; + height: 0.5rem; + border-radius: 50%; + background: #1c1310; + flex: none; + animation: sim-pulse 1.6s ease-in-out infinite; +} + +@keyframes sim-pulse { + 0%, 100% { opacity: 1; } + 50% { opacity: 0.25; } +} + +@media (prefers-reduced-motion: reduce) { + .sim-bar-dot { animation: none; } +} + +/* The live clock readout is the one place a fake time could be taken for real, + so it is tinted while the simulation is on. */ +body.simulating .clock-time { + color: var(--amber); +} + +.sim-readout { + display: flex; + align-items: baseline; + justify-content: space-between; + gap: var(--space-md); + margin-bottom: var(--space-md); + + & .sim-readout-time { + font-family: ui-monospace, monospace; + font-variant-numeric: tabular-nums; + font-size: 2rem; + font-weight: 700; + color: var(--accent); + } + + & .sim-readout-state { + font-size: 0.8125rem; + color: var(--text-2); + } +} + +.sim-range { + width: 100%; + accent-color: var(--accent); +} + +.sim-scale { + display: flex; + justify-content: space-between; + font-size: 0.75rem; + color: var(--text-3); + font-family: ui-monospace, monospace; + margin-bottom: var(--space-lg); +} + +/* Every control row wraps rather than scrolls -- at 325px the nudge buttons + need two lines and that is fine. */ +.sim-row { + display: flex; + flex-wrap: wrap; + gap: var(--space-sm); + margin-bottom: var(--space-md); + + & .btn { + width: auto; + flex: 1 1 auto; + white-space: nowrap; + } +} + +/* The nudges are a set of equals, so they go in a grid rather than wrapping + into a short second row of stretched buttons. */ +.sim-nudges { + display: grid; + grid-template-columns: repeat(6, 1fr); +} + +@media (max-width: 460px) { + .sim-nudges { + grid-template-columns: repeat(3, 1fr); + } +} + +.sim-rates .btn.active { + background: var(--accent); + border-color: var(--accent); + color: #fff; +} + +@media print { + .sim-bar { display: none !important; } +} + /* ---- Settings dialog ---- */ #btn-settings { position: relative; diff --git a/cook-plan/utils.js b/cook-plan/utils.js index 5258078..b457e79 100644 --- a/cook-plan/utils.js +++ b/cook-plan/utils.js @@ -2,6 +2,11 @@ // Cook Planner — utils.js // ============================================= +// "Now" comes from the simulated clock rather than Date directly, so that +// setting a fake time moves every part of the app at once rather than just the +// readout. With no simulation running it is the real clock. +import { now } from './sim-clock.js'; + export function parseTime(str) { if (!str) return null; const [h, m] = str.split(':').map(Number); @@ -34,13 +39,13 @@ export function formatCountdown(totalSeconds) { } export function nowMins() { - const now = new Date(); - return now.getHours() * 60 + now.getMinutes(); + const n = now(); + return n.getHours() * 60 + n.getMinutes(); } export function nowSecs() { - const now = new Date(); - return now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds(); + const n = now(); + return n.getHours() * 3600 + n.getMinutes() * 60 + n.getSeconds(); } export function uid() { diff --git a/icons/stopwatch.svg b/icons/stopwatch.svg new file mode 100644 index 0000000..a14a92e --- /dev/null +++ b/icons/stopwatch.svg @@ -0,0 +1,7 @@ + + + + + + + From 013caeb5444f7ea9c86d19179a70c0f31298f942 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 21:32:38 +0000 Subject: [PATCH 05/14] [cook-plan] Put the chime log beside the timeline, not the timeline beside itself MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two columns asked for were the timeline and the chimes, not the timeline split down the middle. Splitting it was the wrong read: it bought nothing — a sequence of times reads perfectly well in one column — while the chime log sat at the top of the page, which is exactly where you are not looking once the cook is under way and the view has scrolled to the stage you are on. So the timeline goes back to a single column, and on a wide screen the log takes a column of its own on the right, sticky, so what has just gone off stays in view however far down the timeline you are. The schedule view widens to make room; the editor is a column of form rows and doesn't. Stacked, the log keeps its place above the timeline — below it would be past the end of a two-hour cook — and when nothing has chimed yet it isn't there at all, since there is no column for it to fill. On a wide screen the column stays, labelled and with a line saying what will appear in it, because a layout that reflows the moment the first bell goes is worse than one that starts out with a little room set aside. Neither the log nor the simulate pill prints. Co-Authored-By: Claude Opus 5 --- cook-plan/render-schedule.js | 26 +++++---- cook-plan/style.css | 110 +++++++++++++++++++++-------------- 2 files changed, 80 insertions(+), 56 deletions(-) diff --git a/cook-plan/render-schedule.js b/cook-plan/render-schedule.js index 6f3875d..92ff301 100644 --- a/cook-plan/render-schedule.js +++ b/cook-plan/render-schedule.js @@ -16,13 +16,9 @@ import { initSimUI } from './sim-dialog.js'; import { buildShareLink } from './share-link.js'; import { exportJSON } from './render-input.js'; -// Below this many stops, two columns would leave one of them nearly empty. -const TWO_COLUMN_MIN_GROUPS = 6; - export function renderScheduleView() { stopClock(); const { items, conflicts, events } = computeSchedule(); - const groups = groupEvents(events); const app = document.getElementById('app'); app.innerHTML = ` @@ -48,9 +44,6 @@ export function renderScheduleView() {
- - -
@@ -70,12 +63,21 @@ export function renderScheduleView() { ${conflicts.length > 0 ? renderConflicts(conflicts) : ''} - -
-

Timeline

-
- ${renderTimeline(events, items)} + +
+
+

Timeline

+
+ ${renderTimeline(events, items)} +
+ + +
diff --git a/cook-plan/style.css b/cook-plan/style.css index 5e01e2c..9aea0c2 100644 --- a/cook-plan/style.css +++ b/cook-plan/style.css @@ -1152,51 +1152,68 @@ button { } } -/* Two columns once there is room for them. Multi-column flow fills the left - column before the right, so the timeline still reads top-to-bottom then - across — the one arrangement that doesn't scramble a sequence of times. - Applied only to longer plans (see TWO_COLUMN_MIN_GROUPS): splitting five - stops leaves one column looking abandoned. */ -@media (min-width: 1024px) { - #view-schedule .container:has(.timeline-2col) { - max-width: 68rem; +/* The timeline and the chime log, side by side once there is room. The log + stays put while the timeline scrolls: on a two-hour cook the point of it is + to see what has just gone off without leaving the stage you are on. */ +.schedule-main { + display: grid; + gap: var(--space-lg); +} + +.schedule-aside { + /* Stacked, the log belongs above the timeline — below it would be past the + end of a two-hour cook. */ + order: -1; + + & h2 { + font-size: 0.8125rem; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.05em; + color: var(--text-2); + margin-bottom: var(--space-md); } +} - .timeline-2col { - /* The single-column timeline is a flex column, and multi-column layout has - no effect on a flex container — it has to go back to being a block. */ - display: block; - columns: 2; - column-gap: var(--space-3xl); +.schedule-aside-empty { + font-size: 0.8125rem; + color: var(--text-3); + line-height: 1.45; +} - /* The single full-height spine only ever covers the first column, so each - stop draws its own short segment instead; stacked, they join up. */ - &::before { - display: none; - } +.schedule-aside:has(.notifications:not([hidden])) .schedule-aside-empty { + display: none; +} - & .tl-event { - break-inside: avoid; - - &::before { - content: ''; - position: absolute; - left: 3.75rem; - top: 0; - bottom: 0; - width: 2px; - z-index: -1; - background: var(--border); - } +/* Narrow, there is no column to fill and nothing has chimed yet, so the + heading and its placeholder are just something else to scroll past. */ +@media (max-width: 1023px) { + .schedule-aside:not(:has(.notifications:not([hidden]))) { + display: none; + } +} - /* Inside a column the band stops short of the gutter, so the two - columns' highlights can never run into each other. */ - &.tl-current::after, - &.tl-next::after { - inset-inline: calc(var(--space-sm) * -1); - border-radius: var(--radius); - } - } +@media (min-width: 1024px) { + /* The schedule view alone widens — the editor is a column of form rows and + has nothing to do with the extra space. */ + #view-schedule .container { + max-width: 64rem; + } + + .schedule-main { + grid-template-columns: minmax(0, 1fr) 17rem; + gap: var(--space-2xl); + align-items: start; + } + + .schedule-aside { + order: 0; + position: sticky; + top: var(--space-lg); + /* Its own scrollbar rather than the page's, so a long stack of chimes + can't push the column taller than the screen. */ + max-height: calc(100dvh - var(--space-2xl)); + overflow-y: auto; } } @@ -1640,9 +1657,6 @@ body.simulating .clock-time { color: #fff; } -@media print { - .sim-bar { display: none !important; } -} /* ---- Settings dialog ---- */ #btn-settings { @@ -1686,12 +1700,20 @@ body.simulating .clock-time { } @media print { + /* The chime log is a record of a cook in progress — on paper it is a list of + things that already happened, and an empty column beside the timeline. */ .clock-bar .wake-lock-btn, .schedule-footer, - .app-header .header-actions { + .app-header .header-actions, + .schedule-aside, + .sim-bar { display: none !important; } + .schedule-main { + display: block; + } + .clock-bar { background: none; color: var(--text); From 88f67053ae3960d659a91c20811394e6df8c76e5 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 22:01:58 +0000 Subject: [PATCH 06/14] [cook-plan] Space the timeline out and clip the accent bars properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three things that all showed up in the same screenshot. Stops butted together. Each one's highlight band is the full height of its row, so with no gap between rows a lit stop and the one after it met edge to edge and read as a single block — exactly the confusion the band was added to clear up. The timeline now has a gap between stops. The gutter between the timeline and the chime log was narrower than it looked: the band bleeds a gutter's width past the timeline's content, so most of the 2rem gap was being spent before the columns were separated at all. Widened so there is a real gap left over. And the accent bars were border-lefts on rounded boxes, which curves the bar's inner edge along with its outer one and pinches it at top and bottom. The chime cards now draw theirs as a pseudo-element clipped by overflow: hidden, with the bar width and colour as custom properties; the timeline band can't hold a pseudo-element of its own — it is one — so it paints the bar into its background instead, which the radius clips the same way. Outer edge follows the corner, inner edge stays straight. Co-Authored-By: Claude Opus 5 --- cook-plan/style.css | 66 ++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/cook-plan/style.css b/cook-plan/style.css index 9aea0c2..8fa3c83 100644 --- a/cook-plan/style.css +++ b/cook-plan/style.css @@ -645,16 +645,31 @@ button { } .notification { + --bar: 4px; + --bar-colour: var(--text-3); display: flex; gap: var(--space-md); align-items: center; background: var(--bg-card); border: 1px solid var(--border); - border-left: 4px solid var(--text-3); border-radius: 0.375rem; - padding: var(--space-sm) var(--space-md); + padding: var(--space-sm) var(--space-md) var(--space-sm) calc(var(--space-md) + var(--bar)); box-shadow: var(--shadow-md); animation: notification-in 0.2s ease-out; + /* The accent is a clipped pseudo-element rather than a border-left, which + would curve the bar's inner edge along with its outer one and pinch it at + the corners. overflow: hidden does the clipping, so the outer edge follows + the radius and the inner edge stays straight. */ + position: relative; + overflow: hidden; + + &::before { + content: ''; + position: absolute; + inset: 0 auto 0 0; + width: var(--bar); + background: var(--bar-colour); + } & .notification-time { font-family: ui-monospace, monospace; @@ -698,24 +713,12 @@ button { } /* Per-type accent matches the timeline chip colours */ - &.notification-prep { - border-left-color: var(--amber); - } - &.notification-cook_start { - border-left-color: var(--accent); - } - &.notification-cook_end { - border-left-color: var(--text-3); - } - &.notification-set { - border-left-color: #3b82f6; - } - &.notification-ready { - border-left-color: var(--green); - } - &.notification-serve { - border-left-color: var(--amber); - } + &.notification-prep { --bar-colour: var(--amber); } + &.notification-cook_start { --bar-colour: var(--accent); } + &.notification-cook_end { --bar-colour: var(--text-3); } + &.notification-set { --bar-colour: #3b82f6; } + &.notification-ready { --bar-colour: var(--green); } + &.notification-serve { --bar-colour: var(--amber); } } @keyframes notification-in { @@ -794,6 +797,10 @@ button { .timeline { display: flex; flex-direction: column; + /* Stops sit apart rather than butting together: each one's highlight band is + the full height of its row, so with no gap two lit rows meet edge to edge + and read as one block. */ + gap: var(--space-md); position: relative; &::before { @@ -808,6 +815,7 @@ button { } .tl-event { + --bar: 4px; display: grid; grid-template-columns: 3.5rem 1.5rem 1fr; gap: 0 var(--space-sm); @@ -1067,8 +1075,13 @@ button { inset-block: 0; inset-inline: calc(var(--space-lg) * -1); z-index: -1; - background: var(--now-bg); - border-left: 4px solid var(--accent); + /* The bar is painted into the background rather than drawn as a border: + a border-left curves at both edges once the band has a radius, which + leaves the bar pinched at top and bottom. A background is clipped to + the curve, so the outer edge follows the corner and the inner edge + stays straight. */ + background: linear-gradient(to right, + var(--accent) 0 var(--bar), var(--now-bg) var(--bar)); } & .tl-time { color: var(--text); @@ -1107,8 +1120,9 @@ button { inset-block: 0; inset-inline: calc(var(--space-lg) * -1); z-index: -1; - border-left: 4px solid color-mix(in srgb, var(--accent) 35%, transparent); - background: color-mix(in srgb, var(--now-bg) 45%, transparent); + background: linear-gradient(to right, + color-mix(in srgb, var(--accent) 35%, transparent) 0 var(--bar), + color-mix(in srgb, var(--now-bg) 45%, transparent) var(--bar)); } & .tl-stage-next { display: block; @@ -1202,7 +1216,9 @@ button { .schedule-main { grid-template-columns: minmax(0, 1fr) 17rem; - gap: var(--space-2xl); + /* The highlight band bleeds a gutter's width past the timeline's content, + so the gap has to cover that before it starts separating the columns. */ + gap: var(--space-3xl); align-items: start; } From 6e05841d80b954308343b183af3ea0a9d87a209d Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 22:08:13 +0000 Subject: [PATCH 07/14] [cook-plan] Count up inside each step that is under way MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A step says how long it takes, which is the one thing you already know. What you want standing at the oven is how long it has been in — the chicken went in at 14:05 and the useful figure at twenty to three is 35m, not 1h 30m. Every step with a duration now carries a live count under its details, in hours and minutes with the hours left off until there are some. The markup carries only the window the step runs for; the clock fills in the figure and decides whether to show it, so it is one more thing the per-second tick does alongside the stage band — which means it follows the simulated clock for free, and scrubbing or running at 60x moves it as you would expect. It appears between the step's start and its end and nowhere else. Before, there is nothing to count. After, the row is past and dimmed and the step's full length is already printed on the line above. Steps that are instants rather than stretches — "chicken out of oven" — never get one: you cannot be forty minutes into a moment. Nor does a printed plan, which has no now. Co-Authored-By: Claude Opus 5 --- cook-plan/clock.js | 28 ++++++++++++++++++++++++++++ cook-plan/render-schedule.js | 12 ++++++++++++ cook-plan/style.css | 21 ++++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/cook-plan/clock.js b/cook-plan/clock.js index 465fda7..ed61ed9 100644 --- a/cook-plan/clock.js +++ b/cook-plan/clock.js @@ -282,10 +282,38 @@ function updateClock(events) { }); markCurrentStage(tlRows, nowM); + tickElapsed(nowM); // Update appliance slots (re-render just slot bars would need full re-render; skip for perf) } +// How long each step that is currently under way has been under way: the +// chicken went in at 14:05, and at twenty to three the thing worth knowing is +// that it has been in for 35 minutes. Shown only between the step's start and +// its end -- before, there is nothing to count; after, the row is past and the +// step's full length is already printed beside it. +function tickElapsed(nowM) { + for (const el of document.querySelectorAll('.tl-elapsed')) { + const start = Number(el.dataset.start); + const end = Number(el.dataset.end); + if (!Number.isFinite(start) || !Number.isFinite(end)) continue; + const running = nowM >= start && nowM <= end; + el.hidden = !running; + if (running) { + el.querySelector('.tl-elapsed-value').textContent = elapsedText(nowM - start); + } + } +} + +// Hours and minutes, with the hours dropped when there are none. The minutes +// are padded once hours appear so a ticking figure doesn't jump a character +// wider between 1h 9m and 1h 10m. +function elapsedText(mins) { + const m = Math.max(0, mins); + const h = Math.floor(m / 60); + return h === 0 ? `${m}m` : `${h}h ${String(m % 60).padStart(2, '0')}m`; +} + // Which stop the cook has got to. // // "In progress" is no help on its own: a turkey is in progress for two hours, diff --git a/cook-plan/render-schedule.js b/cook-plan/render-schedule.js index 92ff301..0b4707d 100644 --- a/cook-plan/render-schedule.js +++ b/cook-plan/render-schedule.js @@ -180,6 +180,17 @@ export function renderTimeline(events, items) { ? `` : ''; + // How long this step has been going. Only steps that take time get one -- + // "chicken out of oven" is an instant, not something you can be 40 + // minutes into. The clock fills it in and decides when to show it, so + // the markup carries the window rather than a value. + const runsUntil = Math.max(...evs.map(e => e.endTime ?? e.time)); + const elapsedHtml = runsUntil > group.time + ? `` + : ''; + // Hidden trackers so the clock updater can find each original event const trackers = evs.map(ev => `` @@ -192,6 +203,7 @@ export function renderTimeline(events, items) { ${editBtn}
${escHtml(label)}
${sub ? `
${escHtml(sub)}
` : ''} + ${elapsedHtml} ${tray ? `
🍲 ${escHtml(tray)}
` : ''} ${editHtml ? `
${editHtml}
` : ''}
diff --git a/cook-plan/style.css b/cook-plan/style.css index 8fa3c83..ac97969 100644 --- a/cook-plan/style.css +++ b/cook-plan/style.css @@ -896,6 +896,24 @@ button { border-left-color: var(--green); } + /* The live count sits under the step's own details, where the static + "1h 30m" it is counting towards already is. */ + & .tl-elapsed { + display: inline-flex; + align-items: baseline; + gap: 0.3em; + margin-top: var(--space-xs); + font-size: 0.8125rem; + color: var(--text-2); + } + + & .tl-elapsed-value { + font-family: ui-monospace, monospace; + font-variant-numeric: tabular-nums; + font-weight: 600; + color: var(--accent); + } + & .tl-tracker { display: none; } @@ -1749,7 +1767,8 @@ body.simulating .clock-time { time the ink is dry. */ .tl-event.tl-current::after, .tl-event.tl-next::after, - .tl-stage { + .tl-stage, + .tl-elapsed { display: none !important; } } From b91b2b22c3f28b86f5d8f17dbf82b7771118fb94 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 22:15:54 +0000 Subject: [PATCH 08/14] [cook-plan] Add serving prep, and say when the meal actually lands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A dish isn't done when it stops cooking. A chicken has to be carved, a pudding turned out, a sauce poured — ten minutes of work that has to happen before anyone eats, and that the plan was quietly assuming took no time at all. Items now carry a serving prep alongside prep, cook and rest, and the whole schedule counts back through it: a chicken needing ten minutes of carving goes into the oven ten minutes earlier than one that doesn't, in both start and end mode. It shows on the timeline as its own step — PLATE, "carve / plate" — which means it gets a chime, a running count and a colour of its own, violet, since it is the one stage that is neither heat nor waiting. "Ready" moves to the end of it, because that is when the dish is actually ready. The catalogue carries a serving time too, so picking Roast chicken fills in 10 minutes along with the other three; nearly every other dish is zero, a tray of parsnips going from oven to table as it always did. The summary strip was also quietly unhelpful: in start mode it showed when to start and never said when you would eat. It now reads first action, serving at, start to table, items — with the serve time read off the schedule rather than the target, so a hand-set start that pushes the meal later says so. The running count gets its own colour rather than the orange it shared with the step's own label, where a figure that changes read as part of the heading. Co-Authored-By: Claude Opus 5 --- cook-plan/clock.js | 3 +- cook-plan/constants.js | 1 + cook-plan/db.js | 2 + cook-plan/events.js | 28 ++++++-- cook-plan/foods.js | 124 ++++++++++++++++++----------------- cook-plan/item-modal.js | 40 +++++++---- cook-plan/render-input.js | 1 + cook-plan/render-schedule.js | 27 ++++++-- cook-plan/schedule.js | 22 +++++-- cook-plan/share-link.js | 6 +- cook-plan/style.css | 22 ++++++- 11 files changed, 183 insertions(+), 93 deletions(-) diff --git a/cook-plan/clock.js b/cook-plan/clock.js index ed61ed9..c05c5a3 100644 --- a/cook-plan/clock.js +++ b/cook-plan/clock.js @@ -109,7 +109,7 @@ function chimeKey(ev) { // is a dozen events on one minute -- every dish ready, several out of the oven, // and serve -- and they are one moment, not a dozen. Only the leader is // sounded, so SERVE wins over the things that merely finished with it. -const CHIME_PRIORITY = ['serve', 'cook_end', 'cook_start', 'prep', 'set', 'ready']; +const CHIME_PRIORITY = ['serve', 'cook_end', 'serve_prep', 'cook_start', 'prep', 'set', 'ready']; function leadEvent(evs) { for (const type of CHIME_PRIORITY) { @@ -135,6 +135,7 @@ function playChime(type) { cook_start: 523.25, // C5 -- things going in cook_end: 783.99, // G5 -- higher/urgent: things coming out set: 440.00, // A4 -- soft + serve_prep: 659.25, // E5 -- hands needed, but nothing is burning serve: 987.77, // B5 -- bright fanfare note }; const freq = freqMap[type] ?? 523.25; diff --git a/cook-plan/constants.js b/cook-plan/constants.js index 9df5eba..cc39264 100644 --- a/cook-plan/constants.js +++ b/cook-plan/constants.js @@ -29,6 +29,7 @@ export const EV_TYPE_CHIP = { cook_start: 'IN', cook_end: 'OUT', set: 'REST', + serve_prep: 'PLATE', ready: 'READY', serve: '', }; diff --git a/cook-plan/db.js b/cook-plan/db.js index d425f1a..758dd2a 100644 --- a/cook-plan/db.js +++ b/cook-plan/db.js @@ -49,6 +49,7 @@ function itemToDoc(item) { prepTime: item.prepTime || 0, cookTime: item.cookTime || 0, setTime: item.setTime || 0, + servePrep: item.servePrep || 0, overrideCookStart: item.overrideCookStart ?? null, order: item.order ?? 0, createdAt: item.createdAt ?? Date.now(), @@ -66,6 +67,7 @@ function itemFromDoc(doc) { prepTime: doc.prepTime || 0, cookTime: doc.cookTime || 0, setTime: doc.setTime || 0, + servePrep: doc.servePrep || 0, overrideCookStart: doc.overrideCookStart ?? null, order: doc.order ?? 0, createdAt: doc.createdAt ?? 0, diff --git a/cook-plan/events.js b/cook-plan/events.js index f8445d3..804c9f6 100644 --- a/cook-plan/events.js +++ b/cook-plan/events.js @@ -9,7 +9,7 @@ export function buildEvents(items, serveTime) { const events = []; for (const item of items) { - const { cookStart, prepStart, cookEnd, setEnd } = item._s; + const { cookStart, prepStart, cookEnd, setEnd, serveEnd } = item._s; const ct = COOK_TYPE_MAP[item.cookType]; if (item.prepTime > 0) { @@ -92,9 +92,24 @@ export function buildEvents(items, serveTime) { }); } + // Carving, plating, saucing: the last hands-on job, and the reason a dish + // that needs it has to come out of the oven earlier than one that doesn't. + if (item.servePrep > 0) { + events.push({ + time: setEnd, + endTime: serveEnd, + type: 'serve_prep', + label: `${item.name} \u2014 carve / plate`, + sub: formatDuration(item.servePrep), + itemId: item.id, + itemName: item.name, + applianceKey: 'serve_prep', + }); + } + events.push({ - time: setEnd, - endTime: setEnd, + time: serveEnd, + endTime: serveEnd, type: 'ready', label: `${item.name} ready`, sub: null, @@ -107,8 +122,8 @@ export function buildEvents(items, serveTime) { // Cooked items that are already done before serve get a "ready and waiting" // note. Prep-only items aren't included \u2014 they're not "out of the oven". const restingNotes = items - .filter(it => it.cookType !== 'none' && it.cookTime > 0 && it._s.setEnd < serveTime) - .map(it => `${it.name} been out ${formatDuration(serveTime - it._s.setEnd)}`) + .filter(it => it.cookType !== 'none' && it.cookTime > 0 && it._s.serveEnd < serveTime) + .map(it => `${it.name} been out ${formatDuration(serveTime - it._s.serveEnd)}`) .join(' \u00b7 '); events.push({ @@ -150,7 +165,8 @@ export function mergedLabel(type, evs, names) { if (resource === 'hob') return `${joinNames(names)} off hob`; return `${joinNames(names)} done`; } - case 'set': return `${joinNames(names)} \u2014 rest / set`; + case 'set': return `${joinNames(names)} \u2014 rest / set`; + case 'serve_prep': return `${joinNames(names)} \u2014 carve / plate`; case 'ready': return `${joinNames(names)} ready`; default: return evs[0]?.label || ''; } diff --git a/cook-plan/foods.js b/cook-plan/foods.js index 68d7366..85bb48b 100644 --- a/cook-plan/foods.js +++ b/cook-plan/foods.js @@ -17,81 +17,85 @@ // 200°C+, mid 180–190°C, low 150–170°C. `tray` says whether a dish is loose on // a baking tray ('open', so it can share one) or sealed in its own dish or tin // ('dish' — happy to share a shelf, but never a tray). +// +// `serve` is the hands-on job between resting and eating — carving a joint, +// turning out a pudding. Nearly everything is zero: a tray of parsnips goes +// from the oven to the table. // ============================================= -// name, cookType, prep, cook, rest, slots, family, heat, tray +// name, cookType, prep, cook, rest, serve, slots, family, heat, tray const RAW = [ // ── Big roasts ── - ['Turkey', 'oven', 20, 180, 30, 2, 'poultry', 'mid', 'dish'], - ['Turkey crown', 'oven', 15, 120, 25, 2, 'poultry', 'mid', 'dish'], - ['Roast chicken', 'oven', 10, 90, 15, 2, 'poultry', 'mid', 'dish'], - ['Chicken thighs', 'oven', 5, 45, 5, 1, 'poultry', 'mid', 'open'], - ['Roast duck', 'oven', 15, 120, 20, 2, 'poultry', 'mid', 'dish'], - ['Roast goose', 'oven', 20, 150, 30, 2, 'poultry', 'mid', 'dish'], - ['Beef joint', 'oven', 15, 90, 25, 2, 'red-meat', 'hot', 'dish'], - ['Rib of beef', 'oven', 20, 120, 30, 2, 'red-meat', 'hot', 'dish'], - ['Leg of lamb', 'oven', 15, 105, 25, 2, 'red-meat', 'mid', 'dish'], - ['Shoulder of lamb', 'oven', 15, 240, 30, 2, 'red-meat', 'low', 'dish'], - ['Pork loin', 'oven', 15, 100, 20, 2, 'red-meat', 'mid', 'dish'], - ['Pork belly', 'oven', 20, 150, 15, 2, 'red-meat', 'low', 'dish'], - ['Gammon joint', 'oven', 15, 120, 15, 2, 'red-meat', 'mid', 'dish'], - ['Beef Wellington', 'oven', 30, 40, 15, 2, 'pastry', 'hot', 'dish'], - ['Nut roast', 'oven', 20, 50, 10, 1, 'veg-bake', 'mid', 'dish'], + ['Turkey', 'oven', 20, 180, 30, 20, 2, 'poultry', 'mid', 'dish'], + ['Turkey crown', 'oven', 15, 120, 25, 15, 2, 'poultry', 'mid', 'dish'], + ['Roast chicken', 'oven', 10, 90, 15, 10, 2, 'poultry', 'mid', 'dish'], + ['Chicken thighs', 'oven', 5, 45, 5, 0, 1, 'poultry', 'mid', 'open'], + ['Roast duck', 'oven', 15, 120, 20, 10, 2, 'poultry', 'mid', 'dish'], + ['Roast goose', 'oven', 20, 150, 30, 15, 2, 'poultry', 'mid', 'dish'], + ['Beef joint', 'oven', 15, 90, 25, 10, 2, 'red-meat', 'hot', 'dish'], + ['Rib of beef', 'oven', 20, 120, 30, 15, 2, 'red-meat', 'hot', 'dish'], + ['Leg of lamb', 'oven', 15, 105, 25, 10, 2, 'red-meat', 'mid', 'dish'], + ['Shoulder of lamb', 'oven', 15, 240, 30, 10, 2, 'red-meat', 'low', 'dish'], + ['Pork loin', 'oven', 15, 100, 20, 10, 2, 'red-meat', 'mid', 'dish'], + ['Pork belly', 'oven', 20, 150, 15, 10, 2, 'red-meat', 'low', 'dish'], + ['Gammon joint', 'oven', 15, 120, 15, 10, 2, 'red-meat', 'mid', 'dish'], + ['Beef Wellington', 'oven', 30, 40, 15, 5, 2, 'pastry', 'hot', 'dish'], + ['Nut roast', 'oven', 20, 50, 10, 5, 1, 'veg-bake', 'mid', 'dish'], // ── Roast veg: the tray-sharers ── - ['Roast potatoes', 'oven', 20, 55, 0, 2, 'root-veg', 'hot', 'open'], - ['Hasselback potatoes', 'oven', 20, 60, 0, 2, 'root-veg', 'hot', 'open'], - ['Parsnips', 'oven', 10, 40, 0, 1, 'root-veg', 'hot', 'open'], - ['Honey-roast carrots', 'oven', 10, 35, 0, 1, 'root-veg', 'hot', 'open'], - ['Roast swede', 'oven', 10, 45, 0, 1, 'root-veg', 'hot', 'open'], - ['Roast beetroot', 'oven', 10, 50, 0, 1, 'root-veg', 'hot', 'open'], - ['Sweet potatoes', 'oven', 10, 40, 0, 1, 'root-veg', 'hot', 'open'], - ['Roast veg medley', 'oven', 15, 40, 0, 2, 'root-veg', 'hot', 'open'], - ['Roast onions', 'oven', 5, 35, 0, 1, 'allium', 'hot', 'open'], - ['Roast shallots', 'oven', 5, 30, 0, 1, 'allium', 'hot', 'open'], - ['Roast leeks', 'oven', 5, 30, 0, 1, 'allium', 'mid', 'open'], - ['Roast sprouts', 'oven', 8, 25, 0, 1, 'brassica', 'hot', 'open'], - ['Roast cauliflower', 'oven', 8, 30, 0, 1, 'brassica', 'hot', 'open'], - ['Roast broccoli', 'oven', 5, 20, 0, 1, 'brassica', 'hot', 'open'], + ['Roast potatoes', 'oven', 20, 55, 0, 0, 2, 'root-veg', 'hot', 'open'], + ['Hasselback potatoes', 'oven', 20, 60, 0, 0, 2, 'root-veg', 'hot', 'open'], + ['Parsnips', 'oven', 10, 40, 0, 0, 1, 'root-veg', 'hot', 'open'], + ['Honey-roast carrots', 'oven', 10, 35, 0, 0, 1, 'root-veg', 'hot', 'open'], + ['Roast swede', 'oven', 10, 45, 0, 0, 1, 'root-veg', 'hot', 'open'], + ['Roast beetroot', 'oven', 10, 50, 0, 0, 1, 'root-veg', 'hot', 'open'], + ['Sweet potatoes', 'oven', 10, 40, 0, 0, 1, 'root-veg', 'hot', 'open'], + ['Roast veg medley', 'oven', 15, 40, 0, 0, 2, 'root-veg', 'hot', 'open'], + ['Roast onions', 'oven', 5, 35, 0, 0, 1, 'allium', 'hot', 'open'], + ['Roast shallots', 'oven', 5, 30, 0, 0, 1, 'allium', 'hot', 'open'], + ['Roast leeks', 'oven', 5, 30, 0, 0, 1, 'allium', 'mid', 'open'], + ['Roast sprouts', 'oven', 8, 25, 0, 0, 1, 'brassica', 'hot', 'open'], + ['Roast cauliflower', 'oven', 8, 30, 0, 0, 1, 'brassica', 'hot', 'open'], + ['Roast broccoli', 'oven', 5, 20, 0, 0, 1, 'brassica', 'hot', 'open'], // ── Trimmings ── - ['Pigs in blankets', 'oven', 10, 30, 0, 1, 'sausage', 'mid', 'open'], - ['Pork sausages', 'oven', 2, 30, 0, 1, 'sausage', 'mid', 'open'], - ['Stuffing balls', 'oven', 10, 30, 0, 1, 'stuffing', 'mid', 'open'], - ['Sage & onion stuffing','oven', 10, 35, 0, 1, 'stuffing', 'mid', 'dish'], - ['Yorkshire puddings', 'oven', 10, 22, 0, 1, 'batter', 'hot', 'dish'], - ['Toad in the hole', 'oven', 15, 40, 0, 2, 'batter', 'hot', 'dish'], - ['Pork crackling', 'oven', 5, 25, 0, 1, 'red-meat', 'hot', 'open'], - ['Cauliflower cheese', 'oven', 20, 30, 5, 2, 'veg-bake', 'mid', 'dish'], - ['Dauphinoise potatoes', 'oven', 20, 75, 10, 2, 'veg-bake', 'mid', 'dish'], - ['Bread rolls', 'oven', 2, 10, 0, 1, 'bread', 'hot', 'open'], - ['Garlic bread', 'oven', 2, 15, 0, 1, 'bread', 'hot', 'open'], - ['Salmon fillets', 'oven', 5, 20, 5, 1, 'fish', 'mid', 'open'], + ['Pigs in blankets', 'oven', 10, 30, 0, 0, 1, 'sausage', 'mid', 'open'], + ['Pork sausages', 'oven', 2, 30, 0, 0, 1, 'sausage', 'mid', 'open'], + ['Stuffing balls', 'oven', 10, 30, 0, 0, 1, 'stuffing', 'mid', 'open'], + ['Sage & onion stuffing','oven', 10, 35, 0, 0, 1, 'stuffing', 'mid', 'dish'], + ['Yorkshire puddings', 'oven', 10, 22, 0, 0, 1, 'batter', 'hot', 'dish'], + ['Toad in the hole', 'oven', 15, 40, 0, 0, 2, 'batter', 'hot', 'dish'], + ['Pork crackling', 'oven', 5, 25, 0, 0, 1, 'red-meat', 'hot', 'open'], + ['Cauliflower cheese', 'oven', 20, 30, 5, 0, 2, 'veg-bake', 'mid', 'dish'], + ['Dauphinoise potatoes', 'oven', 20, 75, 10, 5, 2, 'veg-bake', 'mid', 'dish'], + ['Bread rolls', 'oven', 2, 10, 0, 0, 1, 'bread', 'hot', 'open'], + ['Garlic bread', 'oven', 2, 15, 0, 0, 1, 'bread', 'hot', 'open'], + ['Salmon fillets', 'oven', 5, 20, 5, 0, 1, 'fish', 'mid', 'open'], // ── Hob ── - ['Mashed potatoes', 'boil', 15, 20, 0, 1, 'root-veg', 'mid', 'open'], - ['Boiled potatoes', 'boil', 10, 20, 0, 1, 'root-veg', 'mid', 'open'], - ['Brussels sprouts', 'boil', 10, 8, 0, 1, 'brassica', 'mid', 'open'], - ['Carrots', 'boil', 5, 15, 0, 1, 'root-veg', 'mid', 'open'], - ['Green beans', 'boil', 3, 6, 0, 1, 'brassica', 'mid', 'open'], - ['Garden peas', 'boil', 2, 5, 0, 1, 'brassica', 'mid', 'open'], - ['Cauliflower', 'boil', 5, 10, 0, 1, 'brassica', 'mid', 'open'], - ['Broccoli', 'boil', 3, 6, 0, 1, 'brassica', 'mid', 'open'], - ['Red cabbage', 'pan', 10, 45, 0, 1, 'brassica', 'mid', 'dish'], - ['Gravy', 'pan', 5, 15, 0, 1, 'sauce', 'mid', 'dish'], - ['Bread sauce', 'pan', 5, 15, 0, 1, 'sauce', 'mid', 'dish'], - ['Cranberry sauce', 'pan', 5, 10, 0, 1, 'sauce', 'mid', 'dish'], + ['Mashed potatoes', 'boil', 15, 20, 0, 0, 1, 'root-veg', 'mid', 'open'], + ['Boiled potatoes', 'boil', 10, 20, 0, 0, 1, 'root-veg', 'mid', 'open'], + ['Brussels sprouts', 'boil', 10, 8, 0, 0, 1, 'brassica', 'mid', 'open'], + ['Carrots', 'boil', 5, 15, 0, 0, 1, 'root-veg', 'mid', 'open'], + ['Green beans', 'boil', 3, 6, 0, 0, 1, 'brassica', 'mid', 'open'], + ['Garden peas', 'boil', 2, 5, 0, 0, 1, 'brassica', 'mid', 'open'], + ['Cauliflower', 'boil', 5, 10, 0, 0, 1, 'brassica', 'mid', 'open'], + ['Broccoli', 'boil', 3, 6, 0, 0, 1, 'brassica', 'mid', 'open'], + ['Red cabbage', 'pan', 10, 45, 0, 0, 1, 'brassica', 'mid', 'dish'], + ['Gravy', 'pan', 5, 15, 0, 0, 1, 'sauce', 'mid', 'dish'], + ['Bread sauce', 'pan', 5, 15, 0, 0, 1, 'sauce', 'mid', 'dish'], + ['Cranberry sauce', 'pan', 5, 10, 0, 0, 1, 'sauce', 'mid', 'dish'], // ── Pudding ── - ['Apple crumble', 'oven', 20, 40, 10, 2, 'dessert', 'mid', 'dish'], - ['Apple pie', 'oven', 15, 45, 10, 2, 'dessert', 'mid', 'dish'], - ['Christmas pudding', 'boil', 5, 120, 0, 1, 'dessert', 'mid', 'dish'], - ['Mince pies', 'oven', 2, 18, 0, 1, 'dessert', 'mid', 'open'], + ['Apple crumble', 'oven', 20, 40, 10, 0, 2, 'dessert', 'mid', 'dish'], + ['Apple pie', 'oven', 15, 45, 10, 5, 2, 'dessert', 'mid', 'dish'], + ['Christmas pudding', 'boil', 5, 120, 0, 5, 1, 'dessert', 'mid', 'dish'], + ['Mince pies', 'oven', 2, 18, 0, 0, 1, 'dessert', 'mid', 'open'], ]; export const FOODS = RAW.map( - ([name, cookType, prepTime, cookTime, setTime, shelfSlots, family, heat, tray]) => ({ - name, cookType, prepTime, cookTime, setTime, shelfSlots, family, heat, tray, + ([name, cookType, prepTime, cookTime, setTime, servePrep, shelfSlots, family, heat, tray]) => ({ + name, cookType, prepTime, cookTime, setTime, servePrep, shelfSlots, family, heat, tray, }) ); diff --git a/cook-plan/item-modal.js b/cook-plan/item-modal.js index 4ed0b91..9a95220 100644 --- a/cook-plan/item-modal.js +++ b/cook-plan/item-modal.js @@ -115,14 +115,28 @@ export function openItemModal(editId) {
-
- -
- - min +
+
+ +
+ + min +
+
+
+ +
+ + min +
+

Rest is the dish sitting on its own after cooking; + serving prep is the hands-on job after that — carving, plating, saucing. + Both are counted back from the serve time, so a chicken that needs ten + minutes of carving goes in ten minutes earlier.

- +
-
${state.mode === 'end' ? 'Serving at' : 'Starting at'}
-
${state.targetTime}
+
First action
+
${firstAt != null ? formatTime(firstAt) : '--:--'}
-
Items
-
${state.items.length}
+
Serving at
+
${serveAt != null ? formatTime(serveAt) : '--:--'}
-
First action
-
${events.length > 0 ? formatTime(events[0].time) : '--:--'}
+
Start to table
+
${totalSpan ? formatDuration(totalSpan) : '\u2014'}
+
+
+
Items
+
${state.items.length}
diff --git a/cook-plan/schedule.js b/cook-plan/schedule.js index 414be58..88e3c2d 100644 --- a/cook-plan/schedule.js +++ b/cook-plan/schedule.js @@ -9,13 +9,18 @@ import { detectConflicts } from './conflicts.js'; import { buildEvents } from './events.js'; import { syncDayOffset } from './clock.js'; +// Everything a dish needs from first touch to being on the table. +function totalDuration(it) { + return (it.prepTime || 0) + (it.cookTime || 0) + (it.setTime || 0) + (it.servePrep || 0); +} + export function computeSchedule() { const target = parseTime(state.targetTime); if (target === null) return { items: [], conflicts: [], events: [] }; // In start mode, find the longest item so everything back-schedules to finish together const maxDuration = state.mode === 'start' - ? Math.max(...state.items.map(it => (it.prepTime || 0) + (it.cookTime || 0) + (it.setTime || 0))) + ? Math.max(...state.items.map(totalDuration)) : 0; const startModeFinish = target + maxDuration; @@ -25,16 +30,22 @@ export function computeSchedule() { if (item.overrideCookStart) { cookStart = parseTime(item.overrideCookStart); } else if (state.mode === 'end') { - const cookEnd = target - (item.setTime || 0); + // Back from the table: carving and plating happen last, so a dish that + // needs ten minutes of that has to be out of the oven ten minutes + // earlier than one that goes straight to the table. + const setEnd = target - (item.servePrep || 0); + const cookEnd = setEnd - (item.setTime || 0); cookStart = cookEnd - (item.cookTime || 0); } else { // start mode: stagger so all items finish together when the longest item does - cookStart = startModeFinish - (item.setTime || 0) - (item.cookTime || 0); + cookStart = startModeFinish + - (item.servePrep || 0) - (item.setTime || 0) - (item.cookTime || 0); } const prepStart = cookStart - (item.prepTime || 0); const cookEnd = cookStart + (item.cookTime || 0); const setEnd = cookEnd + (item.setTime || 0); - return { ...item, _s: { cookStart, prepStart, cookEnd, setEnd } }; + const serveEnd = setEnd + (item.servePrep || 0); + return { ...item, _s: { cookStart, prepStart, cookEnd, setEnd, serveEnd } }; }); // Optional: snap nearby start times together so the schedule rounds to natural clusters @@ -48,7 +59,7 @@ export function computeSchedule() { // must shift SERVE later — eating before something is ready makes no sense. const baseServe = state.mode === 'start' ? startModeFinish : target; const lastFinish = assigned.length > 0 - ? Math.max(...assigned.map(it => it._s.setEnd)) + ? Math.max(...assigned.map(it => it._s.serveEnd)) : baseServe; const serveTime = Math.max(baseServe, lastFinish); const events = buildEvents(assigned, serveTime); @@ -87,6 +98,7 @@ export function snapTimings(items, threshold) { prepStart: s.prepStart + shift, cookEnd: s.cookEnd + shift, setEnd: s.setEnd + shift, + serveEnd: s.serveEnd + shift, }}); } else { result.push(item); diff --git a/cook-plan/share-link.js b/cook-plan/share-link.js index 4aabb3e..9ff5daa 100644 --- a/cook-plan/share-link.js +++ b/cook-plan/share-link.js @@ -9,8 +9,8 @@ // Two layers of compression keep the hash short and readable: // 1. KEYS: every JSON key is the first letter of its property name. Where two // properties share an initial we fall back to two letters (cookType/cookTime -// → ct/co; shelfSlots/setTime → sh/se; hasCombi/hobCount → ha/ho; -// shelfPref → sp). +// → ct/co; shelfSlots/setTime/servePrep → sh/se/sv; hasCombi/hobCount → +// ha/ho; shelfPref → sp). // 2. VALUES: anything equal to its default — null, 0, the documented default // string — is omitted on encode and refilled on decode. // @@ -32,6 +32,7 @@ function compactItem(item) { if (item.prepTime) out.p = item.prepTime; if (item.cookTime) out.co = item.cookTime; if (item.setTime) out.se = item.setTime; + if (item.servePrep) out.sv = item.servePrep; if (item.overrideCookStart) out.o = item.overrideCookStart; return out; } @@ -47,6 +48,7 @@ function expandItem(c) { prepTime: c.p || 0, cookTime: c.co || 0, setTime: c.se || 0, + servePrep: c.sv || 0, overrideCookStart: c.o ?? null, }; } diff --git a/cook-plan/style.css b/cook-plan/style.css index ac97969..837f55e 100644 --- a/cook-plan/style.css +++ b/cook-plan/style.css @@ -30,6 +30,14 @@ --green: #10b981; --green-soft: #d1fae5; + /* Carving and plating: the last hands-on job, and the only step that is + neither heat nor waiting, so it gets a colour that is neither. */ + --plate: #8b5cf6; + --plate-soft: #ede9fe; + /* The running count. Not orange: the step's own label is orange, and a + figure that changes under it should read as a separate thing rather than + as part of the heading. */ + --timer: #0f766e; --danger: #ef4444; --danger-soft: #fee2e2; @@ -67,6 +75,9 @@ --text-3: #71717a; --green-soft: #022c22; + --plate: #a78bfa; + --plate-soft: #2e1065; + --timer: #2dd4bf; --danger-soft: #450a0a; --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4); @@ -717,6 +728,7 @@ button { &.notification-cook_start { --bar-colour: var(--accent); } &.notification-cook_end { --bar-colour: var(--text-3); } &.notification-set { --bar-colour: #3b82f6; } + &.notification-serve_prep { --bar-colour: var(--plate); } &.notification-ready { --bar-colour: var(--green); } &.notification-serve { --bar-colour: var(--amber); } } @@ -892,6 +904,9 @@ button { & .tl-type-set { border-left-color: #3b82f6; } + & .tl-type-serve_prep { + border-left-color: var(--plate); + } & .tl-type-ready { border-left-color: var(--green); } @@ -911,7 +926,7 @@ button { font-family: ui-monospace, monospace; font-variant-numeric: tabular-nums; font-weight: 600; - color: var(--accent); + color: var(--timer); } & .tl-tracker { @@ -969,6 +984,11 @@ button { color: #1d4ed8; border-color: #3b82f6; } + & .tl-type-serve_prep .tl-chip { + background: var(--plate-soft); + color: var(--plate); + border-color: var(--plate); + } & .tl-type-ready .tl-chip { background: var(--green-soft); color: var(--green); From 32ce7354c2e8b8c18ef8a721315a20f5cfbb9e44 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 22:18:16 +0000 Subject: [PATCH 09/14] [cook-plan] Turn the oven on before the first thing goes in it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The plan assumed an oven was at temperature the moment a dish reached it. It isn't, and "turn the oven on" is the real first instruction of a roast, so the kitchen settings now carry a heat-up time — six minutes by default — and every oven that gets used earns a HEAT step that far ahead of its first dish. One per oven, at its own first use, so a combi that only comes into play at half past gets its own step at twenty-four past rather than being warmed for two hours alongside the main one. Microwaves get none, and a hob heats while you stand over it. It is a property of the kitchen rather than of any dish, which is why it sits with the shelves and the hobs rather than in the food editor. Co-Authored-By: Claude Opus 5 --- cook-plan/appliance-settings.js | 23 +++++++++++++++++++++ cook-plan/appliances.js | 4 ++++ cook-plan/clock.js | 7 +++++-- cook-plan/constants.js | 3 ++- cook-plan/events.js | 36 +++++++++++++++++++++++++++++++++ cook-plan/share-link.js | 4 +++- cook-plan/style.css | 10 +++++++-- 7 files changed, 81 insertions(+), 6 deletions(-) diff --git a/cook-plan/appliance-settings.js b/cook-plan/appliance-settings.js index 5fdce3f..8a72af1 100644 --- a/cook-plan/appliance-settings.js +++ b/cook-plan/appliance-settings.js @@ -45,6 +45,16 @@ export function renderApplianceSettings() { ).join('')}
+
+ +
+ + min +
+

Each oven gets a "turn it on" step this long before + the first dish goes in

+
@@ -58,10 +68,23 @@ export function renderApplianceSettings() { if (!bound) { el.addEventListener('click', handleClick); + el.addEventListener('input', handleInput); bound = true; } } +// Typed settings save as they are typed; an empty box is nothing rather than +// zero, so it waits rather than wiping the value out from under the cursor. +// The schedule itself is repainted when the dialog closes, as for every other +// setting here. +function handleInput(e) { + if (e.target.id !== 'set-preheat') return; + if (e.target.value === '') return; + const mins = Math.min(120, Math.max(0, parseInt(e.target.value, 10) || 0)); + state.appliances = { ...applianceConfig(), preheatMins: mins }; + savePlan(); +} + function handleClick(e) { const btn = e.target.closest('button[data-val]'); const group = btn?.closest('[data-setting]'); diff --git a/cook-plan/appliances.js b/cook-plan/appliances.js index 53289a8..499deea 100644 --- a/cook-plan/appliances.js +++ b/cook-plan/appliances.js @@ -12,6 +12,10 @@ export function applianceConfig() { mainOvenShelves: a.mainOvenShelves ?? 2, // 1 -> 2 slots, 2 -> 4 slots hasCombi: a.hasCombi !== false, // default true hobCount: a.hobCount ?? 5, + // How long an oven takes to come up to temperature. Not a property of any + // dish -- it is the kitchen's, and it is why the first instruction of a + // roast is "turn the oven on" rather than "put the chicken in". + preheatMins: a.preheatMins ?? 6, }; } diff --git a/cook-plan/clock.js b/cook-plan/clock.js index c05c5a3..7235992 100644 --- a/cook-plan/clock.js +++ b/cook-plan/clock.js @@ -101,15 +101,17 @@ export function syncDayOffset(events) { nextDayOffset = nowMins() > last + 60 ? 1440 : 0; } +// Events without a dish of their own -- heating an oven, serve -- fall back to +// the appliance, so two ovens warming up on the same minute stay distinct. function chimeKey(ev) { - return `${ev.time}:${ev.type}:${ev.itemId || ''}`; + return `${ev.time}:${ev.type}:${ev.itemId || ev.applianceKey || ''}`; } // Which event speaks for a moment, most significant first. The end of a cook // is a dozen events on one minute -- every dish ready, several out of the oven, // and serve -- and they are one moment, not a dozen. Only the leader is // sounded, so SERVE wins over the things that merely finished with it. -const CHIME_PRIORITY = ['serve', 'cook_end', 'serve_prep', 'cook_start', 'prep', 'set', 'ready']; +const CHIME_PRIORITY = ['serve', 'cook_end', 'serve_prep', 'cook_start', 'preheat', 'prep', 'set', 'ready']; function leadEvent(evs) { for (const type of CHIME_PRIORITY) { @@ -135,6 +137,7 @@ function playChime(type) { cook_start: 523.25, // C5 -- things going in cook_end: 783.99, // G5 -- higher/urgent: things coming out set: 440.00, // A4 -- soft + preheat: 349.23, // F4 -- low: go and press a button serve_prep: 659.25, // E5 -- hands needed, but nothing is burning serve: 987.77, // B5 -- bright fanfare note }; diff --git a/cook-plan/constants.js b/cook-plan/constants.js index cc39264..d1421ec 100644 --- a/cook-plan/constants.js +++ b/cook-plan/constants.js @@ -28,6 +28,7 @@ export const EV_TYPE_CHIP = { prep: 'PREP', cook_start: 'IN', cook_end: 'OUT', + preheat: 'HEAT', set: 'REST', serve_prep: 'PLATE', ready: 'READY', @@ -39,7 +40,7 @@ export const DEFAULT_STATE = { mode: 'end', // 'start' | 'end' targetTime: '17:00', items: [], - appliances: { mainOvenShelves: 2, hasCombi: true, hobCount: 5 }, + appliances: { mainOvenShelves: 2, hasCombi: true, hobCount: 5, preheatMins: 6 }, snapMins: 0, }; diff --git a/cook-plan/events.js b/cook-plan/events.js index 804c9f6..7ce1872 100644 --- a/cook-plan/events.js +++ b/cook-plan/events.js @@ -4,6 +4,7 @@ import { COOK_TYPE_MAP } from './constants.js'; import { formatDuration } from './utils.js'; +import { applianceConfig } from './appliances.js'; export function buildEvents(items, serveTime) { const events = []; @@ -135,6 +136,8 @@ export function buildEvents(items, serveTime) { itemId: null, }); + events.push(...preheatEvents(items, applianceConfig().preheatMins)); + // Sort; serve goes last if same time events.sort((a, b) => a.time - b.time || (a.type === 'serve' ? 1 : b.type === 'serve' ? -1 : 0)); @@ -142,6 +145,39 @@ export function buildEvents(items, serveTime) { return events; } +// An oven does not start hot. Each one that gets used needs turning on before +// the first dish goes into it, which is a job for the cook and so a stop on the +// timeline -- one per oven, at its own first use. A microwave needs none, and a +// hob heats while you stand over it. +function preheatEvents(items, preheatMins) { + if (!(preheatMins > 0)) return []; + + const firstUse = new Map(); + for (const item of items) { + if (!(item.cookTime > 0)) continue; + if (COOK_TYPE_MAP[item.cookType]?.resource !== 'oven') continue; + const key = item._appliance; + if (key !== 'main' && key !== 'combi') continue; + const at = item._s.cookStart; + if (!firstUse.has(key) || at < firstUse.get(key)) firstUse.set(key, at); + } + + return [...firstUse].map(([key, at]) => { + const label = applianceLabel(key, null); + return { + time: at - preheatMins, + endTime: at, + type: 'preheat', + label: `Heat ${label}`, + sub: formatDuration(preheatMins), + itemId: null, + itemName: null, + applianceKey: `preheat-${key}`, + applianceLabel: label, + }; + }); +} + export function joinNames(names) { if (names.length === 1) return names[0]; return names.slice(0, -1).join(', ') + ' & ' + names[names.length - 1]; diff --git a/cook-plan/share-link.js b/cook-plan/share-link.js index 9ff5daa..9bd7891 100644 --- a/cook-plan/share-link.js +++ b/cook-plan/share-link.js @@ -19,7 +19,7 @@ // and the form is human-readable. Two legacy base64 formats are still decoded. // ============================================= -const APP_DEFAULTS = { mainOvenShelves: 2, hasCombi: true, hobCount: 5 }; +const APP_DEFAULTS = { mainOvenShelves: 2, hasCombi: true, hobCount: 5, preheatMins: 6 }; // ---- v2 compact (current) --------------------------------------------------- @@ -65,6 +65,7 @@ function compactState(s) { if (a.mainOvenShelves !== APP_DEFAULTS.mainOvenShelves) ac.m = a.mainOvenShelves; if (a.hasCombi !== APP_DEFAULTS.hasCombi) ac.ha = a.hasCombi; if (a.hobCount !== APP_DEFAULTS.hobCount) ac.ho = a.hobCount; + if ((a.preheatMins ?? APP_DEFAULTS.preheatMins) !== APP_DEFAULTS.preheatMins) ac.ph = a.preheatMins; if (Object.keys(ac).length) c.a = ac; c.i = (s.items || []).map(compactItem); @@ -81,6 +82,7 @@ function expandState(c) { mainOvenShelves: c.a?.m ?? APP_DEFAULTS.mainOvenShelves, hasCombi: c.a?.ha ?? APP_DEFAULTS.hasCombi, hobCount: c.a?.ho ?? APP_DEFAULTS.hobCount, + preheatMins: c.a?.ph ?? APP_DEFAULTS.preheatMins, }, items: (c.i || []).map(expandItem), }; diff --git a/cook-plan/style.css b/cook-plan/style.css index 837f55e..ec483b4 100644 --- a/cook-plan/style.css +++ b/cook-plan/style.css @@ -725,6 +725,7 @@ button { /* Per-type accent matches the timeline chip colours */ &.notification-prep { --bar-colour: var(--amber); } + &.notification-preheat { --bar-colour: var(--amber); } &.notification-cook_start { --bar-colour: var(--accent); } &.notification-cook_end { --bar-colour: var(--text-3); } &.notification-set { --bar-colour: #3b82f6; } @@ -892,7 +893,11 @@ button { } /* Per-type left border colours */ - & .tl-type-prep { + /* Heating an oven and prepping a dish are the same kind of thing -- a job + to do before anything cooks -- so they share a colour and differ by + their chip. */ + & .tl-type-prep, + & .tl-type-preheat { border-left-color: var(--amber); } & .tl-type-cook_start { @@ -969,7 +974,8 @@ button { border: 1px solid var(--border); } - & .tl-type-prep .tl-chip { + & .tl-type-prep .tl-chip, + & .tl-type-preheat .tl-chip { background: var(--amber-soft); color: var(--amber); border-color: var(--amber); From a7c786b887abbf77a335b8301cd2931f9fa07b0c Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Sun, 22 Nov 2026 22:23:49 +0000 Subject: [PATCH 10/14] [cook-plan] Move a dish between ovens rather than just complaining MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Move a dish to the main oven" was advice the planner had no business giving: it had not checked whether there was anywhere to move one, and if there was, it should have done it rather than leaving the cook to work it out. A dish is usually in the combi only because the main oven was full when it went in. Shelves come free as things come out, so it can often move across partway through, carry on cooking in the main oven, and leave the combi empty and cooling in time to microwave something. The planner now looks for that: at each moment something changes — a dish going in, a shelf coming free — it asks whether the main oven could hold everything that is in the combi's way, all at once, for the rest of their cooking. The earliest moment that works wins, and the move becomes a step on the timeline with its own chime: "Move Parsnips → Main Oven · Shelf 1 · frees the combi for Red cabbage". A dish is therefore in two places over its cook, so the capacity sweeps and the appliance summary now work in windows rather than whole cooks — otherwise the main oven would be overfilled by a dish it was never told about. A combi chosen by hand is never moved: undoing an override to make room is the planner overruling the cook, which is the wrong way round. And when no move fits, the message says so — "the main oven is full for that stretch, so there is nothing to move" — rather than suggesting one that doesn't exist. Also: a microwave dish in a kitchen with no combi had nowhere to cook and nothing said so, despite a comment promising it would. Co-Authored-By: Claude Opus 5 --- cook-plan/appliances.js | 91 ++++++++++++++++++++++++++++++++++++ cook-plan/clock.js | 3 +- cook-plan/conflicts.js | 74 ++++++++++++++++++++--------- cook-plan/constants.js | 1 + cook-plan/events.js | 17 +++++++ cook-plan/render-schedule.js | 51 +++++++++++++------- cook-plan/style.css | 8 +++- 7 files changed, 204 insertions(+), 41 deletions(-) diff --git a/cook-plan/appliances.js b/cook-plan/appliances.js index 499deea..bd4ee4d 100644 --- a/cook-plan/appliances.js +++ b/cook-plan/appliances.js @@ -168,6 +168,7 @@ export function assignAppliances(items) { const ct = COOK_TYPE_MAP[item.cookType]; const food = lookupFood(item.name); item._trayMates = []; + item._moveTo = null; if (!ct) { item._appliance = null; continue; } if (ct.resource === 'none') { @@ -283,10 +284,100 @@ export function assignAppliances(items) { } } + // A microwave dish that still has no slot may be rescuable: see if what is + // in the combi can move to the main oven partway through and let it in. + const byId = new Map(sorted.map(it => [it.id, it])); + for (const mw of order) { + if (COOK_TYPE_MAP[mw.cookType]?.resource !== 'combi') continue; + if (!(mw.cookTime > 0) || !cfg.hasCombi) continue; + if (combiUsage.some(u => u.itemId === mw.id && u.mode === 'microwave')) continue; + mw._relocation = tryRelocate(mw) ? 'done' : 'impossible'; + } + annotateTrayMates(sorted, mainOvenUsage); annotateTrayMates(sorted, combiUsage); return sorted; + + // Freeing the combi by moving what is in it. + // + // A dish is often in the combi only because the main oven was full when it + // went in. Shelves come free as things come out, so it can frequently move + // across partway through and carry on cooking in the main oven, which leaves + // the combi empty and cooling in time to microwave something. That is a real + // job for the cook, so it is only proposed when it genuinely fits: every + // dish in the way has to be out before the cooldown starts, and the main + // oven has to hold all of them, at once, for the rest of their cooking. + function tryRelocate(mw) { + const { cookStart: mwStart, cookEnd: mwEnd } = mw._s; + const freeBy = mwStart - COMBI_COOLDOWN; + + const blockers = combiUsage.filter(u => + u.mode === 'oven' && u.start < mwEnd && u.end + COMBI_COOLDOWN > mwStart + ); + if (blockers.length === 0) return false; + // A combi chosen by hand stays chosen. Undoing an override to make room is + // the planner overruling the cook, which is the wrong way round. + if (blockers.some(u => byId.get(u.itemId)?.appliancePref === 'combi')) return false; + + // The only moments worth trying are when something changes: a dish going + // in, or a main-oven shelf coming free. + const candidates = [...new Set([ + ...blockers.map(b => b.start), + ...mainOvenUsage.map(u => u.end), + freeBy, + ])].filter(t => t <= freeBy).sort((a, b) => a - b); + + for (const at of candidates) { + const moves = planMoves(blockers, at); + if (moves) { applyMoves(moves, mw); return true; } + } + return false; + } + + // Can the main oven take every dish in the way, from `at` onwards, all at + // the same time? Longest remaining cook first: the awkward one to place + // should pick its shelf before the easy ones fill them. + function planMoves(blockers, at) { + const trial = [...mainOvenUsage]; + const moves = []; + const hardestFirst = [...blockers].sort((a, b) => + (b.end - Math.max(b.start, at)) - (a.end - Math.max(a.start, at))); + + for (const b of hardestFirst) { + const start = Math.max(b.start, at); + if (start >= b.end) continue; // finished before the move: nothing to do + let shelf = null; + for (let n = 1; n <= cfg.mainOvenShelves; n++) { + if (slotsOnShelf(trial, n, start, b.end, b.itemId) + b.slots <= 2) { shelf = n; break; } + } + if (shelf === null) return null; + trial.push({ start, end: b.end, shelf, slots: b.slots, itemId: b.itemId, food: b.food }); + moves.push({ usage: b, at: start, shelf }); + } + return moves.length > 0 ? moves : null; + } + + function applyMoves(moves, mw) { + for (const { usage, at, shelf } of moves) { + const item = byId.get(usage.itemId); + mainOvenUsage.push({ ...usage, start: at, shelf }); + if (at <= usage.start) { + // It never goes near the combi after all: a reassignment, not a move. + combiUsage.splice(combiUsage.indexOf(usage), 1); + if (item) { item._appliance = 'main'; item._shelf = shelf; } + } else { + usage.end = at; // the combi half of its cook + if (item) item._moveTo = { shelf, at, forItem: mw.name }; + } + } + combiUsage.push({ + start: mw._s.cookStart, end: mw._s.cookEnd, mode: 'microwave', + shelf: 1, slots: 1, itemId: mw.id, food: lookupFood(mw.name), + }); + mw._appliance = 'combi-mw'; + mw._shelf = 1; + } } // Note, on each dish, which of its shelf-mates it could genuinely go in one diff --git a/cook-plan/clock.js b/cook-plan/clock.js index 7235992..a9fdc26 100644 --- a/cook-plan/clock.js +++ b/cook-plan/clock.js @@ -111,7 +111,7 @@ function chimeKey(ev) { // is a dozen events on one minute -- every dish ready, several out of the oven, // and serve -- and they are one moment, not a dozen. Only the leader is // sounded, so SERVE wins over the things that merely finished with it. -const CHIME_PRIORITY = ['serve', 'cook_end', 'serve_prep', 'cook_start', 'preheat', 'prep', 'set', 'ready']; +const CHIME_PRIORITY = ['serve', 'move', 'cook_end', 'serve_prep', 'cook_start', 'preheat', 'prep', 'set', 'ready']; function leadEvent(evs) { for (const type of CHIME_PRIORITY) { @@ -137,6 +137,7 @@ function playChime(type) { cook_start: 523.25, // C5 -- things going in cook_end: 783.99, // G5 -- higher/urgent: things coming out set: 440.00, // A4 -- soft + move: 880.00, // A5 -- urgent: an oven door has to open now preheat: 349.23, // F4 -- low: go and press a button serve_prep: 659.25, // E5 -- hands needed, but nothing is burning serve: 987.77, // B5 -- bright fanfare note diff --git a/cook-plan/conflicts.js b/cook-plan/conflicts.js index ec6d1d4..3cef4c6 100644 --- a/cook-plan/conflicts.js +++ b/cook-plan/conflicts.js @@ -37,19 +37,25 @@ export function detectConflicts(items) { function checkOvenConflicts() { const cfg = applianceConfig(); const maxSlots = cfg.mainOvenShelves * 2; - const ovenItems = items.filter(i => - COOK_TYPE_MAP[i.cookType]?.resource === 'oven' && i._appliance === 'main' && i.cookTime > 0 - ); + // What is in the main oven, and when. A dish that moves across from the + // combi partway through its cook is in here only from the move onwards, so + // it is that stretch that gets swept rather than the whole cook. + const mainUsage = []; + for (const i of items) { + if (COOK_TYPE_MAP[i.cookType]?.resource !== 'oven' || !(i.cookTime > 0)) continue; + const slots = i.shelfSlots || 1; + if (i._appliance === 'main') { + mainUsage.push({ start: i._s.cookStart, end: i._s.cookEnd, shelf: i._shelf ?? 1, slots, itemId: i.id }); + } else if (i._appliance === 'combi' && i._moveTo) { + mainUsage.push({ start: i._moveTo.at, end: i._s.cookEnd, shelf: i._moveTo.shelf, slots, itemId: i.id }); + } + } const describe = (id) => { - const it = ovenItems.find(i => i.id === id); + const it = items.find(i => i.id === id); return it ? `"${it.name}" (${it.shelfSlots||1} slot${(it.shelfSlots||1)>1?'s':''})` : id; }; - const toUsage = (arr) => arr.map(i => ({ - start: i._s.cookStart, end: i._s.cookEnd, - slots: i.shelfSlots || 1, itemId: i.id, - })); - const over = sweepConflicts(toUsage(ovenItems), maxSlots); + const over = sweepConflicts(mainUsage, maxSlots); const seen = new Set(); for (const { time, slots, itemIds } of over) { const key = [...itemIds].sort().join(','); @@ -68,9 +74,9 @@ export function detectConflicts(items) { // nowhere left to put something. Neither shows up in the total above. const shelfSeen = new Set(); for (let shelf = 1; shelf <= cfg.mainOvenShelves; shelf++) { - const onShelf = ovenItems.filter(i => (i._shelf ?? 1) === shelf); + const onShelf = mainUsage.filter(u => u.shelf === shelf); if (onShelf.length < 2) continue; - for (const { time, slots, itemIds } of sweepConflicts(toUsage(onShelf), 2)) { + for (const { time, slots, itemIds } of sweepConflicts(onShelf, 2)) { const key = shelf + ':' + [...itemIds].sort().join(','); if (shelfSeen.has(key)) continue; shelfSeen.add(key); @@ -84,17 +90,35 @@ export function detectConflicts(items) { } function checkCombiConflicts() { + const cfg = applianceConfig(); const combiItems = items.filter(i => (i._appliance === 'combi' || i._appliance === 'combi-mw') && i.cookTime > 0 ); const ovenItems = combiItems.filter(i => i._appliance === 'combi'); const mwItems = combiItems.filter(i => i._appliance === 'combi-mw'); + // The combi is the only microwave in the model, so without one these + // dishes have nowhere at all to cook -- not a clash, an absence. + if (!cfg.hasCombi && mwItems.length > 0) { + conflicts.push({ + type: 'combi-capacity', + message: `There is no combi or microwave in the kitchen, so ` + + `${names(mwItems)} ${mwItems.length > 1 ? 'have' : 'has'} nowhere to cook. ` + + `Change the cook type, or turn the combi on in Settings.`, + itemIds: mwItems.map(i => i.id), + }); + return; + } + + // A dish that moves out to the main oven partway through holds the combi + // only up to the move. + const combiEnd = (i) => i._moveTo ? i._moveTo.at : i._s.cookEnd; + // Oven mode: 2-slot capacity const ovenUsage = ovenItems.map(i => ({ - start: i._s.cookStart, end: i._s.cookEnd, + start: i._s.cookStart, end: combiEnd(i), slots: i.shelfSlots || 1, itemId: i.id, - })); + })).filter(u => u.end > u.start); const ovenOver = sweepConflicts(ovenUsage, 2); const seen = new Set(); for (const { time, slots, itemIds } of ovenOver) { @@ -131,29 +155,35 @@ export function detectConflicts(items) { // is what is tying it up and that something has to give. for (const mw of mwItems) { const overlapping = ovenItems.filter(o => - o._s.cookStart < mw._s.cookEnd && o._s.cookEnd > mw._s.cookStart + o._s.cookStart < mw._s.cookEnd && combiEnd(o) > mw._s.cookStart ); const tooSoon = ovenItems.filter(o => - o._s.cookEnd <= mw._s.cookStart - && mw._s.cookStart - o._s.cookEnd < COMBI_COOLDOWN + combiEnd(o) <= mw._s.cookStart + && mw._s.cookStart - combiEnd(o) < COMBI_COOLDOWN ); + // The planner has already tried to move what is in the way; saying so + // stops the advice being "move a dish" when there is nowhere to move it. + const nowhere = mw._relocation === 'impossible' + ? ` The main oven is full for that stretch, so there is nothing to move.` + : ''; + if (overlapping.length > 0) { - const until = formatTime(Math.max(...overlapping.map(o => o._s.cookEnd))); + const until = formatTime(Math.max(...overlapping.map(combiEnd))); conflicts.push({ type: 'combi-mode', message: `Combi is in use as an oven until ${until} (${names(overlapping)}), ` - + `so it can't microwave "${mw.name}" at ${formatTime(mw._s.cookStart)}. ` - + `Move a dish to the main oven, or cook "${mw.name}" another way.`, + + `so it can't microwave "${mw.name}" at ${formatTime(mw._s.cookStart)}.` + + `${nowhere} Cook "${mw.name}" another way, or make room in the main oven.`, itemIds: [mw.id, ...overlapping.map(o => o.id)], }); } else if (tooSoon.length > 0) { - const last = tooSoon.reduce((a, b) => (b._s.cookEnd > a._s.cookEnd ? b : a)); - const gap = mw._s.cookStart - last._s.cookEnd; + const last = tooSoon.reduce((a, b) => (combiEnd(b) > combiEnd(a) ? b : a)); + const gap = mw._s.cookStart - combiEnd(last); conflicts.push({ type: 'combi-cooldown', message: `Combi needs ${COMBI_COOLDOWN}m to cool down before it will microwave. ` - + `"${last.name}" comes out at ${formatTime(last._s.cookEnd)} and ` + + `"${last.name}" comes out at ${formatTime(combiEnd(last))} and ` + `"${mw.name}" wants it at ${formatTime(mw._s.cookStart)} \u2014 only ${gap}m gap.`, itemIds: [mw.id, last.id], }); diff --git a/cook-plan/constants.js b/cook-plan/constants.js index d1421ec..49a3d96 100644 --- a/cook-plan/constants.js +++ b/cook-plan/constants.js @@ -29,6 +29,7 @@ export const EV_TYPE_CHIP = { cook_start: 'IN', cook_end: 'OUT', preheat: 'HEAT', + move: 'MOVE', set: 'REST', serve_prep: 'PLATE', ready: 'READY', diff --git a/cook-plan/events.js b/cook-plan/events.js index 7ce1872..e6efa0f 100644 --- a/cook-plan/events.js +++ b/cook-plan/events.js @@ -80,6 +80,23 @@ export function buildEvents(items, serveTime) { }); } + // Started in the combi, finishes in the main oven. A real job with a time + // of its own, and the only reason the microwave gets its slot. + if (item._moveTo) { + events.push({ + time: item._moveTo.at, + endTime: item._moveTo.at, + type: 'move', + label: `Move ${item.name} \u2192 Main Oven`, + sub: `Shelf ${item._moveTo.shelf} \u00b7 frees the combi for ${item._moveTo.forItem}`, + itemId: item.id, + itemName: item.name, + // Each move is its own instruction: two dishes going to different + // shelves is two jobs, not one line with a shelf missing from it. + applianceKey: `move-${item.id}`, + }); + } + if (item.setTime > 0) { events.push({ time: cookEnd, diff --git a/cook-plan/render-schedule.js b/cook-plan/render-schedule.js index 0c59c3d..1d01da7 100644 --- a/cook-plan/render-schedule.js +++ b/cook-plan/render-schedule.js @@ -324,19 +324,37 @@ function editFields(ev, item, cfg) { export function renderApplianceSummary(items) { const cfg = applianceConfig(); const nextDayOffset = getNextDayOffset(); - const ovenItems = items.filter(i => i._appliance === 'main'); - const combiItems = items.filter(i => i._appliance === 'combi' || i._appliance === 'combi-mw'); - const hobItems = items.filter(i => i._appliance?.startsWith('hob')); + const hobItems = items.filter(i => i._appliance?.startsWith('hob')); + + // A dish that moves between ovens belongs to both cards, for the stretch it + // actually spends in each. Everything else is one window covering its cook. + const mainWindows = []; + const combiWindows = []; + for (const i of items) { + if (i._appliance === 'main') { + mainWindows.push({ item: i, shelf: i._shelf, start: i._s.cookStart, end: i._s.cookEnd }); + } else if (i._appliance === 'combi' || i._appliance === 'combi-mw') { + combiWindows.push({ + item: i, start: i._s.cookStart, end: i._moveTo ? i._moveTo.at : i._s.cookEnd, + mode: i._appliance === 'combi' ? 'oven' : 'MW', + }); + if (i._moveTo) { + mainWindows.push({ + item: i, shelf: i._moveTo.shelf, start: i._moveTo.at, end: i._s.cookEnd, moved: true, + }); + } + } + } // Current slot usage at nowMins const now = nowMins() - nextDayOffset; - function usedSlots(arr) { - return arr.filter(i => i._s.cookStart <= now && i._s.cookEnd > now) - .reduce((s, i) => s + (i.shelfSlots || 1), 0); + function usedSlots(wins) { + return wins.filter(w => w.start <= now && w.end > now) + .reduce((s, w) => s + (w.item.shelfSlots || 1), 0); } - const mainUsed = usedSlots(ovenItems); - const combiUsed = usedSlots(combiItems); + const mainUsed = usedSlots(mainWindows); + const combiUsed = usedSlots(combiWindows); function slotBar(used, total) { let html = `
`; @@ -348,10 +366,11 @@ export function renderApplianceSummary(items) { // Shelf is called out here too, so a hand-picked one is verifiable at a // glance; a pin marks the ones the cook chose rather than the planner. - function ovenLine(i) { - const shelf = cfg.mainOvenShelves > 1 && i._shelf - ? `Shelf ${i._shelf}${i._shelfPinned ? ' 📌' : ''} · ` : ''; - return `${escHtml(i.name)}: ${shelf}${formatTime(i._s.cookStart)}–${formatTime(i._s.cookEnd)}`; + function ovenLine(w) { + const shelf = cfg.mainOvenShelves > 1 && w.shelf + ? `Shelf ${w.shelf}${w.item._shelfPinned ? ' 📌' : ''} · ` : ''; + const moved = w.moved ? ' · moved in' : ''; + return `${escHtml(w.item.name)}: ${shelf}${formatTime(w.start)}–${formatTime(w.end)}${moved}`; } return ` @@ -363,8 +382,8 @@ export function renderApplianceSummary(items) {
${cfg.mainOvenShelves * 2} slots (${cfg.mainOvenShelves} shelf${cfg.mainOvenShelves > 1 ? ' × 2' : ''})
${slotBar(mainUsed, cfg.mainOvenShelves * 2)}
- ${ovenItems.length === 0 ? 'Nothing scheduled' : - ovenItems.map(ovenLine).join('')} + ${mainWindows.length === 0 ? 'Nothing scheduled' : + mainWindows.map(ovenLine).join('')}
${cfg.hasCombi ? ` @@ -373,8 +392,8 @@ export function renderApplianceSummary(items) {
2 slots (1 shelf), oven or MW
${slotBar(combiUsed, 2)}
- ${combiItems.length === 0 ? 'Nothing scheduled' : - combiItems.map(i => `${escHtml(i.name)} (${i._appliance === 'combi' ? 'oven' : 'MW'}): ${formatTime(i._s.cookStart)}–${formatTime(i._s.cookEnd)}`).join('')} + ${combiWindows.length === 0 ? 'Nothing scheduled' : + combiWindows.map(w => `${escHtml(w.item.name)} (${w.mode}): ${formatTime(w.start)}–${formatTime(w.end)}${w.item._moveTo ? ' · then main oven' : ''}`).join('')}
` : ''}
diff --git a/cook-plan/style.css b/cook-plan/style.css index ec483b4..66e250e 100644 --- a/cook-plan/style.css +++ b/cook-plan/style.css @@ -727,6 +727,7 @@ button { &.notification-prep { --bar-colour: var(--amber); } &.notification-preheat { --bar-colour: var(--amber); } &.notification-cook_start { --bar-colour: var(--accent); } + &.notification-move { --bar-colour: var(--accent); } &.notification-cook_end { --bar-colour: var(--text-3); } &.notification-set { --bar-colour: #3b82f6; } &.notification-serve_prep { --bar-colour: var(--plate); } @@ -900,7 +901,9 @@ button { & .tl-type-preheat { border-left-color: var(--amber); } - & .tl-type-cook_start { + /* Moving a dish between ovens is an oven job like putting one in. */ + & .tl-type-cook_start, + & .tl-type-move { border-left-color: var(--accent); } & .tl-type-cook_end { @@ -980,7 +983,8 @@ button { color: var(--amber); border-color: var(--amber); } - & .tl-type-cook_start .tl-chip { + & .tl-type-cook_start .tl-chip, + & .tl-type-move .tl-chip { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); From 183ea164699693de012f31f4c5e3abbfc1fc682d Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Mon, 23 Nov 2026 09:00:53 +0000 Subject: [PATCH 11/14] [cook-plan] Let a dish finish early and sit covered, where that unblocks the plan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Back-scheduling pinned every cook to the serve time. That is right for anything that suffers from standing and needlessly rigid for a tray of roast veg: finished a few minutes early and covered, it is no worse off, and those few minutes can be exactly what lets the combi stop being an oven in time to be a microwave. So the kitchen gains a keep-warm allowance — fifteen minutes by default — and when a microwave dish is stuck, the planner works out how much earlier what is in the way would have to finish, and holds it back if that is within the allowance. All or nothing per clash: emptying the combi half way empties nothing. Only when there is a clash to clear, too, since food should not be made to wait for nothing. On the plan this came from, nine minutes is enough. The parsnips and the pigs in blankets now come out at 15:41 with "Cover and set aside · 9m until serve" against them, the cauliflower cheese moves to the main oven when the chicken leaves it, and the red cabbage gets the microwave it has been asking for since this all started. No conflicts. Shifting a dish re-opens every allocation decision after it, so the held plan is only kept when it has fewer conflicts than the unheld one — a hold that trades one clash for another is not worth anyone's parsnips going cold. A hand-set start outranks a hold, as it outranks everything else. Co-Authored-By: Claude Opus 5 --- cook-plan/appliance-settings.js | 18 +++++++++-- cook-plan/appliances.js | 4 +++ cook-plan/constants.js | 4 ++- cook-plan/events.js | 6 +++- cook-plan/schedule.js | 57 ++++++++++++++++++++++++++++++--- cook-plan/share-link.js | 6 +++- 6 files changed, 85 insertions(+), 10 deletions(-) diff --git a/cook-plan/appliance-settings.js b/cook-plan/appliance-settings.js index 8a72af1..e84c358 100644 --- a/cook-plan/appliance-settings.js +++ b/cook-plan/appliance-settings.js @@ -55,6 +55,16 @@ export function renderApplianceSettings() {

Each oven gets a "turn it on" step this long before the first dish goes in

+
+ +
+ + min +
+

How long a dish may finish early and sit covered, when + that is what frees an appliance for something else

+
@@ -77,11 +87,13 @@ export function renderApplianceSettings() { // zero, so it waits rather than wiping the value out from under the cursor. // The schedule itself is repainted when the dialog closes, as for every other // setting here. +const TIME_SETTINGS = { 'set-preheat': 'preheatMins', 'set-hold': 'holdMins' }; + function handleInput(e) { - if (e.target.id !== 'set-preheat') return; - if (e.target.value === '') return; + const key = TIME_SETTINGS[e.target.id]; + if (!key || e.target.value === '') return; const mins = Math.min(120, Math.max(0, parseInt(e.target.value, 10) || 0)); - state.appliances = { ...applianceConfig(), preheatMins: mins }; + state.appliances = { ...applianceConfig(), [key]: mins }; savePlan(); } diff --git a/cook-plan/appliances.js b/cook-plan/appliances.js index bd4ee4d..d057f48 100644 --- a/cook-plan/appliances.js +++ b/cook-plan/appliances.js @@ -16,6 +16,10 @@ export function applianceConfig() { // dish -- it is the kitchen's, and it is why the first instruction of a // roast is "turn the oven on" rather than "put the chicken in". preheatMins: a.preheatMins ?? 6, + // How long a dish may be finished early and left covered, when that is + // what frees an appliance. Also the kitchen's, not the dish's: it is + // really a statement about how tolerant this cook is of food standing. + holdMins: a.holdMins ?? 15, }; } diff --git a/cook-plan/constants.js b/cook-plan/constants.js index 49a3d96..48ab424 100644 --- a/cook-plan/constants.js +++ b/cook-plan/constants.js @@ -41,7 +41,9 @@ export const DEFAULT_STATE = { mode: 'end', // 'start' | 'end' targetTime: '17:00', items: [], - appliances: { mainOvenShelves: 2, hasCombi: true, hobCount: 5, preheatMins: 6 }, + appliances: { + mainOvenShelves: 2, hasCombi: true, hobCount: 5, preheatMins: 6, holdMins: 15, + }, snapMins: 0, }; diff --git a/cook-plan/events.js b/cook-plan/events.js index e6efa0f..985c308 100644 --- a/cook-plan/events.js +++ b/cook-plan/events.js @@ -130,7 +130,11 @@ export function buildEvents(items, serveTime) { endTime: serveEnd, type: 'ready', label: `${item.name} ready`, - sub: null, + // A dish finished early to free an appliance needs covering, or the + // minutes it saved the plan cost it its heat. + sub: item._holdFor > 0 && serveEnd < serveTime + ? `Cover and set aside \u00b7 ${formatDuration(serveTime - serveEnd)} until serve` + : null, itemId: item.id, itemName: item.name, applianceKey: 'ready', diff --git a/cook-plan/schedule.js b/cook-plan/schedule.js index 88e3c2d..0951c1e 100644 --- a/cook-plan/schedule.js +++ b/cook-plan/schedule.js @@ -4,7 +4,8 @@ import { state } from './state.js'; import { parseTime } from './utils.js'; -import { assignAppliances } from './appliances.js'; +import { COMBI_COOLDOWN } from './constants.js'; +import { assignAppliances, applianceConfig } from './appliances.js'; import { detectConflicts } from './conflicts.js'; import { buildEvents } from './events.js'; import { syncDayOffset } from './clock.js'; @@ -15,6 +16,52 @@ function totalDuration(it) { } export function computeSchedule() { + const plain = buildSchedule(new Map()); + + // A dish that can wait, waiting. Back-scheduling pins every cook to the + // serve time, which is right for anything that suffers from standing and + // needlessly rigid for a tray of roast veg: finished a few minutes early and + // covered, it is no worse off, and those few minutes can be exactly what + // lets the combi stop being an oven in time to be a microwave. + const holds = planHolds(plain, applianceConfig().holdMins); + if (holds.size === 0) return plain; + + // Shifting a dish re-opens every allocation decision after it, so the new + // plan is only kept if it is genuinely better. Trading one clash for another + // is not worth making anybody's parsnips wait. + const held = buildSchedule(holds); + return held.conflicts.length < plain.conflicts.length ? held : plain; +} + +// How much earlier each dish would have to finish to free the combi, where +// that is the only thing standing between a microwave dish and its slot. +// All or nothing per clash: emptying the combi half way empties nothing. +function planHolds(plan, allowance) { + const holds = new Map(); + if (!(allowance > 0)) return holds; + + for (const mw of plan.items) { + if (mw._relocation !== 'impossible') continue; + const freeBy = mw._s.cookStart - COMBI_COOLDOWN; + + const blockers = plan.items.filter(i => + i._appliance === 'combi' && i.cookTime > 0 && !i.overrideCookStart + && i._s.cookStart < mw._s.cookEnd + && i._s.cookEnd + COMBI_COOLDOWN > mw._s.cookStart + ); + if (blockers.length === 0) continue; + + const needed = blockers.map(b => b._s.cookEnd - freeBy); + if (needed.some(n => n > allowance)) continue; + + blockers.forEach((b, n) => { + if (needed[n] > 0) holds.set(b.id, Math.max(holds.get(b.id) || 0, needed[n])); + }); + } + return holds; +} + +function buildSchedule(holds) { const target = parseTime(state.targetTime); if (target === null) return { items: [], conflicts: [], events: [] }; @@ -27,25 +74,27 @@ export function computeSchedule() { // Compute raw times for each item const scheduled = state.items.map(item => { let cookStart; + // A hand-set start is the cook's own decision and outranks any hold. + const hold = item.overrideCookStart ? 0 : (holds.get(item.id) || 0); if (item.overrideCookStart) { cookStart = parseTime(item.overrideCookStart); } else if (state.mode === 'end') { // Back from the table: carving and plating happen last, so a dish that // needs ten minutes of that has to be out of the oven ten minutes // earlier than one that goes straight to the table. - const setEnd = target - (item.servePrep || 0); + const setEnd = target - hold - (item.servePrep || 0); const cookEnd = setEnd - (item.setTime || 0); cookStart = cookEnd - (item.cookTime || 0); } else { // start mode: stagger so all items finish together when the longest item does - cookStart = startModeFinish + cookStart = startModeFinish - hold - (item.servePrep || 0) - (item.setTime || 0) - (item.cookTime || 0); } const prepStart = cookStart - (item.prepTime || 0); const cookEnd = cookStart + (item.cookTime || 0); const setEnd = cookEnd + (item.setTime || 0); const serveEnd = setEnd + (item.servePrep || 0); - return { ...item, _s: { cookStart, prepStart, cookEnd, setEnd, serveEnd } }; + return { ...item, _holdFor: hold, _s: { cookStart, prepStart, cookEnd, setEnd, serveEnd } }; }); // Optional: snap nearby start times together so the schedule rounds to natural clusters diff --git a/cook-plan/share-link.js b/cook-plan/share-link.js index 9bd7891..c904ab3 100644 --- a/cook-plan/share-link.js +++ b/cook-plan/share-link.js @@ -19,7 +19,9 @@ // and the form is human-readable. Two legacy base64 formats are still decoded. // ============================================= -const APP_DEFAULTS = { mainOvenShelves: 2, hasCombi: true, hobCount: 5, preheatMins: 6 }; +const APP_DEFAULTS = { + mainOvenShelves: 2, hasCombi: true, hobCount: 5, preheatMins: 6, holdMins: 15, +}; // ---- v2 compact (current) --------------------------------------------------- @@ -66,6 +68,7 @@ function compactState(s) { if (a.hasCombi !== APP_DEFAULTS.hasCombi) ac.ha = a.hasCombi; if (a.hobCount !== APP_DEFAULTS.hobCount) ac.ho = a.hobCount; if ((a.preheatMins ?? APP_DEFAULTS.preheatMins) !== APP_DEFAULTS.preheatMins) ac.ph = a.preheatMins; + if ((a.holdMins ?? APP_DEFAULTS.holdMins) !== APP_DEFAULTS.holdMins) ac.hd = a.holdMins; if (Object.keys(ac).length) c.a = ac; c.i = (s.items || []).map(compactItem); @@ -83,6 +86,7 @@ function expandState(c) { hasCombi: c.a?.ha ?? APP_DEFAULTS.hasCombi, hobCount: c.a?.ho ?? APP_DEFAULTS.hobCount, preheatMins: c.a?.ph ?? APP_DEFAULTS.preheatMins, + holdMins: c.a?.hd ?? APP_DEFAULTS.holdMins, }, items: (c.i || []).map(expandItem), }; From 549462c8541b3f167ef1ac0c4902867cd63db767 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Mon, 23 Nov 2026 10:01:20 +0000 Subject: [PATCH 12/14] [cook-plan] Say up front when the plan has a dish changing ovens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A tray moving between ovens halfway through its cook, or coming out early to sit covered, are not things you would guess from reading the list of dishes — and until now they only appeared on the stop they happen at, which is the worst moment to find out. Both now get a "Heads up" card at the top, in the slot the conflict warning uses. Amber rather than red, because nothing is wrong: the planner has arranged something clever and is telling you about it while there is still time to disagree. Nothing is arranged, nothing is said — with keep-warm turned off the plan this came from shows its conflict and no notices at all. The keep-warm note is in there alongside the move for the same reason the move is: both are work the cook has to remember, and both are invisible from the dish list. Amber is too pale to write in on a pale amber card, so the label gets a darker ink of its own in light mode. Co-Authored-By: Claude Opus 5 --- cook-plan/render-schedule.js | 43 ++++++++++++++++++++++++++++++++++++ cook-plan/style.css | 31 ++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/cook-plan/render-schedule.js b/cook-plan/render-schedule.js index 1d01da7..9471b5e 100644 --- a/cook-plan/render-schedule.js +++ b/cook-plan/render-schedule.js @@ -75,6 +75,7 @@ export function renderScheduleView() { ${conflicts.length > 0 ? renderConflicts(conflicts) : ''} + ${renderNotices(items)}
@@ -117,6 +118,48 @@ export function renderScheduleView() { renderNotifications(); } +// Things the planner has arranged that you would never guess from the list of +// dishes: a tray changing oven halfway through, or coming out early to sit +// covered. Both need knowing about while there is still time to disagree, +// rather than being discovered at twenty to four — so they go at the top with +// the conflicts rather than only on the stop they happen at. +export function renderNotices(items) { + const notes = []; + + for (const i of items) { + if (!i._moveTo) continue; + notes.push(`${i.name} starts in the Combi Oven and moves across to the Main Oven` + + `${i._moveTo.shelf ? `, shelf ${i._moveTo.shelf},` : ''} at ${formatTime(i._moveTo.at)}` + + ` — that is what frees the combi to microwave ${i._moveTo.forItem}.`); + } + + // Grouped by how long each waits, since that is the part worth reading. + const byHold = new Map(); + for (const i of items) { + if (!(i._holdFor > 0)) continue; + if (!byHold.has(i._holdFor)) byHold.set(i._holdFor, []); + byHold.get(i._holdFor).push(i.name); + } + for (const [mins, names] of byHold) { + const many = names.length > 1; + notes.push(`${joinNames(names)} ${many ? 'come' : 'comes'} out ${formatDuration(mins)}` + + ` before everything else so the combi is free in time.` + + ` Cover ${many ? 'them' : 'it'} and ${many ? 'they' : 'it'} will keep.`); + } + + if (notes.length === 0) return ''; + return ` +
+ ${notes.map(n => ` +
+ Heads up +
${escHtml(n)}
+
+ `).join('')} +
+ `; +} + export function renderConflicts(conflicts) { return `
diff --git a/cook-plan/style.css b/cook-plan/style.css index 66e250e..22f06d0 100644 --- a/cook-plan/style.css +++ b/cook-plan/style.css @@ -14,6 +14,8 @@ --accent-glow: rgba(234, 88, 12, 0.2); --amber: #f59e0b; --amber-soft: #fef3c7; + /* Amber is too pale to write in on a pale amber card. */ + --amber-ink: #b45309; /* The solid band behind whichever stage is happening right now. */ --now-bg: #ffe8d1; --now-sub: #9a3412; @@ -61,6 +63,7 @@ --accent-soft: #431407; --accent-glow: rgba(234, 88, 12, 0.3); --amber-soft: #451a03; + --amber-ink: #fbbf24; --now-bg: #3d1709; --now-sub: #fdba74; @@ -769,6 +772,34 @@ button { } } +/* Heads-up notices. Amber rather than red: nothing is wrong with the plan, + there is just something in it you would not have thought of. */ +.notices-section { + display: flex; + flex-direction: column; + gap: var(--space-sm); + margin-top: var(--space-sm); +} + +.notice-card { + background: var(--amber-soft); + border: 1px solid var(--amber); + border-radius: 0.375rem; + padding: var(--space-md) var(--space-lg); + font-size: 0.875rem; + color: var(--amber-ink); + + & strong { + font-weight: 600; + } + + & .notice-detail { + margin-top: var(--space-xs); + color: var(--text); + font-size: 0.8125rem; + } +} + /* Conflict warnings */ .conflicts-section { display: flex; From 52716a3e3b606ac5159d8b76626dc7a062d1d4ec Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Mon, 23 Nov 2026 10:09:10 +0000 Subject: [PATCH 13/14] [cook-plan] Put a minute's jobs in the order you'd do them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At 15:41 the timeline read: parsnips out, parsnips and pigs ready, pigs out — two halves of one instruction with the conclusion wedged between them. The stops within a minute came out in whatever order the events had been built, and two dishes leaving two different ovens were two rows because the grouping key included which oven. Coming out, the appliance only decides the verb, so dishes leaving any oven are now one instruction: "Parsnips & Pigs in blankets out of oven". Hobs and the microwave still get their own line, since "off hob" is a different thing to say. And the rows inside a minute are sorted into the order the jobs actually get done — oven on, trays out, trays moved, chopping, trays in, then the things that are merely true afterwards. While grouping the "out" rows together: a dish in the microwave was being taken "out of oven". The combi cook type is the microwave; an oven dish that happens to be cooking in the combi has always been an oven dish. The appliance summary moves up to sit under the heads-up cards and above the timeline. It is read while planning — which oven has room, what is where — and the timeline is long enough that anything after it is effectively filed away. Co-Authored-By: Claude Opus 5 --- cook-plan/events.js | 8 ++++++-- cook-plan/render-schedule.js | 31 ++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/cook-plan/events.js b/cook-plan/events.js index 985c308..75d61ed 100644 --- a/cook-plan/events.js +++ b/cook-plan/events.js @@ -218,7 +218,10 @@ export function mergedLabel(type, evs, names) { } case 'cook_end': { const resource = ct?.resource; - if (resource === 'oven' || resource === 'combi') return `${joinNames(names)} out of oven`; + // 'combi' as a cook type means the microwave; an oven dish that happens + // to be cooking in the combi has resource 'oven' like any other. + if (resource === 'combi') return `${joinNames(names)} out of the microwave`; + if (resource === 'oven') return `${joinNames(names)} out of oven`; if (resource === 'hob') return `${joinNames(names)} off hob`; return `${joinNames(names)} done`; } @@ -277,7 +280,8 @@ export function cookStartLabel(item, ct, appLabel) { } export function cookEndLabel(item, ct) { - if (ct?.resource === 'oven' || ct?.resource === 'combi') return `${item.name} out of oven`; + if (ct?.resource === 'combi') return `${item.name} out of the microwave`; + if (ct?.resource === 'oven') return `${item.name} out of oven`; if (ct?.resource === 'hob') return `${item.name} off hob`; return `${item.name} done`; } diff --git a/cook-plan/render-schedule.js b/cook-plan/render-schedule.js index 9471b5e..45abf20 100644 --- a/cook-plan/render-schedule.js +++ b/cook-plan/render-schedule.js @@ -77,6 +77,10 @@ export function renderScheduleView() { ${conflicts.length > 0 ? renderConflicts(conflicts) : ''} ${renderNotices(items)} + + ${renderApplianceSummary(items)} +
@@ -94,9 +98,6 @@ export function renderScheduleView() {
- - ${renderApplianceSummary(items)} -