Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/*"

Expand Down
2 changes: 1 addition & 1 deletion src/dao/RestAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Ingredient {

export interface IngredientUse {
ingredient: Ingredient
amount: number
amount: number | null
unit: string
}

Expand Down
86 changes: 46 additions & 40 deletions src/screens/wizard/IngredientFromField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ interface Props {
export const IngredientFormField = React.memo(function IngredientFormField(props: Props) {
const [ingredientQuery, setIngredientQuery] = useState<string>(props.ingredient.ingredient.name);
const [unit, setUnit] = useState<string>(props.ingredient.unit);
const [amount, setAmount] = useState<string>(props.ingredient.amount === 0 ? '': String(props.ingredient.amount));
const [amount, setAmount] = useState<string>(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<string[]>([]);
Expand All @@ -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);
}
};

Expand All @@ -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);
}
};
Expand All @@ -75,43 +83,41 @@ export const IngredientFormField = React.memo(function IngredientFormField(props
}, []);

return (
<>
<View style={{borderWidth: 1, borderColor: Colors.grey50, padding: 10, borderRadius: 16}}>
<View style={{flexDirection: 'row', alignItems: 'center'}}>
<View style={{flex: 1, flexDirection: 'column'}}>
<View style={{flex: 1, flexDirection: 'row'}}>
<TextInput
mode="outlined"
style={{width: 100}}
keyboardType="numeric"
value={(amount ? amount.toString() : '')}
label={t('screens.editRecipe.amount')}
onChangeText={onAmountChange} />
<Spacer width={5} />
<SelectionPopup
style={{flex: 1}}
label={t('screens.editRecipe.unit')}
value={unit}
options={availableUnits.map((availableUnit, index) => ({key: index.toString(), value: availableUnit}))}
onValueChanged={(selectedOption) => setUnit(selectedOption.value)}
/>
</View>
<Spacer height={5} />
<View style={{justifyContent: 'center', flex: 1}}>
<SelectionPopup
label={t('screens.editRecipe.ingredient')}
value={ingredientQuery}
options={availableIngredients.map((ingredient) => ({key: ingredient.id ? ingredient.id.toString() : '', value: ingredient.name}))}
onValueChanged={(selectedOption) => setIngredient(selectedOption.value)}
allowAdditionalValues={true}
/>
</View>
<View style={{borderWidth: 1, borderColor: Colors.grey50, padding: 10, borderRadius: 16}}>
<View style={{flexDirection: 'row', alignItems: 'center'}}>
<View style={{flex: 1, flexDirection: 'column'}}>
<View style={{flex: 1, flexDirection: 'row'}}>
<TextInput
mode="outlined"
style={{width: 100}}
keyboardType="numeric"
value={(amount !== undefined ? amount.toString() : '')}
label={t('screens.editRecipe.amount')}
onChangeText={onAmountChange} />
<Spacer width={5} />
<SelectionPopup
style={{flex: 1}}
label={t('screens.editRecipe.unit')}
value={unit}
options={availableUnits.map((availableUnit, index) => ({key: index.toString(), value: availableUnit}))}
onValueChanged={(selectedOption) => setUnit(selectedOption.value)}
/>
</View>
<Spacer height={5} />
<View style={{justifyContent: 'center', flex: 1}}>
<SelectionPopup
label={t('screens.editRecipe.ingredient')}
value={ingredientQuery}
options={availableIngredients.map((ingredient) => ({key: ingredient.id ? ingredient.id.toString() : '', value: ingredient.name}))}
onValueChanged={(selectedOption) => setIngredient(selectedOption.value)}
allowAdditionalValues={true}
/>
</View>
<IconButton
icon="delete-outline"
onPress={() => props.onRemovePress(props.ingredientIndex)} />
</View>
<IconButton
icon="delete-outline"
onPress={() => props.onRemovePress(props.ingredientIndex)} />
</View>
</>
</View>
);
});