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) {
return {
type: types.NAVIGATE,
scene,
newSection,
type: NAVIGATE,
payload: { scene, newSection },
};
}
export function back() {
return {
type: types.BACK,
type: BACK,
};
}
export function updateDrawer(drawerState) {
return {
type: types.OPENDRAWER,
drawerOpen: drawerState,
type: OPENDRAWER, payload: { drawerOpen: drawerState },
};
}
......@@ -2,7 +2,6 @@ import React, { Component } from 'react';
import { AsyncStorage } from 'react-native';
import { applyMiddleware, combineReducers, createStore } from 'redux';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import createSagaMiddleware from 'redux-saga';
import FCM, { FCMEvent } from 'react-native-fcm';
import Moment from 'moment';
......@@ -14,10 +13,9 @@ import ReduxNavigator from './components/navigator';
import * as loginActions from './actions/login';
import { register } from './actions/pushNotifications';
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
const sagaMiddleware = createSagaMiddleware();
const reducer = combineReducers(reducers);
const store = createStoreWithMiddleware(reducer, applyMiddleware(thunk, sagaMiddleware));
const store = createStore(reducer, applyMiddleware(sagaMiddleware));
sagaMiddleware.run(sagas);
const USERNAMEKEY = '@MyStore:username';
......
import * as types from '../actions/actionTypes';
import * as navigationActions from '../actions/navigation';
import * as loginActions from '../actions/login';
const initialState = {
......@@ -18,7 +18,7 @@ export default function navigate(state = initialState, action = {}) {
loggedIn: true,
};
}
case types.BACK: {
case navigationActions.BACK: {
if (drawerOpen) {
return {
...state,
......@@ -32,17 +32,17 @@ export default function navigate(state = initialState, action = {}) {
currentScene: scene,
};
}
case types.NAVIGATE: {
if (action.scene === currentScene) {
case navigationActions.NAVIGATE: {
if (action.payload.scene === currentScene) {
return {
...state,
drawerOpen: false,
};
} else if (action.newSection) {
} else if (action.payload.newSection) {
return {
...state,
previousScenes: [],
currentScene: action.scene,
currentScene: action.payload.scene,
drawerOpen: false,
};
}
......@@ -52,14 +52,14 @@ export default function navigate(state = initialState, action = {}) {
...previousScenes,
currentScene,
],
currentScene: action.scene,
currentScene: action.payload.scene,
drawerOpen: false,
};
}
case types.OPENDRAWER: {
case navigationActions.OPENDRAWER: {
return {
...state,
drawerOpen: action.drawerOpen,
drawerOpen: action.payload.drawerOpen,
};
}
case loginActions.LOGOUT: {
......
import { call, put, select, takeEvery } from 'redux-saga/effects';
import { apiRequest, tokenSelector } from '../url';
import * as types from '../actions/actionTypes';
import * as navigationActions from '../actions/navigation';
import * as calendarActions from '../actions/calendar';
const calendar = function* calendar() {
......@@ -37,7 +37,7 @@ const calendar = function* calendar() {
const calendarSaga = function* eventSaga() {
yield takeEvery([
calendarActions.REFRESH,
action => action.type === types.NAVIGATE && action.scene === 'eventList',
action => action.type === navigationActions.NAVIGATE && action.payload.scene === 'eventList',
], calendar);
};
......
......@@ -29,8 +29,7 @@
"react-native-vector-icons": "^4.0.1",
"react-redux": "^5.0.2",
"redux": "^3.6.0",
"redux-saga": "^0.15.6",
"redux-thunk": "^2.2.0"
"redux-saga": "^0.15.6"
},
"devDependencies": {
"babel-eslint": "^7.1.1",
......
......@@ -4286,10 +4286,6 @@ redux-saga@^0.15.6:
version "0.15.6"
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:
version "3.7.2"
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