Skip to content

Commit f5dccc5

Browse files
authored
fix: entry of zero in ingredient amount (#318)
* fix: allow entry of zero as ingredient amount * chore: update build node version
1 parent 6a6af50 commit f5dccc5

File tree

5 files changed

+68
-62
lines changed

5 files changed

+68
-62
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ jobs:
3636
${{ runner.os }}-build-
3737
${{ runner.os }}-
3838
39-
- name: Use Node.js 16.x
40-
uses: actions/setup-node@v1
39+
- name: Use Node.js 20.x
40+
uses: actions/setup-node@v4
4141
with:
42-
node-version: 16.x
42+
node-version: 20.x
4343

4444
- name: Set version
4545
run: |
@@ -70,10 +70,10 @@ jobs:
7070
- name: Checkout code
7171
uses: actions/checkout@v2
7272

73-
# - name: Use Node.js 16.x
74-
# uses: actions/setup-node@v1
73+
# - name: Use Node.js 20.x
74+
# uses: actions/setup-node@v4
7575
# with:
76-
# node-version: 16.x
76+
# node-version: 20.x
7777
# - name: install dependencies
7878
# run: |
7979
# npm ci
@@ -114,10 +114,10 @@ jobs:
114114
${{ runner.os }}-build-
115115
${{ runner.os }}-
116116
117-
- name: Use Node.js 16.x
118-
uses: actions/setup-node@v1
117+
- name: Use Node.js 20.x
118+
uses: actions/setup-node@v4
119119
with:
120-
node-version: 16.x
120+
node-version: 20.x
121121

122122
- name: install dependencies
123123
run: |
@@ -230,10 +230,10 @@ jobs:
230230
${{ runner.os }}-build-
231231
${{ runner.os }}-
232232
233-
- name: Use Node.js 16.x
234-
uses: actions/setup-node@v1
233+
- name: Use Node.js 20.x
234+
uses: actions/setup-node@v4
235235
with:
236-
node-version: 16.x
236+
node-version: 20.x
237237

238238
- name: Set version
239239
run: |

.github/workflows/preview.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ jobs:
2929
${{ runner.os }}-build-
3030
${{ runner.os }}-
3131
32-
- name: Use Node.js 16.x
33-
uses: actions/setup-node@v1
32+
- name: Use Node.js 20.x
33+
uses: actions/setup-node@v4
3434
with:
35-
node-version: 16.x
35+
node-version: 20.x
3636

3737
- name: install dependencies and build
3838
run: |
@@ -140,10 +140,10 @@ jobs:
140140
${{ runner.os }}-build-
141141
${{ runner.os }}-
142142
143-
- name: Use Node.js 16.x
144-
uses: actions/setup-node@v1
143+
- name: Use Node.js 20.x
144+
uses: actions/setup-node@v4
145145
with:
146-
node-version: 16.x
146+
node-version: 20.x
147147

148148
- name: Install dependencies
149149
run: npm ci

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
fetch-depth: 0
1212

1313
- name: 🏗 Setup Node
14-
uses: actions/setup-node@v2
14+
uses: actions/setup-node@v4
1515
with:
16-
node-version: 16.x
16+
node-version: 20.x
1717

1818
- name: 🏗 Setup java
1919
uses: actions/setup-java@v3
@@ -69,7 +69,7 @@ jobs:
6969
# path: app-build.apk
7070

7171
# - name: Setup Node.js
72-
# uses: actions/setup-node@v2
72+
# uses: actions/setup-node@v4
7373
# with:
7474
# node-version: "lts/*"
7575

src/dao/RestAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface Ingredient {
1212

1313
export interface IngredientUse {
1414
ingredient: Ingredient
15-
amount: number
15+
amount: number | null
1616
unit: string
1717
}
1818

src/screens/wizard/IngredientFromField.tsx

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ interface Props {
1717
export const IngredientFormField = React.memo(function IngredientFormField(props: Props) {
1818
const [ingredientQuery, setIngredientQuery] = useState<string>(props.ingredient.ingredient.name);
1919
const [unit, setUnit] = useState<string>(props.ingredient.unit);
20-
const [amount, setAmount] = useState<string>(props.ingredient.amount === 0 ? '': String(props.ingredient.amount));
20+
const [amount, setAmount] = useState<string>(props.ingredient.amount === undefined || props.ingredient.amount === null ? '' : String(props.ingredient.amount));
2121

2222
useEffect(() => {
2323
setIngredientQuery(props.ingredient.ingredient.name);
2424
setUnit(props.ingredient.unit);
25-
setAmount(props.ingredient.amount === 0 ? '': String(props.ingredient.amount));
25+
setAmount(props.ingredient.amount === undefined || props.ingredient.amount === null ? '' : String(props.ingredient.amount));
2626
}, [props.ingredient]);
2727

2828
const [availableUnits, setAvailableUnits] = useState<string[]>([]);
@@ -38,10 +38,17 @@ export const IngredientFormField = React.memo(function IngredientFormField(props
3838

3939
const invokeIngredientUpdate = (ingredientName: string, newAmount: string, newUnit: string) => {
4040
const existingIngredient = availableIngredients.find((ingredient) => ingredient.name.toLowerCase() === ingredientName.toLowerCase());
41+
42+
let prasedAmount: number | null = parseFloat(newAmount);
43+
// Check if its a number
44+
if (prasedAmount.toString() !== newAmount || newAmount === '') {
45+
prasedAmount = null;
46+
}
47+
4148
if (existingIngredient) {
42-
props.onIngredientChange({ingredient: existingIngredient, amount: newAmount === '' ? 0 : parseFloat(newAmount), unit: newUnit}, props.ingredientIndex);
49+
props.onIngredientChange({ingredient: existingIngredient, amount: prasedAmount, unit: newUnit}, props.ingredientIndex);
4350
} else {
44-
props.onIngredientChange({ingredient: {name: ingredientName}, amount: newAmount === '' ? 0 : parseFloat(newAmount), unit: newUnit}, props.ingredientIndex);
51+
props.onIngredientChange({ingredient: {name: ingredientName}, amount: prasedAmount, unit: newUnit}, props.ingredientIndex);
4552
}
4653
};
4754

@@ -61,7 +68,8 @@ export const IngredientFormField = React.memo(function IngredientFormField(props
6168
setAmount(text);
6269

6370
const prasedAmount = parseFloat(text);
64-
if (prasedAmount.toString() === text) {
71+
// Check if its a number
72+
if (prasedAmount.toString() === text || text === '') {
6573
invokeIngredientUpdate(ingredientQuery, text, unit);
6674
}
6775
};
@@ -75,43 +83,41 @@ export const IngredientFormField = React.memo(function IngredientFormField(props
7583
}, []);
7684

7785
return (
78-
<>
79-
<View style={{borderWidth: 1, borderColor: Colors.grey50, padding: 10, borderRadius: 16}}>
80-
<View style={{flexDirection: 'row', alignItems: 'center'}}>
81-
<View style={{flex: 1, flexDirection: 'column'}}>
82-
<View style={{flex: 1, flexDirection: 'row'}}>
83-
<TextInput
84-
mode="outlined"
85-
style={{width: 100}}
86-
keyboardType="numeric"
87-
value={(amount ? amount.toString() : '')}
88-
label={t('screens.editRecipe.amount')}
89-
onChangeText={onAmountChange} />
90-
<Spacer width={5} />
91-
<SelectionPopup
92-
style={{flex: 1}}
93-
label={t('screens.editRecipe.unit')}
94-
value={unit}
95-
options={availableUnits.map((availableUnit, index) => ({key: index.toString(), value: availableUnit}))}
96-
onValueChanged={(selectedOption) => setUnit(selectedOption.value)}
97-
/>
98-
</View>
99-
<Spacer height={5} />
100-
<View style={{justifyContent: 'center', flex: 1}}>
101-
<SelectionPopup
102-
label={t('screens.editRecipe.ingredient')}
103-
value={ingredientQuery}
104-
options={availableIngredients.map((ingredient) => ({key: ingredient.id ? ingredient.id.toString() : '', value: ingredient.name}))}
105-
onValueChanged={(selectedOption) => setIngredient(selectedOption.value)}
106-
allowAdditionalValues={true}
107-
/>
108-
</View>
86+
<View style={{borderWidth: 1, borderColor: Colors.grey50, padding: 10, borderRadius: 16}}>
87+
<View style={{flexDirection: 'row', alignItems: 'center'}}>
88+
<View style={{flex: 1, flexDirection: 'column'}}>
89+
<View style={{flex: 1, flexDirection: 'row'}}>
90+
<TextInput
91+
mode="outlined"
92+
style={{width: 100}}
93+
keyboardType="numeric"
94+
value={(amount !== undefined ? amount.toString() : '')}
95+
label={t('screens.editRecipe.amount')}
96+
onChangeText={onAmountChange} />
97+
<Spacer width={5} />
98+
<SelectionPopup
99+
style={{flex: 1}}
100+
label={t('screens.editRecipe.unit')}
101+
value={unit}
102+
options={availableUnits.map((availableUnit, index) => ({key: index.toString(), value: availableUnit}))}
103+
onValueChanged={(selectedOption) => setUnit(selectedOption.value)}
104+
/>
105+
</View>
106+
<Spacer height={5} />
107+
<View style={{justifyContent: 'center', flex: 1}}>
108+
<SelectionPopup
109+
label={t('screens.editRecipe.ingredient')}
110+
value={ingredientQuery}
111+
options={availableIngredients.map((ingredient) => ({key: ingredient.id ? ingredient.id.toString() : '', value: ingredient.name}))}
112+
onValueChanged={(selectedOption) => setIngredient(selectedOption.value)}
113+
allowAdditionalValues={true}
114+
/>
109115
</View>
110-
<IconButton
111-
icon="delete-outline"
112-
onPress={() => props.onRemovePress(props.ingredientIndex)} />
113116
</View>
117+
<IconButton
118+
icon="delete-outline"
119+
onPress={() => props.onRemovePress(props.ingredientIndex)} />
114120
</View>
115-
</>
121+
</View>
116122
);
117123
});

0 commit comments

Comments
 (0)