From 6ace2968007203b90d70e58f9ba70888780f6f18 Mon Sep 17 00:00:00 2001 From: steve192 Date: Tue, 27 Feb 2024 19:49:40 +0100 Subject: [PATCH 1/2] fix: allow entry of zero as ingredient amount --- src/dao/RestAPI.ts | 2 +- src/screens/wizard/IngredientFromField.tsx | 86 ++++++++++++---------- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/dao/RestAPI.ts b/src/dao/RestAPI.ts index d734fbee..1fe32037 100644 --- a/src/dao/RestAPI.ts +++ b/src/dao/RestAPI.ts @@ -12,7 +12,7 @@ export interface Ingredient { export interface IngredientUse { ingredient: Ingredient - amount: number + amount: number | null unit: string } diff --git a/src/screens/wizard/IngredientFromField.tsx b/src/screens/wizard/IngredientFromField.tsx index 070f942d..015bb217 100644 --- a/src/screens/wizard/IngredientFromField.tsx +++ b/src/screens/wizard/IngredientFromField.tsx @@ -17,12 +17,12 @@ interface Props { export const IngredientFormField = React.memo(function IngredientFormField(props: Props) { const [ingredientQuery, setIngredientQuery] = useState(props.ingredient.ingredient.name); const [unit, setUnit] = useState(props.ingredient.unit); - const [amount, setAmount] = useState(props.ingredient.amount === 0 ? '': String(props.ingredient.amount)); + const [amount, setAmount] = useState(props.ingredient.amount === undefined || props.ingredient.amount === null ? '' : String(props.ingredient.amount)); useEffect(() => { setIngredientQuery(props.ingredient.ingredient.name); setUnit(props.ingredient.unit); - setAmount(props.ingredient.amount === 0 ? '': String(props.ingredient.amount)); + setAmount(props.ingredient.amount === undefined || props.ingredient.amount === null ? '' : String(props.ingredient.amount)); }, [props.ingredient]); const [availableUnits, setAvailableUnits] = useState([]); @@ -38,10 +38,17 @@ export const IngredientFormField = React.memo(function IngredientFormField(props const invokeIngredientUpdate = (ingredientName: string, newAmount: string, newUnit: string) => { const existingIngredient = availableIngredients.find((ingredient) => ingredient.name.toLowerCase() === ingredientName.toLowerCase()); + + let prasedAmount: number | null = parseFloat(newAmount); + // Check if its a number + if (prasedAmount.toString() !== newAmount || newAmount === '') { + prasedAmount = null; + } + if (existingIngredient) { - props.onIngredientChange({ingredient: existingIngredient, amount: newAmount === '' ? 0 : parseFloat(newAmount), unit: newUnit}, props.ingredientIndex); + props.onIngredientChange({ingredient: existingIngredient, amount: prasedAmount, unit: newUnit}, props.ingredientIndex); } else { - props.onIngredientChange({ingredient: {name: ingredientName}, amount: newAmount === '' ? 0 : parseFloat(newAmount), unit: newUnit}, props.ingredientIndex); + props.onIngredientChange({ingredient: {name: ingredientName}, amount: prasedAmount, unit: newUnit}, props.ingredientIndex); } }; @@ -61,7 +68,8 @@ export const IngredientFormField = React.memo(function IngredientFormField(props setAmount(text); const prasedAmount = parseFloat(text); - if (prasedAmount.toString() === text) { + // Check if its a number + if (prasedAmount.toString() === text || text === '') { invokeIngredientUpdate(ingredientQuery, text, unit); } }; @@ -75,43 +83,41 @@ export const IngredientFormField = React.memo(function IngredientFormField(props }, []); return ( - <> - - - - - - - ({key: index.toString(), value: availableUnit}))} - onValueChanged={(selectedOption) => setUnit(selectedOption.value)} - /> - - - - ({key: ingredient.id ? ingredient.id.toString() : '', value: ingredient.name}))} - onValueChanged={(selectedOption) => setIngredient(selectedOption.value)} - allowAdditionalValues={true} - /> - + + + + + + + ({key: index.toString(), value: availableUnit}))} + onValueChanged={(selectedOption) => setUnit(selectedOption.value)} + /> + + + + ({key: ingredient.id ? ingredient.id.toString() : '', value: ingredient.name}))} + onValueChanged={(selectedOption) => setIngredient(selectedOption.value)} + allowAdditionalValues={true} + /> - props.onRemovePress(props.ingredientIndex)} /> + props.onRemovePress(props.ingredientIndex)} /> - + ); }); From 21192c6c8e0e10d964acf88304b01572aa48639c Mon Sep 17 00:00:00 2001 From: steve192 Date: Tue, 27 Feb 2024 19:58:00 +0100 Subject: [PATCH 2/2] chore: update build node version --- .github/workflows/ci.yml | 24 ++++++++++++------------ .github/workflows/preview.yml | 12 ++++++------ .github/workflows/release.yml | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b897c000..fbd4540e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,10 +36,10 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - - name: Use Node.js 16.x - uses: actions/setup-node@v1 + - name: Use Node.js 20.x + uses: actions/setup-node@v4 with: - node-version: 16.x + node-version: 20.x - name: Set version run: | @@ -70,10 +70,10 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - # - name: Use Node.js 16.x - # uses: actions/setup-node@v1 + # - name: Use Node.js 20.x + # uses: actions/setup-node@v4 # with: - # node-version: 16.x + # node-version: 20.x # - name: install dependencies # run: | # npm ci @@ -114,10 +114,10 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - - name: Use Node.js 16.x - uses: actions/setup-node@v1 + - name: Use Node.js 20.x + uses: actions/setup-node@v4 with: - node-version: 16.x + node-version: 20.x - name: install dependencies run: | @@ -230,10 +230,10 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - - name: Use Node.js 16.x - uses: actions/setup-node@v1 + - name: Use Node.js 20.x + uses: actions/setup-node@v4 with: - node-version: 16.x + node-version: 20.x - name: Set version run: | diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 727afbbb..752d548b 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -29,10 +29,10 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - - name: Use Node.js 16.x - uses: actions/setup-node@v1 + - name: Use Node.js 20.x + uses: actions/setup-node@v4 with: - node-version: 16.x + node-version: 20.x - name: install dependencies and build run: | @@ -140,10 +140,10 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - - name: Use Node.js 16.x - uses: actions/setup-node@v1 + - name: Use Node.js 20.x + uses: actions/setup-node@v4 with: - node-version: 16.x + node-version: 20.x - name: Install dependencies run: npm ci diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e941cb50..7bbe4d75 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,9 +11,9 @@ jobs: fetch-depth: 0 - name: 🏗 Setup Node - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: - node-version: 16.x + node-version: 20.x - name: 🏗 Setup java uses: actions/setup-java@v3 @@ -69,7 +69,7 @@ jobs: # path: app-build.apk # - name: Setup Node.js - # uses: actions/setup-node@v2 + # uses: actions/setup-node@v4 # with: # node-version: "lts/*"