Verified Commit b1ade63b authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Move all navigation calls to new router saga

parent d96a5c69
import {
call, put, takeEvery, select,
call, put, select, takeEvery,
} from 'redux-saga/effects';
import { Sentry } from 'react-native-sentry';
import { apiRequest, tokenSelector } from '../utils/url';
import * as eventActions from '../actions/event';
import NavigationService from '../navigation';
const event = function* event(action) {
const { pk } = action.payload;
const token = yield select(tokenSelector);
yield put(eventActions.fetching());
yield call(NavigationService.navigate, 'Event');
const data = {
method: 'GET',
......
import { all, fork } from 'redux-saga/effects';
import sessionSaga from './session';
import routerSaga from './router';
import eventSaga from './event';
import profileSaga from './profile';
import welcomeSaga from './welcome';
......@@ -15,6 +16,7 @@ import settingsSaga from './settings';
const sagas = function* sagas() {
yield all([
fork(sessionSaga),
fork(routerSaga),
fork(eventSaga),
fork(profileSaga),
fork(welcomeSaga),
......
......@@ -5,7 +5,6 @@ import { Sentry } from 'react-native-sentry';
import { apiRequest, tokenSelector } from '../utils/url';
import * as pizzaActions from '../actions/pizza';
import NavigationService from '../navigation';
const NOT_FOUND = 404;
......@@ -13,7 +12,6 @@ const retrievePizzaInfo = function* retrievePizzaInfo() {
const token = yield select(tokenSelector);
yield put(pizzaActions.fetching());
yield call(NavigationService.navigate, 'Pizza');
const data = {
method: 'GET',
......
import {
call, put, takeEvery, select,
call, put, select, takeEvery,
} from 'redux-saga/effects';
import { Sentry } from 'react-native-sentry';
import { apiRequest, tokenSelector } from '../utils/url';
import * as profileActions from '../actions/profile';
import NavigationService from '../navigation';
const profile = function* profile(action) {
const { member } = action.payload;
const token = yield select(tokenSelector);
yield put(profileActions.fetching());
yield call(NavigationService.navigate, 'Profile');
const data = {
method: 'GET',
......
......@@ -9,7 +9,6 @@ import { apiRequest, tokenSelector } from '../utils/url';
import * as eventActions from '../actions/event';
import * as registrationActions from '../actions/registration';
import NavigationService from '../navigation';
export const eventSelector = state => state.event.data.pk;
......@@ -68,7 +67,6 @@ const update = function* update(action) {
try {
yield call(apiRequest, `registrations/${registration}`, data);
yield call(NavigationService.goBack);
yield put(registrationActions.success());
yield delay(50);
Snackbar.show({ title: 'Successfully updated registration' });
......@@ -99,7 +97,6 @@ const cancel = function* cancel(action) {
Snackbar.show({ title: 'Successfully cancelled registration' });
} catch (error) {
Sentry.captureException(error);
// Swallow error for now
}
yield put(eventActions.event(event));
......@@ -110,7 +107,6 @@ const fields = function* fields(action) {
const token = yield select(tokenSelector);
yield put(registrationActions.loading());
yield call(NavigationService.navigate, 'Registration');
const data = {
method: 'GET',
......
import { takeEvery, call } from 'redux-saga/effects';
import * as eventActions from '../actions/event';
import * as profileActions from '../actions/profile';
import * as pizzaActions from '../actions/pizza';
import * as registrationActions from '../actions/registration';
import * as sessionActions from '../actions/session';
import NavigationService from '../navigation';
function* event() {
yield call(NavigationService.navigate, 'Event');
}
function* profile() {
yield call(NavigationService.navigate, 'Profile');
}
function* registration() {
yield call(NavigationService.navigate, 'Registration');
}
function* pizza() {
yield call(NavigationService.navigate, 'Pizza');
}
function* signedIn() {
yield call(NavigationService.navigate, 'SignedIn');
}
function* auth() {
yield call(NavigationService.navigate, 'Auth');
}
function* back() {
yield call(NavigationService.goBack);
}
const routerSaga = function* eventSaga() {
yield takeEvery(eventActions.EVENT, event);
yield takeEvery(profileActions.PROFILE, profile);
yield takeEvery(registrationActions.FIELDS, registration);
yield takeEvery(registrationActions.SUCCESS, back);
yield takeEvery(pizzaActions.PIZZA, pizza);
yield takeEvery(sessionActions.SIGNED_IN, signedIn);
yield takeEvery([sessionActions.TOKEN_INVALID, sessionActions.SIGN_OUT], auth);
};
export default routerSaga;
......@@ -8,7 +8,6 @@ import { Sentry } from 'react-native-sentry';
import { apiRequest, tokenSelector } from '../utils/url';
import * as sessionActions from '../actions/session';
import * as pushNotificationsActions from '../actions/pushNotifications';
import NavigationService from '../navigation';
export const USERNAMEKEY = '@MyStore:username';
export const TOKENKEY = '@MyStore:token';
......@@ -43,7 +42,7 @@ function* init() {
yield put(sessionActions.fetchUserInfo());
yield put(pushNotificationsActions.register(pushCategories));
} else {
yield call(NavigationService.navigate, 'Auth');
yield put(sessionActions.tokenInvalid());
}
} catch (e) {
Sentry.captureException(e);
......@@ -86,15 +85,18 @@ function* signIn(action) {
}
}
function* signOut() {
function* clearUserInfo() {
yield call(AsyncStorage.clear);
yield put(pushNotificationsActions.invalidate());
}
function* signOut() {
yield call(clearUserInfo);
Snackbar.show({ title: 'Logout successful' });
}
function* signedIn({ payload }) {
const { username } = payload;
yield call(NavigationService.navigate, 'SignedIn');
yield call(Sentry.setUserContext, { username });
}
......@@ -123,19 +125,13 @@ function* userInfo() {
}
}
function* tokenInvalid() {
yield call(AsyncStorage.clear);
yield put(pushNotificationsActions.invalidate());
yield call(NavigationService.navigate, 'Auth');
}
const sessionSaga = function* sessionSaga() {
yield takeEvery(sessionActions.INIT, init);
yield takeEvery(sessionActions.SIGN_IN, signIn);
yield takeEvery(sessionActions.SIGN_OUT, signOut);
yield takeEvery(sessionActions.SIGNED_IN, signedIn);
yield takeEvery(sessionActions.FETCH_USER_INFO, userInfo);
yield takeEvery(sessionActions.TOKEN_INVALID, tokenInvalid);
yield takeEvery(sessionActions.TOKEN_INVALID, clearUserInfo);
};
export default sessionSaga;
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