diff --git a/src/actions/index.js b/src/actions/index.js new file mode 100644 index 0000000..17aaadf --- /dev/null +++ b/src/actions/index.js @@ -0,0 +1,6 @@ +// export function addTodo(txt) { +// return { +// type: 'ADD_TODO', +// payload: txt, +// } +// } diff --git a/src/index.js b/src/index.js index 449989b..5d8ecc1 100644 --- a/src/index.js +++ b/src/index.js @@ -2,10 +2,27 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './assets/index.css'; import App from './App'; +import reducer from './reducers/index.js' import 'semantic-ui-css/semantic.min.css'; -import { combineReducers, createStore } from 'redux'; +import { createStore } from 'redux'; + + + + +console.log('before createStore'); + +const store = createStore(reducer) + +console.log(store); +console.log('after createStore', store.getState()); + +const action = { + type: "CLICK_EVENT", // ALL CAPS WITH _ +} +store.dispatch(action); +console.log('after CLICK_EVENT', store.getState()); ReactDOM.render(, document.getElementById('root')); @@ -26,6 +43,8 @@ ReactDOM.render(, document.getElementById('root')); ///////OLD REDUX SETUP///////// // +// import { combineReducers, createStore } from 'redux'; +// // function usersReducer(state = [], action){ // return state; // } diff --git a/src/reducers/index.js b/src/reducers/index.js new file mode 100644 index 0000000..3880928 --- /dev/null +++ b/src/reducers/index.js @@ -0,0 +1,46 @@ +const initialState = {} + +const renderState = { + loggedIn: false, + signingUp: false, + viewingProfile: false, + searching: false, +} + +export const reducer = (state = initialState, action) => { + switch(action.type){ + case "LOGGED_IN": + return { + ...state, + ...renderState, + loggedIn: true, + } + case "SIGNING_UP": + return { ...state, + ...renderState, + signingUp: true, + } + case "VIEWING_PROFILE": + return { ...state, + ...renderState, + viewingProfile: true, + } + case "SEARCHING": + return { ...state, + ...renderState, + searching: true + } + return state; + } +} + +export default reducer; + +// HOW I HAD THE ORIGINAL THING +// case "SEARCHING": +// return { ...state, +// loggedIn: false, +// signingUp: false, +// viewingProfile: false, +// searching: true +// }