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

Move screen scenes to constant

parent cfee4808
...@@ -8,6 +8,7 @@ import calendarSaga from '../../app/sagas/calendar'; ...@@ -8,6 +8,7 @@ import calendarSaga from '../../app/sagas/calendar';
import * as calendarActions from '../../app/actions/calendar'; import * as calendarActions from '../../app/actions/calendar';
import * as navActions from '../../app/actions/navigation'; import * as navActions from '../../app/actions/navigation';
import { EVENT_LIST_SCENE } from '../../app/ui/components/navigator/scenes';
jest.mock('../../app/utils/url', () => ({ jest.mock('../../app/utils/url', () => ({
apiRequest: jest.fn(() => {}), apiRequest: jest.fn(() => {}),
...@@ -31,7 +32,7 @@ describe('calendar saga', () => { ...@@ -31,7 +32,7 @@ describe('calendar saga', () => {
[select(tokenSelector), 'token'], [select(tokenSelector), 'token'],
[matchers.call.fn(apiRequest), []], [matchers.call.fn(apiRequest), []],
]) ])
.dispatch(navActions.navigate('eventList')) .dispatch(navActions.navigate(EVENT_LIST_SCENE))
.put(calendarActions.fetching()) .put(calendarActions.fetching())
.silentRun()); .silentRun());
......
...@@ -8,6 +8,7 @@ import * as navigationActions from '../../app/actions/navigation'; ...@@ -8,6 +8,7 @@ import * as navigationActions from '../../app/actions/navigation';
import * as eventActions from '../../app/actions/event'; import * as eventActions from '../../app/actions/event';
import * as loginActions from '../../app/actions/login'; import * as loginActions from '../../app/actions/login';
import * as pizzaActions from '../../app/actions/pizza'; import * as pizzaActions from '../../app/actions/pizza';
import { EVENT_LIST_SCENE } from '../../app/ui/components/navigator/scenes';
describe('calendar saga', () => { describe('calendar saga', () => {
it('should parse a URL correctly', () => { it('should parse a URL correctly', () => {
...@@ -40,7 +41,7 @@ describe('calendar saga', () => { ...@@ -40,7 +41,7 @@ describe('calendar saga', () => {
[matchers.call.fn(apiRequest), []], [matchers.call.fn(apiRequest), []],
]) ])
.dispatch(deepLinkingActions.deepLink(`${siteURL}/events/`)) .dispatch(deepLinkingActions.deepLink(`${siteURL}/events/`))
.put(navigationActions.navigate('eventList')) .put(navigationActions.navigate(EVENT_LIST_SCENE))
.silentRun()); .silentRun());
it('shouldl load event on /events/{id} deeplink', () => expectSaga(deepLinkingSaga) it('shouldl load event on /events/{id} deeplink', () => expectSaga(deepLinkingSaga)
......
...@@ -8,6 +8,7 @@ import eventSaga from '../../app/sagas/event'; ...@@ -8,6 +8,7 @@ import eventSaga from '../../app/sagas/event';
import * as eventActions from '../../app/actions/event'; import * as eventActions from '../../app/actions/event';
import * as navActions from '../../app/actions/navigation'; import * as navActions from '../../app/actions/navigation';
import { EVENT_SCENE } from '../../app/ui/components/navigator/scenes';
jest.mock('../../app/utils/url', () => ({ jest.mock('../../app/utils/url', () => ({
apiRequest: jest.fn(() => {}), apiRequest: jest.fn(() => {}),
...@@ -32,7 +33,7 @@ describe('event saga', () => { ...@@ -32,7 +33,7 @@ describe('event saga', () => {
[matchers.call.fn(apiRequest), []], [matchers.call.fn(apiRequest), []],
]) ])
.dispatch(eventActions.event(1)) .dispatch(eventActions.event(1))
.put(navActions.navigate('event')) .put(navActions.navigate(EVENT_SCENE))
.silentRun()); .silentRun());
it('should put an error when the api request fails', () => expectSaga(eventSaga) it('should put an error when the api request fails', () => expectSaga(eventSaga)
......
...@@ -6,6 +6,7 @@ import { apiRequest, tokenSelector } from '../../app/utils/url'; ...@@ -6,6 +6,7 @@ import { apiRequest, tokenSelector } from '../../app/utils/url';
import pizzaSaga from '../../app/sagas/pizza'; import pizzaSaga from '../../app/sagas/pizza';
import * as pizzaActions from '../../app/actions/pizza'; import * as pizzaActions from '../../app/actions/pizza';
import * as navigationActions from '../../app/actions/navigation'; import * as navigationActions from '../../app/actions/navigation';
import { PIZZA_SCENE } from '../../app/ui/components/navigator/scenes';
jest.mock('../../app/utils/url', () => ({ jest.mock('../../app/utils/url', () => ({
apiRequest: jest.fn(() => {}), apiRequest: jest.fn(() => {}),
...@@ -28,7 +29,7 @@ describe('pizza saga', () => { ...@@ -28,7 +29,7 @@ describe('pizza saga', () => {
]) ])
.dispatch(pizzaActions.retrievePizzaInfo()) .dispatch(pizzaActions.retrievePizzaInfo())
.put(pizzaActions.fetching()) .put(pizzaActions.fetching())
.put(navigationActions.navigate('pizza')) .put(navigationActions.navigate(PIZZA_SCENE))
.silentRun()); .silentRun());
describe('failures', () => { describe('failures', () => {
......
...@@ -6,6 +6,7 @@ import profileSaga from '../../app/sagas/profile'; ...@@ -6,6 +6,7 @@ import profileSaga from '../../app/sagas/profile';
import { apiRequest, tokenSelector } from '../../app/utils/url'; import { apiRequest, tokenSelector } from '../../app/utils/url';
import * as profileActions from '../../app/actions/profile'; import * as profileActions from '../../app/actions/profile';
import * as navActions from '../../app/actions/navigation'; import * as navActions from '../../app/actions/navigation';
import { PROFILE_SCENE } from '../../app/ui/components/navigator/scenes';
jest.mock('../../app/utils/url', () => ({ jest.mock('../../app/utils/url', () => ({
apiRequest: jest.fn(() => {}), apiRequest: jest.fn(() => {}),
...@@ -22,7 +23,7 @@ describe('profile saga', () => { ...@@ -22,7 +23,7 @@ describe('profile saga', () => {
]) ])
.dispatch(profileActions.profile('token', 1)) .dispatch(profileActions.profile('token', 1))
.put(profileActions.fetching()) .put(profileActions.fetching())
.put(navActions.navigate('profile')) .put(navActions.navigate(PROFILE_SCENE))
.silentRun()); .silentRun());
it('should put success when the request succeeds', () => expectSaga(profileSaga) it('should put success when the request succeeds', () => expectSaga(profileSaga)
......
...@@ -8,6 +8,7 @@ import registrationSaga, { eventSelector } from '../../app/sagas/registration'; ...@@ -8,6 +8,7 @@ import registrationSaga, { eventSelector } from '../../app/sagas/registration';
import { apiRequest, tokenSelector } from '../../app/utils/url'; import { apiRequest, tokenSelector } from '../../app/utils/url';
import * as eventActions from '../../app/actions/event'; import * as eventActions from '../../app/actions/event';
import * as navigationActions from '../../app/actions/navigation'; import * as navigationActions from '../../app/actions/navigation';
import { REGISTRATION_SCENE } from '../../app/ui/components/navigator/scenes';
jest.mock('react-native-snackbar', () => ({ jest.mock('react-native-snackbar', () => ({
LENGTH_LONG: 100, LENGTH_LONG: 100,
...@@ -61,11 +62,11 @@ describe('registration saga', () => { ...@@ -61,11 +62,11 @@ describe('registration saga', () => {
.silentRun() .silentRun()
.then(() => { .then(() => {
expect(Snackbar.show).toBeCalledWith( expect(Snackbar.show).toBeCalledWith(
{ title: 'Registration successful!' }); { title: 'Registration successful!' },
);
})); }));
it('should put a retrieve fields action when they are available', () => it('should put a retrieve fields action when they are available', () => expectSaga(registrationSaga)
expectSaga(registrationSaga)
.provide([ .provide([
[select(tokenSelector), 'token'], [select(tokenSelector), 'token'],
[matchers.call.like({ fn: apiRequest, args: ['events/1/registrations'] }), [matchers.call.like({ fn: apiRequest, args: ['events/1/registrations'] }),
...@@ -139,7 +140,8 @@ describe('registration saga', () => { ...@@ -139,7 +140,8 @@ describe('registration saga', () => {
.silentRun() .silentRun()
.then(() => { .then(() => {
expect(Snackbar.show).toBeCalledWith( expect(Snackbar.show).toBeCalledWith(
{ title: 'Successfully updated registration' }); { title: 'Successfully updated registration' },
);
})); }));
it('should put failure action when the request fails', () => expectSaga(registrationSaga) it('should put failure action when the request fails', () => expectSaga(registrationSaga)
...@@ -191,7 +193,8 @@ describe('registration saga', () => { ...@@ -191,7 +193,8 @@ describe('registration saga', () => {
.silentRun() .silentRun()
.then(() => { .then(() => {
expect(Snackbar.show).toBeCalledWith( expect(Snackbar.show).toBeCalledWith(
{ title: 'Successfully cancelled registration' }); { title: 'Successfully cancelled registration' },
);
})); }));
it('should put event action when the request succeeds', () => expectSaga(registrationSaga) it('should put event action when the request succeeds', () => expectSaga(registrationSaga)
...@@ -252,7 +255,7 @@ describe('registration saga', () => { ...@@ -252,7 +255,7 @@ describe('registration saga', () => {
it('should navigate to the registration screen', () => expectSaga(registrationSaga) it('should navigate to the registration screen', () => expectSaga(registrationSaga)
.dispatch(registrationActions.retrieveFields(1)) .dispatch(registrationActions.retrieveFields(1))
.put(navigationActions.navigate('registration')) .put(navigationActions.navigate(REGISTRATION_SCENE))
.silentRun()); .silentRun());
it('should put showFields action when the request succeeds', () => expectSaga(registrationSaga) it('should put showFields action when the request succeeds', () => expectSaga(registrationSaga)
......
...@@ -6,13 +6,14 @@ import { Sentry } from 'react-native-sentry'; ...@@ -6,13 +6,14 @@ import { Sentry } from 'react-native-sentry';
import { apiRequest, tokenSelector } from '../utils/url'; import { apiRequest, tokenSelector } from '../utils/url';
import * as eventActions from '../actions/event'; import * as eventActions from '../actions/event';
import * as navActions from '../actions/navigation'; import * as navActions from '../actions/navigation';
import { EVENT_SCENE } from '../ui/components/navigator/scenes';
const event = function* event(action) { const event = function* event(action) {
const { pk } = action.payload; const { pk } = action.payload;
const token = yield select(tokenSelector); const token = yield select(tokenSelector);
yield put(eventActions.fetching()); yield put(eventActions.fetching());
yield put(navActions.navigate('event')); yield put(navActions.navigate(EVENT_SCENE));
const data = { const data = {
method: 'GET', method: 'GET',
......
...@@ -6,6 +6,7 @@ import { apiRequest, tokenSelector } from '../utils/url'; ...@@ -6,6 +6,7 @@ import { apiRequest, tokenSelector } from '../utils/url';
import * as pizzaActions from '../actions/pizza'; import * as pizzaActions from '../actions/pizza';
import * as navigationActions from '../actions/navigation'; import * as navigationActions from '../actions/navigation';
import { PIZZA_SCENE } from '../ui/components/navigator/scenes';
const NOT_FOUND = 404; const NOT_FOUND = 404;
...@@ -13,7 +14,7 @@ const retrievePizzaInfo = function* retrievePizzaInfo() { ...@@ -13,7 +14,7 @@ const retrievePizzaInfo = function* retrievePizzaInfo() {
const token = yield select(tokenSelector); const token = yield select(tokenSelector);
yield put(pizzaActions.fetching()); yield put(pizzaActions.fetching());
yield put(navigationActions.navigate('pizza')); yield put(navigationActions.navigate(PIZZA_SCENE));
const data = { const data = {
method: 'GET', method: 'GET',
......
...@@ -4,12 +4,13 @@ import { Sentry } from 'react-native-sentry'; ...@@ -4,12 +4,13 @@ import { Sentry } from 'react-native-sentry';
import { apiRequest } from '../utils/url'; import { apiRequest } from '../utils/url';
import * as profileActions from '../actions/profile'; import * as profileActions from '../actions/profile';
import * as navActions from '../actions/navigation'; import * as navActions from '../actions/navigation';
import { PROFILE_SCENE } from '../ui/components/navigator/scenes';
const profile = function* profile(action) { const profile = function* profile(action) {
const { token, member } = action.payload; const { token, member } = action.payload;
yield put(profileActions.fetching()); yield put(profileActions.fetching());
yield put(navActions.navigate('profile')); yield put(navActions.navigate(PROFILE_SCENE));
const data = { const data = {
method: 'GET', method: 'GET',
......
...@@ -10,6 +10,7 @@ import { apiRequest, tokenSelector } from '../utils/url'; ...@@ -10,6 +10,7 @@ import { apiRequest, tokenSelector } from '../utils/url';
import * as eventActions from '../actions/event'; import * as eventActions from '../actions/event';
import * as navigationActions from '../actions/navigation'; import * as navigationActions from '../actions/navigation';
import * as registrationActions from '../actions/registration'; import * as registrationActions from '../actions/registration';
import { REGISTRATION_SCENE } from '../ui/components/navigator/scenes';
export const eventSelector = state => state.event.data.pk; export const eventSelector = state => state.event.data.pk;
...@@ -110,7 +111,7 @@ const fields = function* fields(action) { ...@@ -110,7 +111,7 @@ const fields = function* fields(action) {
const token = yield select(tokenSelector); const token = yield select(tokenSelector);
yield put(registrationActions.loading()); yield put(registrationActions.loading());
yield put(navigationActions.navigate('registration')); yield put(navigationActions.navigate(REGISTRATION_SCENE));
const data = { const data = {
method: 'GET', method: 'GET',
......
...@@ -20,24 +20,34 @@ import Settings from '../../screens/settings/Settings'; ...@@ -20,24 +20,34 @@ import Settings from '../../screens/settings/Settings';
import * as actions from '../../../actions/navigation'; import * as actions from '../../../actions/navigation';
import styles from './style/ReduxNavigator'; import styles from './style/ReduxNavigator';
import Colors from '../../style/Colors'; import Colors from '../../style/Colors';
import {
WELCOME_SCENE,
EVENT_LIST_SCENE,
EVENT_SCENE,
PROFILE_SCENE,
PIZZA_SCENE,
REGISTRATION_SCENE,
MEMBERS_SCENE,
SETTINGS_SCENE,
} from './scenes';
const sceneToComponent = (scene) => { const sceneToComponent = (scene) => {
switch (scene) { switch (scene) {
case 'welcome': case WELCOME_SCENE:
return <Welcome />; return <Welcome />;
case 'event': case EVENT_SCENE:
return <Event />; return <Event />;
case 'eventList': case EVENT_LIST_SCENE:
return <Calendar />; return <Calendar />;
case 'profile': case PROFILE_SCENE:
return <Profile />; return <Profile />;
case 'pizza': case PIZZA_SCENE:
return <Pizza />; return <Pizza />;
case 'registration': case REGISTRATION_SCENE:
return <Registration />; return <Registration />;
case 'members': case MEMBERS_SCENE:
return <MemberList />; return <MemberList />;
case 'settings': case SETTINGS_SCENE:
return <Settings />; return <Settings />;
default: default:
return <Welcome />; return <Welcome />;
...@@ -123,7 +133,7 @@ const mapStateToProps = state => ({ ...@@ -123,7 +133,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
updateDrawer: isOpen => dispatch(actions.updateDrawer(isOpen)), updateDrawer: isOpen => dispatch(actions.updateDrawer(isOpen)),
back: () => dispatch(actions.back()), back: () => dispatch(actions.back()),
navigateToWelcome: () => dispatch(actions.navigate('welcome', true)), navigateToWelcome: () => dispatch(actions.navigate(WELCOME_SCENE, true)),
}); });
export default connect(mapStateToProps, mapDispatchToProps)(translate('components/navigator/ReduxNavigator')(ReduxNavigator)); export default connect(mapStateToProps, mapDispatchToProps)(translate('components/navigator/ReduxNavigator')(ReduxNavigator));
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import {
Alert, Text, View, Image, TouchableHighlight, ImageBackground, Alert, Image, ImageBackground, Text, TouchableHighlight, View,
} from 'react-native'; } from 'react-native';
import LinearGradient from 'react-native-linear-gradient'; import LinearGradient from 'react-native-linear-gradient';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
...@@ -13,6 +13,9 @@ import * as navigationActions from '../../../actions/navigation'; ...@@ -13,6 +13,9 @@ import * as navigationActions from '../../../actions/navigation';
import * as loginActions from '../../../actions/login'; import * as loginActions from '../../../actions/login';
import * as profileActions from '../../../actions/profile'; import * as profileActions from '../../../actions/profile';
import Colors from '../../style/Colors'; import Colors from '../../style/Colors';
import {
EVENT_LIST_SCENE, MEMBERS_SCENE, SETTINGS_SCENE, WELCOME_SCENE,
} from './scenes';
const background = require('../../../assets/img/huygens.jpg'); const background = require('../../../assets/img/huygens.jpg');
...@@ -27,32 +30,32 @@ const logoutPrompt = props => () => Alert.alert( ...@@ -27,32 +30,32 @@ const logoutPrompt = props => () => Alert.alert(
const Sidebar = (props) => { const Sidebar = (props) => {
const buttons = [ const buttons = [
{ {
onPress: () => props.navigate('welcome', true), onPress: () => props.navigate(WELCOME_SCENE, true),
iconName: 'home', iconName: 'home',
text: props.t('Welcome'), text: props.t('Welcome'),
style: {}, style: {},
scene: 'welcome', scene: WELCOME_SCENE,
}, },
{ {
onPress: () => props.navigate('eventList', true), onPress: () => props.navigate(EVENT_LIST_SCENE, true),
iconName: 'event', iconName: 'event',
text: props.t('Calendar'), text: props.t('Calendar'),
style: {}, style: {},
scene: 'eventList', scene: EVENT_LIST_SCENE,
}, },
{ {
onPress: () => props.navigate('members', true), onPress: () => props.navigate(MEMBERS_SCENE, true),
iconName: 'people', iconName: 'people',
text: props.t('Member List'), text: props.t('Member List'),
style: {}, style: {},
scene: 'members', scene: MEMBERS_SCENE,
}, },
{ {
onPress: () => props.navigate('settings', true), onPress: () => props.navigate(SETTINGS_SCENE, true),
iconName: 'settings', iconName: 'settings',
text: props.t('Settings'), text: props.t('Settings'),
style: {}, style: {},
scene: 'settings', scene: SETTINGS_SCENE,
}, },
{ {
onPress: logoutPrompt(props), onPress: logoutPrompt(props),
......
export const WELCOME_SCENE = 'welcome';
export const EVENT_SCENE = 'event';
export const EVENT_LIST_SCENE = 'eventList';
export const PROFILE_SCENE = 'profile';
export const PIZZA_SCENE = 'pizza';
export const REGISTRATION_SCENE = 'registration';
export const MEMBERS_SCENE = 'members';
export const SETTINGS_SCENE = 'settings';
...@@ -14,6 +14,7 @@ import ErrorScreen from '../../components/errorScreen/ErrorScreen'; ...@@ -14,6 +14,7 @@ import ErrorScreen from '../../components/errorScreen/ErrorScreen';
import * as welcomeActions from '../../../actions/welcome'; import * as welcomeActions from '../../../actions/welcome';
import { navigate } from '../../../actions/navigation'; import { navigate } from '../../../actions/navigation';
import styles from './style/Welcome'; import styles from './style/Welcome';
import { EVENT_LIST_SCENE } from '../../components/navigator/scenes';
const eventListToSections = (eventList, t) => { const eventListToSections = (eventList, t) => {
const calendarFormat = { const calendarFormat = {
...@@ -48,7 +49,7 @@ const eventListToSections = (eventList, t) => { ...@@ -48,7 +49,7 @@ const eventListToSections = (eventList, t) => {
const Footer = props => ( const Footer = props => (
<TouchableOpacity <TouchableOpacity
onPress={() => props.navigate('eventList', true)} onPress={() => props.navigate(EVENT_LIST_SCENE, true)}
style={styles.footer} style={styles.footer}
> >
<Text style={styles.footerText}> <Text style={styles.footerText}>
......
Supports Markdown
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