From fb68beb1b3edf87c733c7f7dd89777414aedd9d5 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 30 Jun 2024 19:49:41 -0700 Subject: [PATCH] start to refactor components. --- app/(tabs)/index.tsx | 201 +---------------------- components/AreaInput.tsx | 49 ++++++ components/LengthInput.tsx | 88 ---------- components/MeasurementInput.tsx | 48 ++++++ components/Price.tsx | 39 +++++ components/ProductCalculatorSelector.tsx | 148 +++++++++++++++++ components/ProductList.tsx | 47 ++++++ components/ProductTile.tsx | 41 +++-- components/UnitChooser.tsx | 49 ++++++ features/product/productSlice.ts | 2 +- lib/__tests__/product-test.ts | 7 + lib/product.ts | 2 +- 12 files changed, 421 insertions(+), 300 deletions(-) create mode 100644 components/AreaInput.tsx delete mode 100644 components/LengthInput.tsx create mode 100644 components/MeasurementInput.tsx create mode 100644 components/Price.tsx create mode 100644 components/ProductCalculatorSelector.tsx create mode 100644 components/ProductList.tsx create mode 100644 components/UnitChooser.tsx diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 1a9e66e..6a9fffe 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -1,202 +1,13 @@ -import { Image, StyleSheet, Platform, ImageBackground, View, Text, Button, TextInputKeyPressEventData, TextInput, FlatList } from 'react-native'; +import ProductCalculatorSelector from '@/components/ProductCalculatorSelector'; +import { SafeAreaView, View } from 'react-native'; -import { SafeAreaView } from 'react-native-safe-area-context'; -import { useAppSelector } from '../store'; -import { selectProducts } from '@/features/product/productSlice'; -import { Product, dimensions_t } from '@/lib/product'; -import { useEffect, useState } from 'react'; -import { TouchableHighlight } from 'react-native-gesture-handler'; const fallbackImage = require("@/assets/images/board-stock-lightened-blurred.png"); -export default function HomeScreen() { - - const products = useAppSelector(selectProducts); - const [activeProduct, setActiveProduct] = useState(null as Product | null); - const [price, setPrice] = useState("0.00"); - const [length, setLength] = useState("0"); - const [width, setWidth] = useState("0"); - const [units, setUnits] = useState("in" as "ft" | "in"); - - useEffect(function () { - const iv = setInterval(function () { - if (!activeProduct) return; - const l = Number.parseInt(length); - const w = Number.parseInt(width); - // console.log("l=%d, w=%d", l, w); - const u = units; - const d: dimensions_t = activeProduct.area ? { l, w, u } : { l, u }; - 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); - } - }, [activeProduct, length, width]); - +export const HomeScreen = () => { return ( - - - $ {price} - - - - {activeProduct ? ( - - - {units} - {activeProduct.area && ( - - - {units} - ) - } - -