File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ import { IIngredient } from "../../../types";
55
66import * as API from "../api" ;
77
8- const loadAllIngredients = API . getIngredients ( ) ;
8+ export const loadAllIngredients = API . getIngredients ( ) ;
9+
910
1011const normalize = ( str : string ) =>
1112 str . normalize ( "NFD" ) . replace ( / [ \u0300 - \u036f ] / g, "" ) . toLowerCase ( ) ;
Original file line number Diff line number Diff line change 11import * as React from 'react' ;
22import './searchform.css' ;
33
4- import { IngredientList } from './IngredientList' ;
4+ import { IngredientList , loadAllIngredients } from './IngredientList' ;
55import { IIngredient } from "../../../types" ;
66import { useTipsySelector } from '../tipsyselector/tipsyselector' ;
77
8+ const DEFAULT_INGREDIENTS = [
9+ "carbonated water" ,
10+ "coffee" ,
11+ "cola" ,
12+ "crushed ice" ,
13+ "cow's milk" ,
14+ "drinking water" ,
15+ "ice" ,
16+ "sugar" ,
17+ "milk" ,
18+ "water" ,
19+ ] ;
20+
821function SearchForm ( {
922 submit
1023} : {
@@ -14,6 +27,13 @@ function SearchForm({
1427 const [ ingredients , setIngredients ] = React . useState < IIngredient [ ] > ( [ ] ) ;
1528 const [ tipsySelectorEl , promille ] = useTipsySelector ( { rangeOptions : { min : .3 , max : 2 } } ) ;
1629
30+ // If the ingredients were loaded before the user started adding some,
31+ // prefill the ingredient list with something basically everyone has
32+ React . useEffect ( ( ) => {
33+ loadAllIngredients
34+ . then ( result => setIngredients ( prev => prev . length ? prev : result . ingredients . filter ( it => DEFAULT_INGREDIENTS . includes ( it . name ) ) ) ) ;
35+ } , [ ] ) ;
36+
1737 return (
1838 < >
1939 < div className = "segment" >
You can’t perform that action at this time.
0 commit comments