fix: vague ingredient description now persists

This commit is contained in:
Zhongheng Liu 2026-01-24 14:48:22 +01:00
commit aec8a6bc17
Signed by: steven
GPG key ID: F69B980899C1C09D

View file

@ -64,18 +64,21 @@ public class IngredientListCell extends OrderedEditableListCell<RecipeIngredient
Optional<Double> templateAmount = Optional.empty();
Optional<Unit> unit = Optional.empty();
TextField amountInput;
// Initialize the input fields with some initial data if we get a formal ingredient
if (ingredient.getClass().equals(FormalIngredient.class)) {
FormalIngredient formal = (FormalIngredient) ingredient;
templateAmount = Optional.of(formal.getAmount());
unit = Optional.of(Unit.fromString(formal.getUnitSuffix()).orElseThrow(
() -> new RuntimeException("FormalIngredient whereas invalid unit")));
amountInput = new TextField(templateAmount.map(Object::toString).orElse(null));
} else {
assert ingredient instanceof VagueIngredient;
amountInput = new TextField(((VagueIngredient) ingredient).getDescription());
}
// TODO initialize some other data in the case of vague ingredient
// Initialize the input boxes
TextField amountInput = new TextField(templateAmount.map(Object::toString).orElse(null));
ChoiceBox<Unit> unitChoice = new ChoiceBox<>();
// initialize the current unit if it is present
@ -115,7 +118,6 @@ public class IngredientListCell extends OrderedEditableListCell<RecipeIngredient
menu.setText(getLocaleString("app.prompt.new-ingredient")); // otherwise the text label on menu refuses to update
selectedIngredient.setValue(null); // indicate null to signal a new ingredient creation
logger.info("Making new ingredient");
// TODO printError() integration
TextField newIngredientNameInput = makeNewIngredientNameField(selectedIngredient::set);
container.getChildren().add(newIngredientNameInput);
});