-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetching
ingredients
Asynchronously from the Firebase-Backend
- Loading branch information
Showing
5 changed files
with
47 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export const ADD_INGREDIENT = "ADD_INGREDIENT"; | ||
export const REMOVE_INGREDIENT = "REMOVE_INGREDIENT"; | ||
export const SET_INGREDIENTS = "SET_INGREDIENTS"; | ||
export const FETCH_INGREDIENTS_FAILED = "FETCH_INGREDIENTS_FAILED"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,50 @@ | ||
import * as actionTypes from "./actionTypes"; | ||
import axios from "../../axios-orders"; | ||
|
||
export const addIngredient = ingName => { | ||
return { | ||
type: actionTypes.ADD_INGREDIENT, | ||
ingredientName: ingName, | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
export const removeIngredient = ingName => { | ||
return { | ||
type: actionTypes.REMOVE_INGREDIENT, | ||
ingredientName: ingName, | ||
}; | ||
}; | ||
|
||
export const setIngredients = ingredients => { | ||
return { | ||
type: actionTypes.SET_INGREDIENTS, | ||
ingredients | ||
}; | ||
}; | ||
|
||
export const fetchIngredientsFailed = () => { | ||
return { | ||
type: actionTypes.FETCH_INGREDIENTS_FAILED, | ||
} | ||
} | ||
|
||
/** | ||
* Fetch the default ingredients data from the DB here: | ||
* https://burger-builder-ram.firebaseio.com/ingredients | ||
* | ||
* NOTE: we have to append `.json` at the end of the API | ||
* endpoint in case of firebase db. | ||
*/ | ||
export const initIngredients = () => { | ||
return dispatch => { | ||
axios | ||
.get("https://burger-builder-ram.firebaseio.com/ingredients.json") | ||
.then(response => { | ||
dispatch(setIngredients(response.data)); | ||
}) | ||
.catch(error => { | ||
dispatch(fetchIngredientsFailed()); | ||
return error; | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters