From 408a996fe76f39587f555787919f8c2213e06a56 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 30 Jun 2024 09:37:27 -0700 Subject: [PATCH] change product to dump to object before storing in redix. TODO: solve dimensions issue. --- app/(tabs)/_layout.tsx | 2 +- app/(tabs)/index.tsx | 32 +-- app/store.ts | 4 +- components/ProductAttributeEditor.tsx | 39 ++-- components/ProductEditor.tsx | 37 +++- components/ProductEditorItem.tsx | 184 ++++++++++++++---- .../__tests__/ProductAttributeEditor-test.tsx | 25 ++- components/__tests__/ProductEditor-test.tsx | 44 ++++- .../__tests__/ProductEditorItem-test.tsx | 54 ++++- features/product/productSlice.ts | 170 +++++++++++++--- lib/product.ts | 144 ++++++++------ lib/rendering.tsx | 4 +- lib/util.ts | 0 package.json | 3 + pnpm-lock.yaml | 21 ++ 15 files changed, 577 insertions(+), 186 deletions(-) create mode 100644 lib/util.ts diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index a3fb5d5..5148202 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -10,7 +10,7 @@ import { setupStore } from '../store'; export default function TabLayout() { const colorScheme = useColorScheme(); const store = setupStore({ - products: fixtures + products: fixtures.map(p => p.asObject) }); return ( diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index e0f8fe6..1a9e66e 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -23,17 +23,23 @@ export default function HomeScreen() { if (!activeProduct) return; const l = Number.parseInt(length); const w = Number.parseInt(width); - console.log("l=%d, w=%d", l, w); + // console.log("l=%d, w=%d", l, w); const u = units; const d: dimensions_t = activeProduct.area ? { l, w, u } : { l, u }; - const p = activeProduct.priceFor(d); - console.log("set price %s", p); - const s = p.toLocaleString(undefined, { - minimumFractionDigits: 2, - maximumFractionDigits: 2, - }) - setPrice(s == "NaN" ? "0.00" : s); - }, 10); + try { + const p = activeProduct.priceFor(d); + console.log("set price %s", p); + const s = p.toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }) + setPrice(s == "NaN" ? "0.00" : s); + } catch (err) { + console.log(activeProduct); + console.error(err) + return null; + } + }, 50); return function () { clearInterval(iv); } @@ -67,13 +73,13 @@ export default function HomeScreen() { {units} ) } + +