Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Whats_In_Your_Fridge
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CI102-3TeamL
Whats_In_Your_Fridge
Commits
ef6c975b
Commit
ef6c975b
authored
3 years ago
by
zh393
Browse files
Options
Downloads
Patches
Plain Diff
migrated API to premium version
parent
195c0d1e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pages/recipe/Recipe.js
+20
-20
20 additions, 20 deletions
src/pages/recipe/Recipe.js
src/pages/results/Results.js
+31
-32
31 additions, 32 deletions
src/pages/results/Results.js
with
51 additions
and
52 deletions
src/pages/recipe/Recipe.js
+
20
−
20
View file @
ef6c975b
import
React
,
{
useEffect
,
useState
}
from
'
react
'
import
{
useParams
}
from
"
react-router-dom
"
import
axios
from
"
axios
"
import
{
Container
,
Typography
}
from
'
@mui/material
'
;
import
parse
from
'
html-react-parser
'
;
var
axios
=
require
(
"
axios
"
).
default
;
function
Recipe
()
{
const
{
id
}
=
useParams
();
const
[
data
,
setData
]
=
useState
([]);
useEffect
(()
=>
{
const
params
=
new
URLSearchParams
({
apiKey
:
"
4ce04e457c8348cfaec8ee0c7100b2f8
"
,
includeNutrition
:
true
})
let
base_url
=
`https://api.spoonacular.com/recipes/
${
id
}
/information`
let
url
=
base_url
+
"
?
"
+
params
.
toString
()
let
resp
=
axios
({
url
:
url
,
method
:
"
get
"
,
var
options
=
{
method
:
'
GET
'
,
url
:
`https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/
${
id
}
/information`
,
params
:
{
includeNutrition
:
'
true
'
},
headers
:
{
"
Content-Type
"
:
"
application/json
"
'
x-rapidapi-host
'
:
'
spoonacular-recipe-food-nutrition-v1.p.rapidapi.com
'
,
'
x-rapidapi-key
'
:
'
9488865383msh30a38be9ec16e99p109d9bjsn9090d29ce12f
'
}
})
};
axios
.
request
(
options
).
then
(
function
(
response
)
{
setData
(
response
.
data
);
}).
catch
(
function
(
error
)
{
console
.
error
(
error
);
});
resp
.
then
(
r
=>
setData
(
r
.
data
));
},
[])
// eslint-disable-line react-hooks/exhaustive-deps
let
body
=
<
Typography
variant
=
"
p
"
>
Loading
...
<
/Typography>
;
...
...
This diff is collapsed.
Click to expand it.
src/pages/results/Results.js
+
31
−
32
View file @
ef6c975b
import
{
Container
,
Typography
}
from
'
@mui/material
'
import
axios
from
'
axios
'
import
React
,
{
useState
,
useEffect
}
from
'
react
'
import
{
useLocation
,
Link
}
from
"
react-router-dom
"
var
axios
=
require
(
"
axios
"
).
default
;
function
Results
()
{
...
...
@@ -12,27 +12,26 @@ function Results() {
let
ingredientNames
=
""
location
.
state
.
items
.
forEach
(
ingredient
=>
ingredientNames
+=
ingredient
+
"
,
"
);
ingredientNames
=
ingredientNames
.
slice
(
0
,
-
1
);
// remove the last comma
const
params
=
new
URLSearchParams
({
apiKey
:
"
4ce04e457c8348cfaec8ee0c7100b2f8
"
,
ingredients
:
ingredientNames
})
let
base_url
=
"
https://api.spoonacular.com/recipes/findByIngredients
"
let
url
=
base_url
+
"
?
"
+
params
.
toString
()
let
resp
=
axios
({
url
:
url
,
method
:
"
get
"
,
var
options
=
{
method
:
'
GET
'
,
url
:
'
https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/findByIngredients
'
,
params
:
{
ingredients
:
ingredientNames
,
number
:
'
10
'
,
ignorePantry
:
'
true
'
,
ranking
:
'
2
'
},
headers
:
{
"
Content-Type
"
:
"
application/json
"
'
x-rapidapi-host
'
:
'
spoonacular-recipe-food-nutrition-v1.p.rapidapi.com
'
,
'
x-rapidapi-key
'
:
'
9488865383msh30a38be9ec16e99p109d9bjsn9090d29ce12f
'
}
})
resp
.
then
(
r
=>
{
setRecipes
(
r
.
data
);
})
};
axios
.
request
(
options
).
then
(
function
(
response
)
{
setRecipes
(
response
.
data
);
}).
catch
(
function
(
error
)
{
console
.
error
(
error
);
});
},
[])
// eslint-disable-line react-hooks/exhaustive-deps
const
recipeComponent
=
recipes
.
map
(
recipe
=>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment