This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<title>React Router Example</title> | |
</head> | |
<body> |
This file contains hidden or 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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { Provider } from 'react-redux'; | |
// We will need to import this from redux to create our store and make use of the thunk | |
import { createStore, applyMiddleware } from 'redux'; | |
// Dont forget to import redux thunk | |
import thunk from 'redux-thunk'; | |
// Getting our combined reducers | |
import reducers from './reducers/reducers'; | |
// And our Recipe component |
This file contains hidden or 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
import React, { Component } from 'react'; | |
import { connect } from 'react-redux'; | |
// Remember our thunk this is where we will need to make use of it | |
import { recipesFetchData } from '../actions/actions.js'; | |
// We gonna use lodash to map over our recipe object | |
import _ from 'lodash' | |
class Recipe extends Component { | |
constructor(props) { | |
super(props); |
This file contains hidden or 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
import { combineReducers } from 'redux'; | |
import getRecipes from './recipe_actions/get_recipes.js'; | |
import loadingRecipes from './recipe_actions/loading_recipes.js'; | |
const reducers = combineReducers({ | |
recipes: getRecipes, | |
loadRecipes: loadingRecipes, | |
}); | |
export default reducers; |
This file contains hidden or 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
import { LOADING_RECIPES } from '../../actions/actions'; | |
export default function loadingRecipes(state = true, action) { | |
switch (action.type) { | |
case LOADING_RECIPES: | |
return action.payload; | |
} | |
return state; | |
} |
This file contains hidden or 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
import { GET_RECIPES } from '../../actions/actions'; | |
export default function getRecipe(state = {}, action) { | |
switch (action.type) { | |
case GET_RECIPES: | |
return action.payload | |
} | |
return state; | |
} |
This file contains hidden or 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
import axios from 'axios'; | |
// Exporting our actions | |
export const LOADING_RECIPES = 'LOADING_RECIPES'; | |
export const GET_RECIPES = 'GET_RECIPES'; | |
// An action to check if the recipes are loaded accepts true or false | |
export function loadingRecipes(loading) { | |
return { | |
type: LOADING_RECIPES, |
This file contains hidden or 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
// Then to get access to our API route we will use importer | |
var importRoutes = keystone.importer(__dirname); | |
// And finally set up the api on a route | |
var routes = { | |
api: importRoutes('./api'), | |
}; | |
// Export our app routes | |
exports = module.exports = function (app) { | |
// Get access to the API route in our app |
This file contains hidden or 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
var keystone = require('keystone'); | |
/** | |
* List Recipe | |
*/ | |
// Getting our recipe model | |
var Recipe = keystone.list('Recipe'); | |
// Creating the API end point |
This file contains hidden or 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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { Provider } from 'react-redux'; | |
// This will be the entry point of our app | |
const App = () => { | |
return ( | |
// We will add our components here | |
<div /> | |
); |