Members
(constant) MAIN_API_URL
How to use:
After DATA is initialized automatically:
inside init() function, under "await fetchRecipes();":
call getRecipeCardInfo() to get recipe id,diets,image and title of all fetched recipes
NOTE 1:I store fetched data in DATA. To access DATA, access inside init() function or there will be nothing.
NOTE 2:DATA[0]['results'][0] returns first recipe; DATA[0]['results'][1] returns second one; aka DATA[0]['results'] = recipeData in lab 6
NOTE 3:main link https://spoonacular.com/food-api/docs#Search-Recipes-Complex
- Source:
Methods
addMoreIngredients(ig)
This hepler function adds ingredients to the edit recipe.
Parameters:
Name | Type | Description |
---|---|---|
ig |
string | ingredient |
addMoreInstructions(ins)
This hepler function adds instructions to the edit recipe
Parameters:
Name | Type | Description |
---|---|---|
ins |
string | instruction |
addNewCookBook()
This function ask user to enter new cookbook's name,
store it to local storage and call appendNewCookBook()
addRemoveCookBook(button)
This function removes a cookbook from cookbook List
Parameters:
Name | Type | Description |
---|---|---|
button |
HTMLElement | the button that adds the cookbook |
addRemoveRecipe(button)
This function removes recipe from a cookbook
Parameters:
Name | Type | Description |
---|---|---|
button |
HTMLElement | the button that removes the recipe |
appendNewCookBook(newCookBook)
This function adds new cookbook to the save-cookbook menu
Parameters:
Name | Type | Description |
---|---|---|
newCookBook |
string |
bindAll()
Calls all binding functions above and is called in the init function
bindAppNameClick()
Returns to home when app name is clicked
bindCategoryCards(categoryCard, categoryName)
Binds the click event to the category card to initiate the search
Parameters:
Name | Type | Description |
---|---|---|
categoryCard |
Element | the category card to bind to |
categoryName |
String | the name of the category searched |
bindCookbookPage()
Goes to cookbook page when cookbook is clicked
bindCuisineFilters()
This function adds an event listener waiting for the user to click on the cuisine filters button
and change the direction of the arrow icon which will then call toggleCuisineFilters() method to
either reveal or hide the cuisine filters drop down menu
bindDietFilters()
This function adds an event listener waiting for the user to click on the diet filters button
which will then call toggleDietFilters() method to either reveal or hide the diet filters drop down menu
and change the direction of the arrow icon
bindHomePage()
Goes to home page when home is clicked
bindMealFilters()
This function adds an event listener waiting for the user to click on the meal type filters button
which will then call toggleMealTypeFilters() method to either reveal or hide the meal type filters
drop down menu and change the direction of the arrow icon
bindNewCookBook(li)
This functions bind a cookbook / add an event upon click, so that when users click on a cookbook,
it saves the current recipe to the cookbook that user chose
Parameters:
Name | Type | Description |
---|---|---|
li |
HTMLObjectElement | the cookbook to save to |
bindPopState()
Binds a pop state to a routing page
bindSettingsPage()
Goes to setting page when settings is clicked
bindTimeFilters()
This function adds an event listener waiting for the user to click on the time filters button
which will then call toggleTimeFilters() method to either reveal or hide the time filters drop down menu
and change the direction of the arrow icon
checkBookMark(data)
This function check if the recurrent recipe has been whether saved or not.
If the data has been saved, display bookmark and edit recipe,
and load data from local storage.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object |
clearAllFilters()
This function removes all the filter cards and clears all checkboxes
clearCheckBoxes()
Clears check boxes on a recipe page and list
clearFilterCheckBoxes()
Clears check boxes in the filter drop down menus
createCategoryCards()
Creates 6 category cards from the categories and images arrays above using random
values so every time the user refreshes, there will be a new set of categories
createFilters()
Function to create filter-card elements based off of the selected
filters in the filters array.
emailRecipe()
Open the share recipe modal
(async) fetchRecipes(queries, callbackFn) → {Promise}
Fetch the recipes for the search page
Parameters:
Name | Type | Description |
---|---|---|
queries |
String | string that contains all query parameters for API call |
callbackFn |
function | assigns the value from the fetch to the global variable |
- Source:
Returns:
a Promise for whether or not a recipe has been loaded successfully
- Type
- Promise
getIngredients(data) → {Array}
Extract the ingredients from data
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | JSON |
- Source:
Returns:
return a list of ingredients
- Type
- Array
getInstructions(data) → {Array}
Extract the instructions from data
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | JSON |
- Source:
Returns:
return a list of instructions
- Type
- Array
getRecipeCardInfo(data) → {Array}
Extract needed info of all recipes fetched as an array
Parameters:
Name | Type | Description |
---|---|---|
data |
Array | an array of data for a recipe card |
- Source:
Returns:
an array of extracted data for a recipe card
- Type
- Array
getRecipeCardInfo(data) → {Object}
Extract needed info of all recipes fetched as an array
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | the data of the recipe card |
Returns:
{{diets1,id1,image1,title1},{diets2,id2,image2,title2},...}
- Type
- Object
hideApplyBtn()
This function hides the apply filters button
hideCategoryCards()
Hide category cards
hideClearFiltersBtn()
This function should only be called when no filters are selected, showing, or is on another page like the settings
home, or cookbook page. Thus the clear filters button should only show when a filter is selected but disappear
all other times
hideCookbooks()
Hide cookbooks page
hideEditRecipe()
Hide edit recipe button
hideFilterBtns()
This function hides the filter buttons
hideFilters()
This function hides the filter drop down menus
hideHome()
Hide the home page
hideRecipeCards()
Hide recipe cards
hideRecipePage()
Hide recipe page
hideSearchBar()
Hide search bar
hideSelectedFilters()
This function hides the selected filters container
hideSettings()
Hide the settings
hideTapMode()
Hide tap mode button
(async) init()
When page is initialized, create a home page to show
load()
This function loads all ingredients and instructions to the Edit Recipe popup
printRecipe()
Print a recipe from the recipe page
removeIngredient()
this function removes the last ingredient in the ingredients list
removeInstruction()
This function removes the last intructions in the instructions list
removeRecipe(Id)
This function removes recipe from localstorage
Parameters:
Name | Type | Description |
---|---|---|
Id |
string | of recipe |
resetFilters()
This function removes all the filter cards in order to display new ones
each time a user selects a new filter
search() → {Boolean}
The search function, calls API functoin to fetch all recipes
Generates recipe cards by passing in values into RecipeData
Returns:
Whether search was successful
- Type
- Boolean
(async) searchByCategory() → {Promise}
Function to search when a category card is clicked
Returns:
a Promise whether recipes have been fetched correctly
- Type
- Promise
searchByFilter()
Function to filter the search the by the filters that the user
selects
showApplyBtn()
This function shows the apply filters button
showBookMarkEditReipce()
This helper function display bookmark-filled and display editRecipe
showCategoryCards()
Show category cards
showClearFiltersBtn()
This function just reveals the clear filters button which should only appear after a filter is selected
in any category
showCookBookMenu()
This functions displays all the cookbooks in local storage to the saved-cookbook menu
when users click on bookmark. There is one cookbook by default - "favorites".
If bookmark has been marked/filled. It removes the recipe from local Storage.
showCookbooks()
Show cookbooks page
showCuisineFilters()
This function shows the cuisine filter drop down menu when cuisine button
is clicked
showDietFilters()
This function shows the diet filter drop down menu when diet button
is clicked
showEditRecipe()
Show edit recipe button
showFilterBtns()
This function shows the filter buttons
showHome()
Show home page
showMealFilters()
This function shows the meal filter drop down menu when meal button
is clicked
showRecipeCards()
Show the recipe cards
showRecipePage()
Show recipe page
showSearchBar()
Show the search bar
showSelectedFilters()
This function shows the selected filters container
showSettings()
Shows the Settings page
showTapMode()
Show tap mode button
showTimeFilters()
This function shows the time filter drop down menu when time button
is clicked
submit()
When users hit "save" on edit recipe popup
It save the data to recipe on local storage and reload the RecipePage with info
tapMode()
This function enables tap-mode
- Source:
toggleCuisineFilters()
Function to toggle the cuisine filters each time the cuisine button is clicked
toggleDietFilters()
Function to toggle the diet filters each time the diet button is clicked
toggleEditRecipe()
This function displays the popup menu to edit recipe
toggleMealTypeFilters()
Function to toggle the meal filters each time the meal button is clicked
toggleMenu()
Toggles the Menu list
toggleSaveCookBook()
Displays saved-cookbook menu
toggleTapMode()
Toggles Tap Mode
toggleTimeFilters()
Function to toggle the time filters each time the time button is clicked
updateSettings()
Update global settings for user