Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
ThaliApp
Commits
7602852f
Verified
Commit
7602852f
authored
Aug 10, 2018
by
Sébastiaan Versteeg
Browse files
Move screen scenes to constant
parent
cfee4808
Changes
14
Hide whitespace changes
Inline
Side-by-side
__tests__/sagas/calendar.spec.js
View file @
7602852f
...
...
@@ -8,6 +8,7 @@ import calendarSaga from '../../app/sagas/calendar';
import
*
as
calendarActions
from
'
../../app/actions/calendar
'
;
import
*
as
navActions
from
'
../../app/actions/navigation
'
;
import
{
EVENT_LIST_SCENE
}
from
'
../../app/ui/components/navigator/scenes
'
;
jest
.
mock
(
'
../../app/utils/url
'
,
()
=>
({
apiRequest
:
jest
.
fn
(()
=>
{}),
...
...
@@ -31,7 +32,7 @@ describe('calendar saga', () => {
[
select
(
tokenSelector
),
'
token
'
],
[
matchers
.
call
.
fn
(
apiRequest
),
[]],
])
.
dispatch
(
navActions
.
navigate
(
'
eventList
'
))
.
dispatch
(
navActions
.
navigate
(
EVENT_LIST_SCENE
))
.
put
(
calendarActions
.
fetching
())
.
silentRun
());
...
...
__tests__/sagas/deepLinking.spec.js
View file @
7602852f
...
...
@@ -8,6 +8,7 @@ import * as navigationActions from '../../app/actions/navigation';
import
*
as
eventActions
from
'
../../app/actions/event
'
;
import
*
as
loginActions
from
'
../../app/actions/login
'
;
import
*
as
pizzaActions
from
'
../../app/actions/pizza
'
;
import
{
EVENT_LIST_SCENE
}
from
'
../../app/ui/components/navigator/scenes
'
;
describe
(
'
calendar saga
'
,
()
=>
{
it
(
'
should parse a URL correctly
'
,
()
=>
{
...
...
@@ -40,7 +41,7 @@ describe('calendar saga', () => {
[
matchers
.
call
.
fn
(
apiRequest
),
[]],
])
.
dispatch
(
deepLinkingActions
.
deepLink
(
`
${
siteURL
}
/events/`
))
.
put
(
navigationActions
.
navigate
(
'
eventList
'
))
.
put
(
navigationActions
.
navigate
(
EVENT_LIST_SCENE
))
.
silentRun
());
it
(
'
shouldl load event on /events/{id} deeplink
'
,
()
=>
expectSaga
(
deepLinkingSaga
)
...
...
__tests__/sagas/event.spec.js
View file @
7602852f
...
...
@@ -8,6 +8,7 @@ import eventSaga from '../../app/sagas/event';
import
*
as
eventActions
from
'
../../app/actions/event
'
;
import
*
as
navActions
from
'
../../app/actions/navigation
'
;
import
{
EVENT_SCENE
}
from
'
../../app/ui/components/navigator/scenes
'
;
jest
.
mock
(
'
../../app/utils/url
'
,
()
=>
({
apiRequest
:
jest
.
fn
(()
=>
{}),
...
...
@@ -18,13 +19,13 @@ describe('event saga', () => {
const
error
=
new
Error
(
'
error
'
);
it
(
'
should start fetching
'
,
()
=>
expectSaga
(
eventSaga
)
.
provide
([
[
select
(
tokenSelector
),
'
token
'
],
[
matchers
.
call
.
fn
(
apiRequest
),
[]],
])
.
dispatch
(
eventActions
.
event
(
1
))
.
put
(
eventActions
.
fetching
())
.
silentRun
());
.
provide
([
[
select
(
tokenSelector
),
'
token
'
],
[
matchers
.
call
.
fn
(
apiRequest
),
[]],
])
.
dispatch
(
eventActions
.
event
(
1
))
.
put
(
eventActions
.
fetching
())
.
silentRun
());
it
(
'
should navigate to the event scene
'
,
()
=>
expectSaga
(
eventSaga
)
.
provide
([
...
...
@@ -32,7 +33,7 @@ describe('event saga', () => {
[
matchers
.
call
.
fn
(
apiRequest
),
[]],
])
.
dispatch
(
eventActions
.
event
(
1
))
.
put
(
navActions
.
navigate
(
'
event
'
))
.
put
(
navActions
.
navigate
(
EVENT_SCENE
))
.
silentRun
());
it
(
'
should put an error when the api request fails
'
,
()
=>
expectSaga
(
eventSaga
)
...
...
__tests__/sagas/pizza.spec.js
View file @
7602852f
...
...
@@ -6,6 +6,7 @@ import { apiRequest, tokenSelector } from '../../app/utils/url';
import
pizzaSaga
from
'
../../app/sagas/pizza
'
;
import
*
as
pizzaActions
from
'
../../app/actions/pizza
'
;
import
*
as
navigationActions
from
'
../../app/actions/navigation
'
;
import
{
PIZZA_SCENE
}
from
'
../../app/ui/components/navigator/scenes
'
;
jest
.
mock
(
'
../../app/utils/url
'
,
()
=>
({
apiRequest
:
jest
.
fn
(()
=>
{}),
...
...
@@ -28,7 +29,7 @@ describe('pizza saga', () => {
])
.
dispatch
(
pizzaActions
.
retrievePizzaInfo
())
.
put
(
pizzaActions
.
fetching
())
.
put
(
navigationActions
.
navigate
(
'
pizza
'
))
.
put
(
navigationActions
.
navigate
(
PIZZA_SCENE
))
.
silentRun
());
describe
(
'
failures
'
,
()
=>
{
...
...
__tests__/sagas/profile.spec.js
View file @
7602852f
...
...
@@ -6,6 +6,7 @@ import profileSaga from '../../app/sagas/profile';
import
{
apiRequest
,
tokenSelector
}
from
'
../../app/utils/url
'
;
import
*
as
profileActions
from
'
../../app/actions/profile
'
;
import
*
as
navActions
from
'
../../app/actions/navigation
'
;
import
{
PROFILE_SCENE
}
from
'
../../app/ui/components/navigator/scenes
'
;
jest
.
mock
(
'
../../app/utils/url
'
,
()
=>
({
apiRequest
:
jest
.
fn
(()
=>
{}),
...
...
@@ -22,7 +23,7 @@ describe('profile saga', () => {
])
.
dispatch
(
profileActions
.
profile
(
'
token
'
,
1
))
.
put
(
profileActions
.
fetching
())
.
put
(
navActions
.
navigate
(
'
profile
'
))
.
put
(
navActions
.
navigate
(
PROFILE_SCENE
))
.
silentRun
());
it
(
'
should put success when the request succeeds
'
,
()
=>
expectSaga
(
profileSaga
)
...
...
__tests__/sagas/registration.spec.js
View file @
7602852f
...
...
@@ -8,6 +8,7 @@ import registrationSaga, { eventSelector } from '../../app/sagas/registration';
import
{
apiRequest
,
tokenSelector
}
from
'
../../app/utils/url
'
;
import
*
as
eventActions
from
'
../../app/actions/event
'
;
import
*
as
navigationActions
from
'
../../app/actions/navigation
'
;
import
{
REGISTRATION_SCENE
}
from
'
../../app/ui/components/navigator/scenes
'
;
jest
.
mock
(
'
react-native-snackbar
'
,
()
=>
({
LENGTH_LONG
:
100
,
...
...
@@ -61,19 +62,19 @@ describe('registration saga', () => {
.
silentRun
()
.
then
(()
=>
{
expect
(
Snackbar
.
show
).
toBeCalledWith
(
{
title
:
'
Registration successful!
'
});
{
title
:
'
Registration successful!
'
},
);
}));
it
(
'
should put a retrieve fields action when they are available
'
,
()
=>
expectSaga
(
registrationSaga
)
.
provide
([
[
select
(
tokenSelector
),
'
token
'
],
[
matchers
.
call
.
like
({
fn
:
apiRequest
,
args
:
[
'
events/1/registrations
'
]
}),
{
fields
:
{},
pk
:
2
}],
])
.
dispatch
(
registrationActions
.
register
(
1
))
.
put
(
registrationActions
.
retrieveFields
(
2
))
.
silentRun
());
it
(
'
should put a retrieve fields action when they are available
'
,
()
=>
expectSaga
(
registrationSaga
)
.
provide
([
[
select
(
tokenSelector
),
'
token
'
],
[
matchers
.
call
.
like
({
fn
:
apiRequest
,
args
:
[
'
events/1/registrations
'
]
}),
{
fields
:
{},
pk
:
2
}],
])
.
dispatch
(
registrationActions
.
register
(
1
))
.
put
(
registrationActions
.
retrieveFields
(
2
))
.
silentRun
());
it
(
'
should show a failure action when the request fails
'
,
()
=>
expectSaga
(
registrationSaga
)
.
provide
([
...
...
@@ -139,7 +140,8 @@ describe('registration saga', () => {
.
silentRun
()
.
then
(()
=>
{
expect
(
Snackbar
.
show
).
toBeCalledWith
(
{
title
:
'
Successfully updated registration
'
});
{
title
:
'
Successfully updated registration
'
},
);
}));
it
(
'
should put failure action when the request fails
'
,
()
=>
expectSaga
(
registrationSaga
)
...
...
@@ -152,22 +154,22 @@ describe('registration saga', () => {
.
silentRun
());
it
(
'
should do a PUT request with fields
'
,
()
=>
expectSaga
(
registrationSaga
)
.
provide
([
[
select
(
tokenSelector
),
'
token
'
],
])
.
dispatch
(
registrationActions
.
update
(
2
,
{
key
:
'
value
'
}))
.
silentRun
()
.
then
(()
=>
{
expect
(
apiRequest
).
toBeCalledWith
(
'
registrations/2
'
,
{
body
:
'
{"fields[key]":"value"}
'
,
headers
:
{
Accept
:
'
application/json
'
,
Authorization
:
'
Token token
'
,
'
Content-Type
'
:
'
application/json
'
,
},
method
:
'
PUT
'
,
});
}));
.
provide
([
[
select
(
tokenSelector
),
'
token
'
],
])
.
dispatch
(
registrationActions
.
update
(
2
,
{
key
:
'
value
'
}))
.
silentRun
()
.
then
(()
=>
{
expect
(
apiRequest
).
toBeCalledWith
(
'
registrations/2
'
,
{
body
:
'
{"fields[key]":"value"}
'
,
headers
:
{
Accept
:
'
application/json
'
,
Authorization
:
'
Token token
'
,
'
Content-Type
'
:
'
application/json
'
,
},
method
:
'
PUT
'
,
});
}));
});
describe
(
'
cancelling
'
,
()
=>
{
...
...
@@ -191,7 +193,8 @@ describe('registration saga', () => {
.
silentRun
()
.
then
(()
=>
{
expect
(
Snackbar
.
show
).
toBeCalledWith
(
{
title
:
'
Successfully cancelled registration
'
});
{
title
:
'
Successfully cancelled registration
'
},
);
}));
it
(
'
should put event action when the request succeeds
'
,
()
=>
expectSaga
(
registrationSaga
)
...
...
@@ -252,7 +255,7 @@ describe('registration saga', () => {
it
(
'
should navigate to the registration screen
'
,
()
=>
expectSaga
(
registrationSaga
)
.
dispatch
(
registrationActions
.
retrieveFields
(
1
))
.
put
(
navigationActions
.
navigate
(
'
registration
'
))
.
put
(
navigationActions
.
navigate
(
REGISTRATION_SCENE
))
.
silentRun
());
it
(
'
should put showFields action when the request succeeds
'
,
()
=>
expectSaga
(
registrationSaga
)
...
...
app/sagas/event.js
View file @
7602852f
...
...
@@ -6,13 +6,14 @@ import { Sentry } from 'react-native-sentry';
import
{
apiRequest
,
tokenSelector
}
from
'
../utils/url
'
;
import
*
as
eventActions
from
'
../actions/event
'
;
import
*
as
navActions
from
'
../actions/navigation
'
;
import
{
EVENT_SCENE
}
from
'
../ui/components/navigator/scenes
'
;
const
event
=
function
*
event
(
action
)
{
const
{
pk
}
=
action
.
payload
;
const
token
=
yield
select
(
tokenSelector
);
yield
put
(
eventActions
.
fetching
());
yield
put
(
navActions
.
navigate
(
'
event
'
));
yield
put
(
navActions
.
navigate
(
EVENT_SCENE
));
const
data
=
{
method
:
'
GET
'
,
...
...
app/sagas/pizza.js
View file @
7602852f
...
...
@@ -6,6 +6,7 @@ import { apiRequest, tokenSelector } from '../utils/url';
import
*
as
pizzaActions
from
'
../actions/pizza
'
;
import
*
as
navigationActions
from
'
../actions/navigation
'
;
import
{
PIZZA_SCENE
}
from
'
../ui/components/navigator/scenes
'
;
const
NOT_FOUND
=
404
;
...
...
@@ -13,7 +14,7 @@ const retrievePizzaInfo = function* retrievePizzaInfo() {
const
token
=
yield
select
(
tokenSelector
);
yield
put
(
pizzaActions
.
fetching
());
yield
put
(
navigationActions
.
navigate
(
'
pizza
'
));
yield
put
(
navigationActions
.
navigate
(
PIZZA_SCENE
));
const
data
=
{
method
:
'
GET
'
,
...
...
app/sagas/profile.js
View file @
7602852f
...
...
@@ -4,12 +4,13 @@ import { Sentry } from 'react-native-sentry';
import
{
apiRequest
}
from
'
../utils/url
'
;
import
*
as
profileActions
from
'
../actions/profile
'
;
import
*
as
navActions
from
'
../actions/navigation
'
;
import
{
PROFILE_SCENE
}
from
'
../ui/components/navigator/scenes
'
;
const
profile
=
function
*
profile
(
action
)
{
const
{
token
,
member
}
=
action
.
payload
;
yield
put
(
profileActions
.
fetching
());
yield
put
(
navActions
.
navigate
(
'
profile
'
));
yield
put
(
navActions
.
navigate
(
PROFILE_SCENE
));
const
data
=
{
method
:
'
GET
'
,
...
...
app/sagas/registration.js
View file @
7602852f
...
...
@@ -10,6 +10,7 @@ import { apiRequest, tokenSelector } from '../utils/url';
import
*
as
eventActions
from
'
../actions/event
'
;
import
*
as
navigationActions
from
'
../actions/navigation
'
;
import
*
as
registrationActions
from
'
../actions/registration
'
;
import
{
REGISTRATION_SCENE
}
from
'
../ui/components/navigator/scenes
'
;
export
const
eventSelector
=
state
=>
state
.
event
.
data
.
pk
;
...
...
@@ -110,7 +111,7 @@ const fields = function* fields(action) {
const
token
=
yield
select
(
tokenSelector
);
yield
put
(
registrationActions
.
loading
());
yield
put
(
navigationActions
.
navigate
(
'
registration
'
));
yield
put
(
navigationActions
.
navigate
(
REGISTRATION_SCENE
));
const
data
=
{
method
:
'
GET
'
,
...
...
app/ui/components/navigator/ReduxNavigator.js
View file @
7602852f
...
...
@@ -20,24 +20,34 @@ import Settings from '../../screens/settings/Settings';
import
*
as
actions
from
'
../../../actions/navigation
'
;
import
styles
from
'
./style/ReduxNavigator
'
;
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
)
=>
{
switch
(
scene
)
{
case
'
welcome
'
:
case
WELCOME_SCENE
:
return
<
Welcome
/>
;
case
'
event
'
:
case
EVENT_SCENE
:
return
<
Event
/>
;
case
'
eventList
'
:
case
EVENT_LIST_SCENE
:
return
<
Calendar
/>
;
case
'
profile
'
:
case
PROFILE_SCENE
:
return
<
Profile
/>
;
case
'
pizza
'
:
case
PIZZA_SCENE
:
return
<
Pizza
/>
;
case
'
registration
'
:
case
REGISTRATION_SCENE
:
return
<
Registration
/>
;
case
'
members
'
:
case
MEMBERS_SCENE
:
return
<
MemberList
/>
;
case
'
settings
'
:
case
SETTINGS_SCENE
:
return
<
Settings
/>
;
default
:
return
<
Welcome
/>
;
...
...
@@ -123,7 +133,7 @@ const mapStateToProps = state => ({
const
mapDispatchToProps
=
dispatch
=>
({
updateDrawer
:
isOpen
=>
dispatch
(
actions
.
updateDrawer
(
isOpen
)),
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
));
app/ui/components/navigator/Sidebar.js
View file @
7602852f
import
React
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
Alert
,
Text
,
View
,
Image
,
TouchableHighlight
,
ImageBackground
,
Alert
,
Image
,
ImageBackground
,
Text
,
TouchableHighlight
,
View
,
}
from
'
react-native
'
;
import
LinearGradient
from
'
react-native-linear-gradient
'
;
import
{
connect
}
from
'
react-redux
'
;
...
...
@@ -13,6 +13,9 @@ import * as navigationActions from '../../../actions/navigation';
import
*
as
loginActions
from
'
../../../actions/login
'
;
import
*
as
profileActions
from
'
../../../actions/profile
'
;
import
Colors
from
'
../../style/Colors
'
;
import
{
EVENT_LIST_SCENE
,
MEMBERS_SCENE
,
SETTINGS_SCENE
,
WELCOME_SCENE
,
}
from
'
./scenes
'
;
const
background
=
require
(
'
../../../assets/img/huygens.jpg
'
);
...
...
@@ -27,32 +30,32 @@ const logoutPrompt = props => () => Alert.alert(
const
Sidebar
=
(
props
)
=>
{
const
buttons
=
[
{
onPress
:
()
=>
props
.
navigate
(
'
welcome
'
,
true
),
onPress
:
()
=>
props
.
navigate
(
WELCOME_SCENE
,
true
),
iconName
:
'
home
'
,
text
:
props
.
t
(
'
Welcome
'
),
style
:
{},
scene
:
'
welcome
'
,
scene
:
WELCOME_SCENE
,
},
{
onPress
:
()
=>
props
.
navigate
(
'
eventList
'
,
true
),
onPress
:
()
=>
props
.
navigate
(
EVENT_LIST_SCENE
,
true
),
iconName
:
'
event
'
,
text
:
props
.
t
(
'
Calendar
'
),
style
:
{},
scene
:
'
eventList
'
,
scene
:
EVENT_LIST_SCENE
,
},
{
onPress
:
()
=>
props
.
navigate
(
'
members
'
,
true
),
onPress
:
()
=>
props
.
navigate
(
MEMBERS_SCENE
,
true
),
iconName
:
'
people
'
,
text
:
props
.
t
(
'
Member List
'
),
style
:
{},
scene
:
'
members
'
,
scene
:
MEMBERS_SCENE
,
},
{
onPress
:
()
=>
props
.
navigate
(
'
settings
'
,
true
),
onPress
:
()
=>
props
.
navigate
(
SETTINGS_SCENE
,
true
),
iconName
:
'
settings
'
,
text
:
props
.
t
(
'
Settings
'
),
style
:
{},
scene
:
'
settings
'
,
scene
:
SETTINGS_SCENE
,
},
{
onPress
:
logoutPrompt
(
props
),
...
...
app/ui/components/navigator/scenes.js
0 → 100644
View file @
7602852f
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
'
;
app/ui/screens/welcome/Welcome.js
View file @
7602852f
...
...
@@ -14,6 +14,7 @@ import ErrorScreen from '../../components/errorScreen/ErrorScreen';
import
*
as
welcomeActions
from
'
../../../actions/welcome
'
;
import
{
navigate
}
from
'
../../../actions/navigation
'
;
import
styles
from
'
./style/Welcome
'
;
import
{
EVENT_LIST_SCENE
}
from
'
../../components/navigator/scenes
'
;
const
eventListToSections
=
(
eventList
,
t
)
=>
{
const
calendarFormat
=
{
...
...
@@ -48,7 +49,7 @@ const eventListToSections = (eventList, t) => {
const
Footer
=
props
=>
(
<
TouchableOpacity
onPress
=
{()
=>
props
.
navigate
(
'
eventList
'
,
true
)}
onPress
=
{()
=>
props
.
navigate
(
EVENT_LIST_SCENE
,
true
)}
style
=
{
styles
.
footer
}
>
<
Text
style
=
{
styles
.
footerText
}
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment