Build coffee history and experiment workflows with Ask Bean Bro
Test and deploy / test-and-deploy (push) Successful in 1m21s
Test and deploy / test-and-deploy (push) Successful in 1m21s
This commit is contained in:
1 parent
1fd53091ac
commit
8c21750356
28 files changed
+3848
-384
No files matched your search
+13
-5
@@ -1,3 +1,4 @@
|
||||
import { initPlannerWorkspace } from "./planner-workspace.js?v=__ASSET_VERSION__";
|
||||
import { FIELD_IDS, blankPlan } from "/shared/fields.js?v=__ASSET_VERSION__";
|
||||
import { computeLedger } from "/shared/ledger.js?v=__ASSET_VERSION__";
|
||||
import {
|
||||
@@ -414,6 +415,7 @@ function hasVal(obj, blank) {
|
||||
}
|
||||
|
||||
export function recompute() {
|
||||
document.dispatchEvent(new Event("plan-updated"));
|
||||
const ledger = renderLedger();
|
||||
renderCurve(ledger);
|
||||
renderBandMarkers();
|
||||
@@ -482,7 +484,7 @@ function syncPlan(snapshot = structuredClone(state.plan), locallySaved = persist
|
||||
draftSyncedAt = body.plan.updated_at;
|
||||
currentPlanName = body.plan.name ?? currentPlanName;
|
||||
// A confirmed server save succeeds even when browser storage is full/disabled.
|
||||
persistDraft(snapshot);
|
||||
persistDraft(structuredClone(state.plan));
|
||||
history.replaceState(null, "", `/app?plan=${encodeURIComponent(remotePlanId)}`);
|
||||
lastSaveError = "";
|
||||
setSaveStatus("saved");
|
||||
@@ -501,6 +503,9 @@ async function flushCurrentPlan() {
|
||||
return await syncPlan(snapshot, persistDraft(snapshot));
|
||||
}
|
||||
function autosave() {
|
||||
// Preserve each edit immediately; debounce only the network write. Reloads and
|
||||
// offline roast-day events must not depend on a later timer firing.
|
||||
persistDraft(structuredClone(state.plan));
|
||||
setSaveStatus("saving");
|
||||
clearTimeout(autosave._t);
|
||||
autosave._t = setTimeout(() => {
|
||||
@@ -681,7 +686,7 @@ function wireDrawers() {
|
||||
for (const [buttonId, panelId] of [
|
||||
["nav-prefill", "panel-prefill"],
|
||||
["nav-alog", "panel-alog"],
|
||||
["nav-chat", "panel-chat"],
|
||||
|
||||
["nav-settings", "panel-settings"],
|
||||
["nav-import-export", "panel-import-export"],
|
||||
])
|
||||
@@ -853,7 +858,7 @@ function wirePwa() {
|
||||
// "controllerchange" is not an update — only a page that was already controlled by a
|
||||
// previous service worker should reload when a new one takes over.
|
||||
const hadController = !!navigator.serviceWorker.controller;
|
||||
window.addEventListener("load", () => {
|
||||
const registerWorker = () => {
|
||||
navigator.serviceWorker
|
||||
.register("/sw.js?v=__ASSET_VERSION__")
|
||||
.then((registration) => {
|
||||
@@ -870,7 +875,9 @@ function wirePwa() {
|
||||
.catch((error) =>
|
||||
console.warn("Service worker registration failed:", error),
|
||||
);
|
||||
});
|
||||
};
|
||||
if (document.readyState === "complete") registerWorker();
|
||||
else window.addEventListener("load", registerWorker, {once:true});
|
||||
navigator.serviceWorker.addEventListener("controllerchange", () => {
|
||||
if (hadController) location.reload();
|
||||
});
|
||||
@@ -970,6 +977,7 @@ async function init() {
|
||||
getTempUnit: () => tempUnit,
|
||||
getMachineProfile: () => machineProfile,
|
||||
});
|
||||
initPlannerWorkspace({state,recompute,renderFormFromPlan,flushCurrentPlan,getRemotePlanId:()=>remotePlanId,rename:async name=>{if(!await flushCurrentPlan())return showToast(lastSaveError,"fail");try{const result=await api(`/api/plans/${remotePlanId}`,{method:"PUT",body:JSON.stringify({name})});currentPlanName=result.plan.name;renderFormFromPlan();}catch(e){showToast(e.message,"fail");}}});
|
||||
renderBandRanges();
|
||||
renderFormFromPlan();
|
||||
wireForm();
|
||||
@@ -1002,7 +1010,7 @@ async function init() {
|
||||
renderFormFromPlan,
|
||||
});
|
||||
wireCuppingLink();
|
||||
initPlanChat({ getPlan: () => state.plan });
|
||||
initPlanChat({ getPlan: () => state.plan, recompute, renderFormFromPlan, flushCurrentPlan, getRemotePlanId:()=>remotePlanId });
|
||||
renderMachineProfileNote();
|
||||
recompute();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user