|
@@ -14,22 +14,56 @@ type IngredientFormProps = {
|
|
|
addSubrecipe: () => void,
|
|
addSubrecipe: () => void,
|
|
|
updateSubrecipeName: (subrecipe: number, newValue: string) => void,
|
|
updateSubrecipeName: (subrecipe: number, newValue: string) => void,
|
|
|
removeSubrecipe: (index: number) => void,
|
|
removeSubrecipe: (index: number) => void,
|
|
|
|
|
+ updateIngredientUnit: (key: Array<string|number>, newValue: string) => void,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-class IngredientForm extends React.Component<IngredientFormProps, { activeGroup: number }>{
|
|
|
|
|
|
|
+type SelectOption = {
|
|
|
|
|
+ label: string,
|
|
|
|
|
+ value: string,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type IngredientFormState = {
|
|
|
|
|
+ activeGroup: number,
|
|
|
|
|
+ unitOptions: SelectOption[],
|
|
|
|
|
+ normalizeUnits: any,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+class IngredientForm extends React.Component<IngredientFormProps, IngredientFormState>{
|
|
|
|
|
|
|
|
constructor(props: IngredientFormProps) {
|
|
constructor(props: IngredientFormProps) {
|
|
|
super(props);
|
|
super(props);
|
|
|
this.state = {
|
|
this.state = {
|
|
|
|
|
+ unitOptions: [
|
|
|
|
|
+ { label: 'gr', value: 'gr'},
|
|
|
|
|
+ { label: 'cup', value: 'cup'},
|
|
|
|
|
+ { label: 'tbsp', value: 'tbsp'},
|
|
|
|
|
+ { label: 'tsp', value: 'tsp'},
|
|
|
|
|
+ { label: 'stick', value: 'stick'},
|
|
|
|
|
+ { label: 'ml', value: 'ml'},
|
|
|
|
|
+ { label: 'oz', value: 'oz'},
|
|
|
|
|
+ { label: 'lb', value: 'lb'},
|
|
|
|
|
+ ],
|
|
|
activeGroup: 0,
|
|
activeGroup: 0,
|
|
|
|
|
+ normalizeUnits: {
|
|
|
|
|
+ tablespoon: 'tbsp',
|
|
|
|
|
+ teaspoon: 'tsp',
|
|
|
|
|
+ pound: 'lb',
|
|
|
|
|
+ ounce: 'oz'
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
handleActiveIndexUpdate = (activeGroup: number) => this.setState({ activeGroup })
|
|
handleActiveIndexUpdate = (activeGroup: number) => this.setState({ activeGroup })
|
|
|
|
|
+
|
|
|
|
|
+ normalizeUnits = (unit: string): string => this.state.normalizeUnits[unit] || unit;
|
|
|
|
|
+
|
|
|
|
|
+ onChangeUnit = (key: Array<string|number>) =>
|
|
|
|
|
+ (selection: SelectOption) => this.props.updateIngredientUnit(key, selection.value);
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const {updateField, components, addSubrecipe, updateSubrecipeName, removeSubrecipe} = this.props;
|
|
|
|
|
- const {activeGroup} = this.state;
|
|
|
|
|
|
|
+ const {updateField, components, addSubrecipe, updateSubrecipeName, removeSubrecipe } = this.props;
|
|
|
|
|
+ const { activeGroup, unitOptions, normalizeUnits } = this.state;
|
|
|
const tabs = components.map(group => group.name);
|
|
const tabs = components.map(group => group.name);
|
|
|
return (
|
|
return (
|
|
|
<div className='cbk-ingredient-form'>
|
|
<div className='cbk-ingredient-form'>
|
|
@@ -67,17 +101,14 @@ class IngredientForm extends React.Component<IngredientFormProps, { activeGroup:
|
|
|
/>
|
|
/>
|
|
|
<Select
|
|
<Select
|
|
|
label=''
|
|
label=''
|
|
|
- options={[
|
|
|
|
|
- {label: 'grams', value: 'gr'},
|
|
|
|
|
- {label: 'cups', value: 'cup'},
|
|
|
|
|
- {label: 'mililiters', value: 'ml'},
|
|
|
|
|
- ]}
|
|
|
|
|
- onChange={(x) => {console.log('selected', x)}}
|
|
|
|
|
|
|
+ value={this.normalizeUnits(ingredient.unit)}
|
|
|
|
|
+ options={unitOptions}
|
|
|
|
|
+ onChange={this.onChangeUnit(['ingredients', activeGroup, 'ingredients', index, 'unit'])}
|
|
|
/>
|
|
/>
|
|
|
<Input
|
|
<Input
|
|
|
label=''
|
|
label=''
|
|
|
value={''}
|
|
value={''}
|
|
|
- onChange={updateField(['ingredients', activeGroup, 'ingredients', index, '_original'])}
|
|
|
|
|
|
|
+ onChange={updateField(['ingredients', activeGroup, 'ingredients', index, 'notes'])}
|
|
|
/>
|
|
/>
|
|
|
<Input
|
|
<Input
|
|
|
label=''
|
|
label=''
|