Added a basic store, fleshing out for our use, including actions relevant to migationsTracker
This commit is contained in:
parent
271942ae7f
commit
a3c380ffd1
@ -1,6 +1,10 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
|
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
|
||||||
|
|
||||||
|
// Store
|
||||||
|
import { Provider } from "react-redux";
|
||||||
|
import store from "../redux/store";
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
import Migrations from "./root/Pages/Migrations";
|
import Migrations from "./root/Pages/Migrations";
|
||||||
import GenericList from "./root/Pages/GenericList";
|
import GenericList from "./root/Pages/GenericList";
|
||||||
@ -11,46 +15,79 @@ import IDSingle from "./root/Pages/IDSingle";
|
|||||||
import Home from "./root/Home";
|
import Home from "./root/Home";
|
||||||
import Navigation from "./root/Navigation";
|
import Navigation from "./root/Navigation";
|
||||||
|
|
||||||
|
|
||||||
// Main app component, react-router comes from here,
|
// Main app component, react-router comes from here,
|
||||||
// and links to all of the sub pages
|
// and links to all of the sub pages
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Router>
|
<Provider store={store}>
|
||||||
<div className="container-fluid">
|
<Router>
|
||||||
<Navigation />
|
<Navigation />
|
||||||
<Switch>
|
<div className="row">
|
||||||
<Route exact path="/" component={Home} />
|
<div className="col s12 m4 13">
|
||||||
<Route exact path="/book" component={Book} />
|
<div className="container-fluid">
|
||||||
<Route exact path="/migrations" component={Migrations} />
|
<Switch>
|
||||||
<Route exact path="/reports" component={Reports} />
|
<Route exact path="/" component={Home} />
|
||||||
<Route path="/migrations/:migrationId" component={IDSingle} />
|
<Route exact path="/book" component={Book} />
|
||||||
<Route exact path="/upcoming-migrations" render={(props) => (
|
<Route exact path="/migrations" component={Migrations} />
|
||||||
<GenericList {...props} APILINK="/pending/" />
|
<Route exact path="/reports" component={Reports} />
|
||||||
)} />
|
<Route path="/migrations/:migrationId" component={IDSingle} />
|
||||||
<Route exact path="/missed" render={(props) => (
|
<Route
|
||||||
<GenericList {...props} APILINK="/missed/" />
|
exact
|
||||||
)} />
|
path="/upcoming-migrations"
|
||||||
<Route exact path="/completed" render={(props) => (
|
render={(props) => (
|
||||||
<GenericList {...props} APILINK="/completed/" />
|
<GenericList {...props} APILINK="/pending/" />
|
||||||
)} />
|
)}
|
||||||
<Route exact path="/pending-terminations" render={(props) => (
|
/>
|
||||||
<GenericList {...props} APILINK="/waitingterm/" />
|
<Route
|
||||||
)} />
|
exact
|
||||||
<Route exact path="/all-terminations" render={(props) => (
|
path="/missed"
|
||||||
<GenericList {...props} APILINK="/pendingterm/" />
|
render={(props) => (
|
||||||
)} />
|
<GenericList {...props} APILINK="/missed/" />
|
||||||
<Route exact path="/historical-migrations" render={(props) => (
|
)}
|
||||||
<GenericList {...props} APILINK="/all/" />
|
/>
|
||||||
)} />
|
<Route
|
||||||
<Route exact path="/booked" render={(props) => (
|
exact
|
||||||
<GenericList {...props} APILINK="/booked/" />
|
path="/completed"
|
||||||
)} />
|
render={(props) => (
|
||||||
</Switch>
|
<GenericList {...props} APILINK="/completed/" />
|
||||||
</div>
|
)}
|
||||||
</Router>
|
/>
|
||||||
|
<Route
|
||||||
|
exact
|
||||||
|
path="/pending-terminations"
|
||||||
|
render={(props) => (
|
||||||
|
<GenericList {...props} APILINK="/waitingterm/" />
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
exact
|
||||||
|
path="/all-terminations"
|
||||||
|
render={(props) => (
|
||||||
|
<GenericList {...props} APILINK="/pendingterm/" />
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
exact
|
||||||
|
path="/historical-migrations"
|
||||||
|
render={(props) => (
|
||||||
|
<GenericList {...props} APILINK="/all/" />
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
exact
|
||||||
|
path="/booked"
|
||||||
|
render={(props) => (
|
||||||
|
<GenericList {...props} APILINK="/booked/" />
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Switch>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Router>
|
||||||
|
</Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
src/redux/constants/action-types.js
Normal file
3
src/redux/constants/action-types.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export const ADD_ARTICLE = "ADD_ARTICLE";
|
||||||
|
export const DATA_LOADED = "DATA_LOADED";
|
||||||
|
export const API_ERRORED = "API_ERRORED";
|
||||||
21
src/redux/middleware/index.js
Normal file
21
src/redux/middleware/index.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { ADD_ARTICLE } from "../constants/action-types";
|
||||||
|
|
||||||
|
const forbiddenWords = ["spam", "money"];
|
||||||
|
|
||||||
|
export function forbiddenWordsMiddleware({ dispatch }) {
|
||||||
|
return function (next) {
|
||||||
|
return function (action) {
|
||||||
|
// do your stuff
|
||||||
|
if (action.type === ADD_ARTICLE) {
|
||||||
|
const foundWord = forbiddenWords.filter((word) =>
|
||||||
|
action.payload.title.includes(word)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (foundWord.length) {
|
||||||
|
return dispatch({ type: "FOUND_BAD_WORD" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return next(action);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
23
src/redux/reducers/index.js
Normal file
23
src/redux/reducers/index.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { ADD_ARTICLE, DATA_LOADED } from "../constants/action-types";
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
articles: [],
|
||||||
|
remoteArticles: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
function rootReducer(state = initialState, action) {
|
||||||
|
if (action.type === ADD_ARTICLE) {
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
articles: state.articles.concat(action.payload),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action.type === DATA_LOADED) {
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
remoteArticles: state.remoteArticles.concat(action.payload),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default rootReducer;
|
||||||
13
src/redux/store/index.js
Normal file
13
src/redux/store/index.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { createStore, applyMiddleware, compose } from "redux";
|
||||||
|
import rootReducer from "../reducers";
|
||||||
|
import { forbiddenWordsMiddleware } from "../middleware";
|
||||||
|
import thunk from "redux-thunk";
|
||||||
|
|
||||||
|
const storeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
||||||
|
|
||||||
|
const store = createStore(
|
||||||
|
rootReducer,
|
||||||
|
storeEnhancers(applyMiddleware(forbiddenWordsMiddleware, thunk))
|
||||||
|
);
|
||||||
|
|
||||||
|
export default store;
|
||||||
Reference in New Issue
Block a user