diff --git a/src/components/App.js b/src/components/App.js
index 9e8e46c..7fd9e5a 100644
--- a/src/components/App.js
+++ b/src/components/App.js
@@ -1,6 +1,10 @@
import React, { Component } from "react";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
+// Store
+import { Provider } from "react-redux";
+import store from "../redux/store";
+
// Routes
import Migrations from "./root/Pages/Migrations";
import GenericList from "./root/Pages/GenericList";
@@ -11,46 +15,79 @@ import IDSingle from "./root/Pages/IDSingle";
import Home from "./root/Home";
import Navigation from "./root/Navigation";
-
// Main app component, react-router comes from here,
// and links to all of the sub pages
class App extends Component {
render() {
return (
-
-
+
+
-
-
-
-
-
-
- (
-
- )} />
- (
-
- )} />
- (
-
- )} />
- (
-
- )} />
- (
-
- )} />
- (
-
- )} />
- (
-
- )} />
-
-
-
+
+
+
+
+
+
+
+
+
+ (
+
+ )}
+ />
+ (
+
+ )}
+ />
+ (
+
+ )}
+ />
+ (
+
+ )}
+ />
+ (
+
+ )}
+ />
+ (
+
+ )}
+ />
+ (
+
+ )}
+ />
+
+
+
+
+
+
);
}
}
diff --git a/src/redux/constants/action-types.js b/src/redux/constants/action-types.js
new file mode 100644
index 0000000..2cd04ee
--- /dev/null
+++ b/src/redux/constants/action-types.js
@@ -0,0 +1,3 @@
+export const ADD_ARTICLE = "ADD_ARTICLE";
+export const DATA_LOADED = "DATA_LOADED";
+export const API_ERRORED = "API_ERRORED";
diff --git a/src/redux/middleware/index.js b/src/redux/middleware/index.js
new file mode 100644
index 0000000..c2e8e83
--- /dev/null
+++ b/src/redux/middleware/index.js
@@ -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);
+ };
+ };
+}
diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js
new file mode 100644
index 0000000..b0c6c83
--- /dev/null
+++ b/src/redux/reducers/index.js
@@ -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;
diff --git a/src/redux/store/index.js b/src/redux/store/index.js
new file mode 100644
index 0000000..ead6a0f
--- /dev/null
+++ b/src/redux/store/index.js
@@ -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;