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

Consistent size chips, sturdier offline pages

Youssefb4d288730e0f
diff --git a/public/sw.js b/public/sw.js
index 27936d8..93a2f7c 100644
--- a/public/sw.js
+++ b/public/sw.js
@@ -4,11 +4,15 @@
* voice clips: cache first, they never change under the same name.
* The API is never cached here.
*/
-const PAGES = "bygga-pages-v1";
-const FILES = "bygga-files-v1";
+const PAGES = "bygga-pages-v2";
+const FILES = "bygga-files-v2";
const KEEP = [PAGES, FILES];
-self.addEventListener("install", () => self.skipWaiting());
+self.addEventListener("install", (e) => {
+ self.skipWaiting();
+ // the search is always there, even if the first visit was a guide
+ e.waitUntil(caches.open(PAGES).then((c) => c.add("/")).catch(() => {}));
+});
self.addEventListener("activate", (e) => {
e.waitUntil(
caches
@@ -42,7 +46,8 @@ self.addEventListener("fetch", (e) => {
}
return res;
})
- .catch(() => caches.match(req).then((hit) => hit || caches.match("/"))),
+ // offline: this page, the same guide at another step, or the home page
+ .catch(async () => (await caches.match(req)) || (await caches.match(req, { ignoreSearch: true })) || caches.match("/")),
);
return;
}
diff --git a/src/app/page.tsx b/src/app/page.tsx
index 41f6cd8..4b64c7a 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -33,7 +33,7 @@ export default function Home() {
<br />
step by step.
</h1>
- <p className="lead">Type the name from the box. Each step plays in 3D, with the exact parts, screws and tools, read out loud if your hands are full.</p>
+ <p className="lead">Type the name from the box. Each step plays in 3D and is read out loud, with the exact parts, screws and tools.</p>
<HeroSearch />
<Resume />
<div className="quick">
diff --git a/src/lib/catalog.ts b/src/lib/catalog.ts
index 3381cc8..8488020 100644
--- a/src/lib/catalog.ts
+++ b/src/lib/catalog.ts
@@ -477,6 +477,17 @@ export function catalogSpec(slug: string): ProductSpec | null {
return toSpec(e);
}
+/** One way of naming sizes per family: grids as columns × rows, shelves and cabinets as width × height (and depth when two share those). */
+function sizeLabel(x: Entry, same: Entry[]) {
+ const head = x.variant.split(",")[0];
+ if (x.shelf?.style === "grid" && x.shelf.cols && x.shelf.rows) return `${head}, ${x.shelf.cols} × ${x.shelf.rows}`;
+ if ((x.archetype === "shelf" || x.archetype === "cabinet") && /\d+ × \d+/.test(x.variant)) {
+ const twin = same.some((o) => o !== x && o.size.w === x.size.w && o.size.h === x.size.h);
+ return `${head}, ${x.size.w} × ${x.size.h} cm${twin ? `, ${x.size.d} deep` : ""}`;
+ }
+ return x.variant;
+}
+
export function toSpec(e: Entry): ProductSpec {
const { family, kind, keywords, featured, checked, ...rest } = e;
void kind;
@@ -485,7 +496,11 @@ export function toSpec(e: Entry): ProductSpec {
void checked;
const kin = BY_FAMILY.get(family) ?? [e];
const same = kin.filter((x) => x.category === e.category);
- const variants = same.map((x) => ({ label: x.variant, slug: x.slug }));
+ // smallest first, and a cube grid always reads as columns × rows, like the labels on the box
+ const variants = [...same]
+ .sort((a, b) => a.size.w * a.size.h - b.size.w * b.size.h || a.size.d - b.size.d)
+ .map((x) => ({ label: sizeLabel(x, same), slug: x.slug }))
+ .filter((v, i, all) => all.findIndex((o) => o.label === v.label) === i || v.slug === e.slug);
const seen = new Set<string>([e.category]);
const siblings: { label: string; slug: string }[] = [];
for (const x of kin) {