Skip to content
This repository was archived by the owner on Feb 10, 2020. It is now read-only.

Commit 15fb8bc

Browse files
authored
Merge pull request #33 from manosim/use-section-list
Use SectionList & ImmutableJS
2 parents 52e5291 + 7893fba commit 15fb8bc

34 files changed

+425
-288
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"dabapps/react",
1111
"dabapps/react-native",
1212
"dabapps/es6",
13-
"dabapps/browser",
1413
],
1514
"rules": {
1615
"react/jsx-indent-props": 0,
1716
"react/jsx-handler-names": 0,
17+
"react-native/no-inline-styles": 0,
1818
}
1919
}

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
sudo: false
2+
13
language: node_js
24

35
node_js:
4-
- '5'
6+
- '6.12.2'
57

68
cache:
79
directories:
810
- node_modules
911

1012
install:
11-
- npm install
13+
- yarn
1214

1315
script:
14-
- npm test
16+
- yarn test

App/Actions/index.js

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
// Settings
1+
/* global fetch */
2+
3+
import { fromJS } from 'immutable';
24

5+
// Settings
36
export const APP_LOADED = 'APP_LOADED';
47
export function appLoaded() {
58
return {
69
type: APP_LOADED
710
};
8-
};
11+
}
912

1013
export const UPDATE_SETTING = 'UPDATE_SETTING';
1114
export function updateSetting(setting, value) {
@@ -14,7 +17,7 @@ export function updateSetting(setting, value) {
1417
setting: setting,
1518
value: value
1619
};
17-
};
20+
}
1821

1922

2023
// Auth
@@ -27,23 +30,23 @@ export function fetchTokenRequest() {
2730
return {
2831
type: FETCH_TOKEN_REQUEST
2932
};
30-
};
33+
}
3134

3235
export function fetchTokenSuccess(payload) {
3336
return {
3437
type: FETCH_TOKEN_SUCCESS,
3538
payload
3639
};
37-
};
40+
}
3841

3942
export function fetchTokenFailure() {
4043
return {
4144
type: FETCH_TOKEN_FAILURE
4245
};
43-
};
46+
}
4447

4548
export function fetchToken(data) {
46-
return (dispatch, getState) => {
49+
return (dispatch) => {
4750
dispatch(fetchTokenRequest());
4851

4952
return fetch('https://github.com/login/oauth/access_token', {
@@ -55,20 +58,20 @@ export function fetchToken(data) {
5558
},
5659
body: JSON.stringify(data)
5760
})
58-
.then(response => {
59-
if (!response.ok) {
60-
throw Error(response.statusText);
61-
}
62-
return response.json();
63-
})
64-
.then(json => {
65-
dispatch(fetchTokenSuccess(json));
66-
})
67-
.catch(error => {
68-
dispatch(fetchTokenFailure());
69-
});
61+
.then(response => {
62+
if (!response.ok) {
63+
throw Error(response.statusText);
64+
}
65+
return response.json();
66+
})
67+
.then(json => {
68+
dispatch(fetchTokenSuccess(json));
69+
})
70+
.catch(() => {
71+
dispatch(fetchTokenFailure());
72+
});
7073
};
71-
};
74+
}
7275

7376
export const LOGOUT = 'LOGOUT';
7477
export function logout() {
@@ -91,20 +94,20 @@ export function fetchNotificationsRequest(isReFetching) {
9194
isReFetching
9295
}
9396
};
94-
};
97+
}
9598

9699
export function fetchNotificationsSuccess(payload) {
97100
return {
98101
type: FETCH_NOTIFICATIONS_SUCCESS,
99102
payload
100103
};
101-
};
104+
}
102105

103106
export function fetchNotificationsFailure() {
104107
return {
105108
type: FETCH_NOTIFICATIONS_FAILURE
106109
};
107-
};
110+
}
108111

109112
export function fetchNotifications(isReFetching = false) {
110113
return (dispatch, getState) => {
@@ -121,20 +124,20 @@ export function fetchNotifications(isReFetching = false) {
121124
'Cache-Control': 'no-cache'
122125
},
123126
})
124-
.then(response => {
125-
if (!response.ok) {
126-
throw Error(response.statusText);
127-
}
128-
return response.json();
129-
})
130-
.then(json => {
131-
dispatch(fetchNotificationsSuccess(json));
132-
})
133-
.catch(error => {
134-
dispatch(fetchNotificationsFailure());
135-
});
127+
.then(response => {
128+
if (!response.ok) {
129+
throw Error(response.statusText);
130+
}
131+
return response.json();
132+
})
133+
.then(json => {
134+
dispatch(fetchNotificationsSuccess(fromJS(json)));
135+
})
136+
.catch(() => {
137+
dispatch(fetchNotificationsFailure());
138+
});
136139
};
137-
};
140+
}
138141

139142

140143
// Single Notification
@@ -147,20 +150,20 @@ export function markNotificationRequest() {
147150
return {
148151
type: MARK_NOTIFICATION_REQUEST
149152
};
150-
};
153+
}
151154

152155
export function markNotificationSuccess(id) {
153156
return {
154157
type: MARK_NOTIFICATION_SUCCESS,
155158
id
156159
};
157-
};
160+
}
158161

159162
export function markNotificationFailure() {
160163
return {
161164
type: MARK_NOTIFICATION_FAILURE
162165
};
163-
};
166+
}
164167

165168
export function markNotification(id) {
166169
return (dispatch, getState) => {
@@ -175,20 +178,20 @@ export function markNotification(id) {
175178
'Cache-Control': 'no-cache'
176179
},
177180
})
178-
.then(response => {
179-
if (!response.ok) {
180-
throw Error(response.statusText);
181-
}
182-
return response.json();
183-
})
184-
.then(json => {
185-
dispatch(markNotificationSuccess(json.id));
186-
})
187-
.catch(error => {
188-
dispatch(markNotificationFailure());
189-
});
181+
.then(response => {
182+
if (!response.ok) {
183+
throw Error(response.statusText);
184+
}
185+
return response.json();
186+
})
187+
.then(json => {
188+
dispatch(markNotificationSuccess(json.id));
189+
})
190+
.catch(() => {
191+
dispatch(markNotificationFailure());
192+
});
190193
};
191-
};
194+
}
192195

193196

194197
// Repo's Notification
@@ -202,20 +205,20 @@ export function markRepoNotificationsRequest() {
202205
return {
203206
type: MARK_REPO_NOTIFICATION_REQUEST
204207
};
205-
};
208+
}
206209

207210
export function markRepoNotificationsSuccess(repoFullName) {
208211
return {
209212
type: MARK_REPO_NOTIFICATION_SUCCESS,
210213
repoFullName
211214
};
212-
};
215+
}
213216

214217
export function markRepoNotificationsFailure() {
215218
return {
216219
type: MARK_REPO_NOTIFICATION_FAILURE
217220
};
218-
};
221+
}
219222

220223
export function markRepoNotifications(loginId, repoId, repoFullName) {
221224
return (dispatch, getState) => {
@@ -230,17 +233,17 @@ export function markRepoNotifications(loginId, repoId, repoFullName) {
230233
},
231234
body: JSON.stringify({})
232235
})
233-
.then(response => {
234-
if (!response.ok) {
235-
throw Error(response.statusText);
236-
}
237-
dispatch(markRepoNotificationsSuccess(repoFullName));
238-
})
239-
.catch(error => {
240-
dispatch(markRepoNotificationsFailure());
241-
});
236+
.then(response => {
237+
if (!response.ok) {
238+
throw Error(response.statusText);
239+
}
240+
dispatch(markRepoNotificationsSuccess(repoFullName));
241+
})
242+
.catch(() => {
243+
dispatch(markRepoNotificationsFailure());
244+
});
242245
};
243-
};
246+
}
244247

245248

246249
// Search
@@ -251,11 +254,11 @@ export function searchNotifications(query) {
251254
type: SEARCH_NOTIFICATIONS,
252255
query: query
253256
};
254-
};
257+
}
255258

256259
export const CLEAR_SEARCH = 'CLEAR_SEARCH';
257260
export function clearSearch() {
258261
return {
259262
type: CLEAR_SEARCH
260263
};
261-
};
264+
}

App/AppContainer.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import { connect } from 'react-redux';
34

45
import {
@@ -24,6 +25,10 @@ const styles = StyleSheet.create({
2425
});
2526

2627
class AppContainer extends React.Component {
28+
static propTypes = {
29+
isLoggedIn: PropTypes.bool.isRequired,
30+
loaded: PropTypes.bool.isRequired,
31+
};
2732

2833
constructor(props) {
2934
super(props);
@@ -54,7 +59,8 @@ class AppContainer extends React.Component {
5459
navigator.pop();
5560
}
5661
}}
57-
{...this.props} />
62+
{...this.props}
63+
/>
5864
);
5965
}
6066

@@ -75,16 +81,17 @@ class AppContainer extends React.Component {
7581
<Navigator
7682
initialRoute={initialRoute}
7783
renderScene={this.renderScene.bind(this)}
78-
navigationBar={<NavigationBar style={styles.navbar} routeMapper={RouteMapper} />} />
84+
navigationBar={<NavigationBar style={styles.navbar} routeMapper={RouteMapper} />}
85+
/>
7986
);
8087
}
81-
};
88+
}
8289

8390
function mapStateToProps(state) {
8491
return {
8592
loaded: state.settings.get('loaded', false),
8693
isLoggedIn: state.auth.get('token') !== null
8794
};
88-
};
95+
}
8996

9097
export default connect(mapStateToProps, null)(AppContainer);

App/Components/AllRead.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export default class AllRead extends React.Component {
7676
<TouchableHighlight
7777
style={styles.button}
7878
underlayColor={Constants.BG_COLOR}
79-
onPress={() => this.props.onReload()}>
79+
onPress={() => this.props.onReload()}
80+
>
8081
<Text>Reload</Text>
8182
</TouchableHighlight>
8283
</View>
@@ -87,6 +88,6 @@ export default class AllRead extends React.Component {
8788
</View>
8889
</View>
8990
);
90-
};
91+
}
9192

92-
};
93+
}

App/Components/Button.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
TouchableHighlight
1010
} from 'react-native';
1111

12-
var styles = StyleSheet.create({
12+
let styles = StyleSheet.create({
1313
button: {
1414
borderRadius: Constants.BASE_BORDER_RADIUS,
1515
borderWidth: 1.5,
@@ -53,10 +53,11 @@ export default class Button extends React.Component {
5353
style={[styles.button, this.props.style]}
5454
disabled={this.props.disabled}
5555
underlayColor={Constants.THEME_ALT_ACTIVE}
56-
onPress={this.onPress.bind(this)}>
56+
onPress={this.onPress.bind(this)}
57+
>
5758
<Text style={styles.buttonText}>{this.props.text}</Text>
5859
</TouchableHighlight>
5960
);
60-
};
61+
}
6162

62-
};
63+
}

0 commit comments

Comments
 (0)