@@ -55,36 +55,46 @@ class SearchForm extends Component {
5555 }
5656
5757 onSubmit ( e ) {
58- // var params = new URLSearchParams();
59- // params.append("q", "chicken");
60- // params.append("app_id", process.env.REACT_APP_API_ID);
61- // params.append("app_key", process.env.REACT_APP_API_KEY);
62- // params.append("from", 0);
63- // params.append("to", 3);
64- // params.append("excluded", "ginger");
65- // params.append("excluded", "garlic");
66- axios . get ( process . env . REACT_APP_API_URL , {
67- headers : { "Access-Control-Allow-Origin" : "*" } ,
68- params : {
69- q : this . state . haveIngredients ,
70- app_id : process . env . REACT_APP_API_ID ,
71- app_key : process . env . REACT_APP_API_KEY ,
72- from : start ,
73- to : start + count ,
74- diet : this . state . specificDiets ,
75- health : this . state . allergies ,
76- excluded : this . state . dontHaveIngredients
77- } ,
78- paramsSerializer : function ( params ) {
79- return qs . stringify ( params , { arrayFormat : 'repeat' } )
80- } ,
81- } ) . then ( response => {
82- console . log ( response . data )
83- this . setState ( { displayFetchedRecipes : response . data . hits } )
84- } )
85- . catch ( error => console . log ( error ) )
86- this . handleReset ( )
58+ if ( this . state . haveIngredients . length > 0 ) {
59+ axios . get ( process . env . REACT_APP_API_URL , {
60+ headers : { "Access-Control-Allow-Origin" : "*" } ,
61+ params : {
62+ q : this . state . haveIngredients ,
63+ app_id : process . env . REACT_APP_API_ID , //remove if not required
64+ app_key : process . env . REACT_APP_API_KEY , //remove if not required
65+ from : start , //index starting point
66+ to : start + count , //index end point
67+ diet : this . state . specificDiets ,
68+ health : this . state . allergies ,
69+ excluded : this . state . dontHaveIngredients
70+ } ,
71+ paramsSerializer : function ( params ) { //to pass arrays
72+ return qs . stringify ( params , { arrayFormat : 'repeat' } )
73+ } ,
74+ } ) . then ( response => {
75+ console . log ( response . data . hits )
76+ this . setState ( { displayFetchedRecipes : response . data . hits } )
77+ } )
78+ . catch ( error => console . log ( error ) )
79+ }
80+ else {
81+ alert ( "Please select atleast one Ingredient" )
82+ }
83+ // this.handleReset() //does not work
8784 e . preventDefault ( )
85+ // update as per fieldname in database
86+ // time: this.state.maxTime,
87+ // includeIngredients: this.state.haveIngredients,
88+ // excludeIngredients: this.state.dontHaveIngredients,
89+ // allergy: this.state.allergies,
90+ // diet: this.state.specificDiets,
91+ // likeCuisines: this.state.likeCuisines,
92+ // ignoreCuisines: this.state.dontLikeCuisines,
93+ // wantCourses: this.state.wantCourses,
94+ // excludeCourses: this.state.dontWantCourses,
95+ // wantdays: this.state.wantOnHolidays,
96+ // excludedays: this.state.dontWantOnHolidays,
97+
8898 }
8999 updateMaxTime ( ) {
90100 var time = window . document . getElementById ( 'time' ) . value
@@ -153,7 +163,7 @@ class SearchForm extends Component {
153163 placeholder = "Maximum Cooking Time in Minutes" />
154164 </ Col >
155165 </ InputGroup >
156- < br />
166+
157167 < InputGroup size = "large" { ...formItemLayout } >
158168 < Ingredient updateIng = { this . updateHaveIngredients . bind ( this ) }
159169 sign = { true } passedSelected = { this . state . dontHaveIngredients }
@@ -163,7 +173,7 @@ class SearchForm extends Component {
163173 placeholder = "Ingredients you don't have" />
164174
165175 </ InputGroup >
166- < br />
176+
167177 < InputGroup size = "large" { ...formItemLayout } >
168178 < Col span = "12" >
169179 < Allergy updateAllergy = { this . updateAllergies . bind ( this ) } />
@@ -174,7 +184,7 @@ class SearchForm extends Component {
174184
175185 </ Col >
176186 </ InputGroup >
177- < br />
187+
178188 < InputGroup size = "large" { ...formItemLayout } >
179189 < Cuisine updateCuisines = { this . updateLikeCuisines . bind ( this ) }
180190 passedSelected = { this . state . dontLikeCuisines } sign = { true }
@@ -183,7 +193,7 @@ class SearchForm extends Component {
183193 passedSelected = { this . state . likeCuisines } sign = { false }
184194 placeholder = "Cuisines you don't like" />
185195 </ InputGroup >
186- < br />
196+
187197 < InputGroup size = "large" { ...formItemLayout } >
188198 < Course updateCourses = { this . updateWantCourses . bind ( this ) }
189199 passedSelected = { this . state . dontWantCourses } sign = { true }
@@ -192,7 +202,7 @@ class SearchForm extends Component {
192202 passedSelected = { this . state . wantCourses } sign = { false }
193203 placeholder = "Courses You don't want" />
194204 </ InputGroup >
195- < br />
205+
196206 < InputGroup size = "large" { ...formItemLayout } >
197207 < Holiday updateHoliday = { this . updateWantOnHolidays . bind ( this ) }
198208 sign = { true } passedSelected = { this . state . dontWantOnHolidays }
@@ -201,7 +211,7 @@ class SearchForm extends Component {
201211 sign = { false } passedSelected = { this . state . wantOnHolidays }
202212 placeholder = "Holidays/Specific You don't want" />
203213 </ InputGroup >
204- < br />
214+
205215
206216 < Button type = "primary" htmlType = "submit" icon = "search" >
207217 Search Recipes
0 commit comments