Skip to content

armgit / bygga

Public Imported from GitHub
0

IKEA assembly, step by step: animated, manual-style 3D guides. Scan any paper manual with Together AI.

TypeScript

One rule for build times: the Workshop and cover agree with Done

Youssefcf5c94c77e4f
diff --git a/src/components/guide/CoverPanel.tsx b/src/components/guide/CoverPanel.tsx
index a9b90c5..bfc938a 100644
--- a/src/components/guide/CoverPanel.tsx
+++ b/src/components/guide/CoverPanel.tsx
@@ -3,7 +3,7 @@
import Link from "next/link";
import { spellOut } from "@/lib/shorthand";
import type { Plan } from "@/lib/types";
-import type { Progress } from "@/lib/store";
+import { buildMinutes, type Progress } from "@/lib/store";
import { floorSpace, totals } from "@/lib/plan/contents";
import { IArrowRight, IBox, ICheck, IClock, IExternal, IPeople, IPerson, IPrint, IRuler, ISparkle, IWrench } from "../art/Icons";
import { Dots } from "./ui";
@@ -44,7 +44,10 @@ export default function CoverPanel({
<p className="built-pill">
<ICheck size={15} strokeWidth={2.6} />
Built {new Date(built.at).toLocaleDateString(undefined, { day: "numeric", month: "short" })}
- {built.full && built.ms ? `, in ${fmtMin(Math.max(1, Math.round(built.ms / 60000)))}` : ""}
+ {(() => {
+ const m = buildMinutes(built.ms, built.full, s.minutes);
+ return m ? `, in ${fmtMin(m)}` : "";
+ })()}
</p>
)}
</header>
diff --git a/src/components/guide/DonePanel.tsx b/src/components/guide/DonePanel.tsx
index 48a8fee..0569e1f 100644
--- a/src/components/guide/DonePanel.tsx
+++ b/src/components/guide/DonePanel.tsx
@@ -6,7 +6,7 @@ import { motion } from "motion/react";
import type { Plan } from "@/lib/types";
import { totals } from "@/lib/plan/contents";
import { POPULAR } from "@/lib/search";
-import { getPref, setPref } from "@/lib/store";
+import { buildMinutes, getPref, setPref } from "@/lib/store";
import { Figure } from "../art/Figure";
import { IArrowLeft, IArrowRight, ICheck, ILibrary, IShare } from "../art/Icons";
import Drawing from "../Drawing";
@@ -19,8 +19,7 @@ export default function DonePanel({ plan, slug, finish, onReview }: { plan: Plan
const t = totals(plan);
const s = plan.spec;
// a time only counts when the steps were followed, not tapped through in a minute
- const mins = finish?.full ? Math.max(1, Math.round(finish.ms / 60000)) : 0;
- const spent = mins >= s.minutes * 0.2 ? mins : null;
+ const spent = buildMinutes(finish?.ms, finish?.full, s.minutes);
const faster = spent !== null && spent < s.minutes * 0.95;
const a = s.archetype;
const recheck = a === "table" || a === "bed" || a === "seat" || a === "sofa";
diff --git a/src/components/workshop/Workshop.tsx b/src/components/workshop/Workshop.tsx
index d792c23..68dd9c5 100644
--- a/src/components/workshop/Workshop.tsx
+++ b/src/components/workshop/Workshop.tsx
@@ -7,7 +7,7 @@ import { catalogSpec } from "@/lib/catalog";
import { buildPlan } from "@/lib/plan";
import { totals } from "@/lib/plan/contents";
import { lineup } from "@/lib/plan/lineup";
-import { isBuilt, listProgress, removeProgress, type Progress } from "@/lib/store";
+import { buildMinutes, isBuilt, listProgress, removeProgress, type Progress } from "@/lib/store";
import type { Plan, ProductSpec } from "@/lib/types";
import { useMounted } from "@/lib/useMounted";
import { peekShot, shot, type Shot } from "@/engine/thumbs";
@@ -33,7 +33,7 @@ function fmtTime(min: number) {
/** Building time, only when the steps were followed (older saves only had start and end). */
function spentOf(r: Row) {
const p = r.p;
- if (p.builtAt) return p.builtFull && p.builtMs ? Math.max(1, Math.round(p.builtMs / 60000)) : null;
+ if (p.builtAt) return buildMinutes(p.builtMs, p.builtFull, r.spec.minutes);
const m = p.startedAt && p.doneAt && p.doneAt > p.startedAt ? Math.round((p.doneAt - p.startedAt) / 60000) : 0;
// a wall clock that ran overnight isn't a build time
return m > 0 && m < r.spec.minutes * 3 ? m : null;
diff --git a/src/lib/store.ts b/src/lib/store.ts
index 06b89f8..0f3eb69 100644
--- a/src/lib/store.ts
+++ b/src/lib/store.ts
@@ -35,6 +35,13 @@ export const isBuilt = (p: Progress) => !!p.builtAt || p.phase === "done";
/** A gap longer than this between taps counts as a break, not building time. */
export const BREAK_MS = 20 * 60_000;
+/** Minutes a build took, only when every step was followed and it took at least a fifth of the typical time (not tapped through). */
+export function buildMinutes(ms: number | undefined, full: boolean | undefined, typical: number): number | null {
+ if (!full || !ms) return null;
+ const m = Math.max(1, Math.round(ms / 60000));
+ return m >= typical * 0.2 ? m : null;
+}
+
const KEY = "bygga:builds";
function read(): Record<string, Progress> {