Commit 8eaec845 authored by Wietse Kuipers's avatar Wietse Kuipers

Refactored navigation and removed redux-thunk

parent 951826ad
export const NAVIGATE = 'NAVIGATE';
export const BACK = 'BACK';
export const OPENDRAWER = 'OPENDRAWER';
export const CALENDARRETREIVED = 'CALENDARRETREIVED';
export const CALENDARERROR = 'CALENDARERROR';
export const RESETLOGINSTATE = 'RESETLOGINSTATE';
export const WELCOME = 'WELCOME';
import * as types from './actionTypes'; export const NAVIGATE = 'NAVIGATE_NAVIGATE';
export const BACK = 'NAVIGATE_BACK';
export const OPENDRAWER = 'NAVIGATE_OPENDRAWER';
export function navigate(scene, newSection = false) { export function navigate(scene, newSection = false) {
return { return {
type: types.NAVIGATE, type: NAVIGATE,
scene, payload: { scene, newSection },
newSection,
}; };
} }
export function back() { export function back() {
return { return {
type: types.BACK, type: BACK,
}; };
} }
export function updateDrawer(drawerState) { export function updateDrawer(drawerState) {
return { return {
type: types.OPENDRAWER, type: OPENDRAWER, payload: { drawerOpen: drawerState },
drawerOpen: drawerState,
}; };
} }
...@@ -2,7 +2,6 @@ import React, { Component } from 'react'; ...@@ -2,7 +2,6 @@ import React, { Component } from 'react';
import { AsyncStorage } from 'react-native'; import { AsyncStorage } from 'react-native';
import { applyMiddleware, combineReducers, createStore } from 'redux'; import { applyMiddleware, combineReducers, createStore } from 'redux';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import createSagaMiddleware from 'redux-saga'; import createSagaMiddleware from 'redux-saga';
import FCM, { FCMEvent } from 'react-native-fcm'; import FCM, { FCMEvent } from 'react-native-fcm';
import Moment from 'moment'; import Moment from 'moment';
...@@ -14,10 +13,9 @@ import ReduxNavigator from './components/navigator'; ...@@ -14,10 +13,9 @@ import ReduxNavigator from './components/navigator';
import * as loginActions from './actions/login'; import * as loginActions from './actions/login';
import { register } from './actions/pushNotifications'; import { register } from './actions/pushNotifications';
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
const sagaMiddleware = createSagaMiddleware(); const sagaMiddleware = createSagaMiddleware();
const reducer = combineReducers(reducers); const reducer = combineReducers(reducers);
const store = createStoreWithMiddleware(reducer, applyMiddleware(thunk, sagaMiddleware)); const store = createStore(reducer, applyMiddleware(sagaMiddleware));
sagaMiddleware.run(sagas); sagaMiddleware.run(sagas);
const USERNAMEKEY = '@MyStore:username'; const USERNAMEKEY = '@MyStore:username';
......
import * as types from '../actions/actionTypes'; import * as navigationActions from '../actions/navigation';
import * as loginActions from '../actions/login'; import * as loginActions from '../actions/login';
const initialState = { const initialState = {
...@@ -18,7 +18,7 @@ export default function navigate(state = initialState, action = {}) { ...@@ -18,7 +18,7 @@ export default function navigate(state = initialState, action = {}) {
loggedIn: true, loggedIn: true,
}; };
} }
case types.BACK: { case navigationActions.BACK: {
if (drawerOpen) { if (drawerOpen) {
return { return {
...state, ...state,
...@@ -32,17 +32,17 @@ export default function navigate(state = initialState, action = {}) { ...@@ -32,17 +32,17 @@ export default function navigate(state = initialState, action = {}) {
currentScene: scene, currentScene: scene,
}; };
} }
case types.NAVIGATE: { case navigationActions.NAVIGATE: {
if (action.scene === currentScene) { if (action.payload.scene === currentScene) {
return { return {
...state, ...state,
drawerOpen: false, drawerOpen: false,
}; };
} else if (action.newSection) { } else if (action.payload.newSection) {
return { return {
...state, ...state,
previousScenes: [], previousScenes: [],
currentScene: action.scene, currentScene: action.payload.scene,
drawerOpen: false, drawerOpen: false,
}; };
} }
...@@ -52,14 +52,14 @@ export default function navigate(state = initialState, action = {}) { ...@@ -52,14 +52,14 @@ export default function navigate(state = initialState, action = {}) {
...previousScenes, ...previousScenes,
currentScene, currentScene,
], ],
currentScene: action.scene, currentScene: action.payload.scene,
drawerOpen: false, drawerOpen: false,
}; };
} }
case types.OPENDRAWER: { case navigationActions.OPENDRAWER: {
return { return {
...state, ...state,
drawerOpen: action.drawerOpen, drawerOpen: action.payload.drawerOpen,
}; };
} }
case loginActions.LOGOUT: { case loginActions.LOGOUT: {
......
import { call, put, select, takeEvery } from 'redux-saga/effects'; import { call, put, select, takeEvery } from 'redux-saga/effects';
import { apiRequest, tokenSelector } from '../url'; import { apiRequest, tokenSelector } from '../url';
import * as types from '../actions/actionTypes'; import * as navigationActions from '../actions/navigation';
import * as calendarActions from '../actions/calendar'; import * as calendarActions from '../actions/calendar';
const calendar = function* calendar() { const calendar = function* calendar() {
...@@ -37,7 +37,7 @@ const calendar = function* calendar() { ...@@ -37,7 +37,7 @@ const calendar = function* calendar() {
const calendarSaga = function* eventSaga() { const calendarSaga = function* eventSaga() {
yield takeEvery([ yield takeEvery([
calendarActions.REFRESH, calendarActions.REFRESH,
action => action.type === types.NAVIGATE && action.scene === 'eventList', action => action.type === navigationActions.NAVIGATE && action.payload.scene === 'eventList',
], calendar); ], calendar);
}; };
......
...@@ -29,8 +29,7 @@ ...@@ -29,8 +29,7 @@
"react-native-vector-icons": "^4.0.1", "react-native-vector-icons": "^4.0.1",
"react-redux": "^5.0.2", "react-redux": "^5.0.2",
"redux": "^3.6.0", "redux": "^3.6.0",
"redux-saga": "^0.15.6", "redux-saga": "^0.15.6"
"redux-thunk": "^2.2.0"
}, },
"devDependencies": { "devDependencies": {
"babel-eslint": "^7.1.1", "babel-eslint": "^7.1.1",
......
...@@ -4286,10 +4286,6 @@ redux-saga@^0.15.6: ...@@ -4286,10 +4286,6 @@ redux-saga@^0.15.6:
version "0.15.6" version "0.15.6"
resolved "https://registry.yarnpkg.com/redux-saga/-/redux-saga-0.15.6.tgz#8638dc522de6c6c0a496fe8b2b5466287ac2dc4d" resolved "https://registry.yarnpkg.com/redux-saga/-/redux-saga-0.15.6.tgz#8638dc522de6c6c0a496fe8b2b5466287ac2dc4d"
redux-thunk@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.2.0.tgz#e615a16e16b47a19a515766133d1e3e99b7852e5"
redux@^3.6.0: redux@^3.6.0:
version "3.7.2" version "3.7.2"
resolved "https://registry.yarnpkg.com/redux/-/redux-3.7.2.tgz#06b73123215901d25d065be342eb026bc1c8537b" resolved "https://registry.yarnpkg.com/redux/-/redux-3.7.2.tgz#06b73123215901d25d065be342eb026bc1c8537b"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment