Skip to content

Commit 4489046

Browse files
committed
fixed comments section
1 parent d8514f6 commit 4489046

File tree

5 files changed

+45
-39
lines changed

5 files changed

+45
-39
lines changed

android/app/bin/.project

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>app</name>
4+
<comment>Project app created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22+
</natures>
23+
</projectDescription>

src/gists/gists.reducer.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ const setError = (state, { error }) => ({
3838
error,
3939
});
4040

41-
const clearCache = () => ({
42-
gists: [],
43-
hasMoreData: true,
41+
const clearCache = state => ({
42+
...state,
4443
nextPageNo: 1,
4544
comments: [],
45+
hasMoreComments: true,
4646
});
4747

4848
const setGistComments = (state, { payload }) => {
@@ -51,11 +51,9 @@ const setGistComments = (state, { payload }) => {
5151
const isLinkAvailable = links && links.next;
5252
let newComments = data;
5353

54-
console.log('isLinkAvailable', links, !!isLinkAvailable, 'nextPageno', state.nextPageNo);
5554
if (state.nextPageNo > 1) {
5655
newComments = array.concat(state.comments, data);
5756
}
58-
console.log('data******************', data, newComments);
5957

6058
return {
6159
...state,

src/gists/gists.saga.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
requestDeleteComment,
2222
requestAddComment,
2323
} from '../api';
24-
import { clearCache } from '../../src/cache/cache.actionType';
2524

2625
const tokenSelector = state => state.auth.access_token;
2726
const userNameSelector = state => state.loggedInUser.userName;
@@ -80,23 +79,20 @@ function* fetchPublicGists() {
8079

8180
function* fetchCommentsForGist(action) {
8281
try {
82+
if (action.payload.clearCache) {
83+
yield put({ type: 'CLEAR_CACHE' });
84+
}
8385
const moreDataAvailabe = yield select(state => state.gistComments.hasMoreComments);
8486

85-
// yield call(clearCache);
86-
console.log('here');
87-
// console.o;
88-
// if (moreDataAvailabe) {
89-
yield put(fetchGistComments.progress());
90-
// const token = yield select(tokenSelector);
91-
const requestData = yield all([select(tokenSelector), select(state => state.gistComments.nextPageNo)]);
92-
const { data, headers } = yield call(requestGistComments, requestData[0], action.payload, requestData[1]);
93-
const links = headerparser(headers.link);
94-
95-
console.log('linkssssssssssssssssssssssssssssssssssssss', links);
96-
yield put(fetchGistComments.success({ data, links }));
97-
// }
87+
if (moreDataAvailabe) {
88+
yield put(fetchGistComments.progress());
89+
const requestData = yield all([select(tokenSelector), select(state => state.gistComments.nextPageNo)]);
90+
const { data, headers } = yield call(requestGistComments, requestData[0], action.payload.id, requestData[1]);
91+
const links = headerparser(headers.link);
92+
93+
yield put(fetchGistComments.success({ data, links }));
94+
}
9895
} catch (err) {
99-
console.log('comments fetch', err);
10096
yield put(publicGistsFetch.error(err));
10197
}
10298
}

src/gists/screens/components/GistContent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ GistListContent.propTypes = {
9696
showLoader: PropTypes.bool,
9797
fetchGists: PropTypes.func.isRequired,
9898
gistList: PropTypes.array, // eslint-disable-line
99-
hasMoreData: PropTypes.bool.isRequired,
99+
hasMoreData: PropTypes.bool,
100100
};
101101

102102
GistListContent.defaultProps = {

src/gists/screens/gistComments.screen.js

+7-18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { fetchGistComments, deleteComment, addComment } from '../gists.actiontyp
1919
import ListEmptyComponent from './components/EmptyListComponent';
2020
import { colors } from '../../config';
2121
import GistOptions from './components/gistoptions.screen';
22+
import { clearCache } from '../../cache/cache.actionType';
2223

2324
const CardContainer = styled(CardView)`
2425
padding: 3%;
@@ -78,7 +79,6 @@ const ActivityIndicatorContainer = styled.View`
7879
justify-content: center;
7980
align-items: center;
8081
`;
81-
// padding: 20;
8282
const EndOfViewStyle = styled.View`
8383
flex: 1;
8484
justify-content: center;
@@ -99,7 +99,7 @@ class GistCommentsScreen extends React.Component {
9999
};
100100
}
101101
componentDidMount() {
102-
this.fetchComments();
102+
this.fetchComments(true);
103103
}
104104

105105
onPressItem = () => {
@@ -122,8 +122,8 @@ class GistCommentsScreen extends React.Component {
122122
});
123123
}
124124

125-
fetchComments = () => {
126-
this.props.fetchComments(this.props.navigation.getParam('gistData').id);
125+
fetchComments = (clearCache = false) => {
126+
this.props.fetchComments({ id: this.props.navigation.getParam('gistData').id, clearCache });
127127
}
128128

129129
deleteComment = () => {
@@ -135,11 +135,10 @@ class GistCommentsScreen extends React.Component {
135135
}
136136

137137
handleOnEndReached = () => {
138-
this.props.fetchComments(this.props.navigation.getParam('gistData').id);
138+
this.fetchComments();
139139
}
140140

141141
renderItem = ({ item }) => {
142-
console.log('item type=============', item.type);
143142
switch (item.type) {
144143
case 'preloader':
145144
return (
@@ -183,20 +182,12 @@ class GistCommentsScreen extends React.Component {
183182
}
184183

185184
render() {
186-
const { inProgress, hasMoreComments, comments } = this.props;
185+
const { hasMoreComments, comments } = this.props;
187186

188-
console.log('hasMoreComments', hasMoreComments);
189187
const toAppendData = hasMoreComments ? getGistComments('preloader') : getGistComments('noData');
190188

191189
const uniqComments = uniqBy(concat(comments, toAppendData), ({ id }) => (id));
192190

193-
// if (inProgress) {
194-
// return (
195-
// <ActivityIndicatorContainer>
196-
// <ActivityIndicator size="large" color="#33B5E5" />
197-
// </ActivityIndicatorContainer>
198-
// );
199-
// }
200191

201192
return (
202193
<React.Fragment>
@@ -236,7 +227,7 @@ class GistCommentsScreen extends React.Component {
236227
}
237228
}
238229
const mapDispatchToProps = dispatch => ({
239-
fetchComments: id => dispatch(fetchGistComments.action(id)),
230+
fetchComments: data => dispatch(fetchGistComments.action(data)),
240231
deleteThisComment: data => dispatch(deleteComment.action(data)),
241232
addThisComment: data => dispatch(addComment.action(data)),
242233
});
@@ -248,8 +239,6 @@ const mapStateToProps = ({ gistComments, loggedInUser }) => ({
248239
});
249240

250241
GistCommentsScreen.propTypes = {
251-
// comments: PropTypes.arrayOf(React.PropTypes.object).isRequired,
252-
inProgress: PropTypes.bool.isRequired,
253242
fetchComments: PropTypes.func.isRequired,
254243
addThisComment: PropTypes.func.isRequired,
255244
deleteThisComment: PropTypes.func.isRequired,

0 commit comments

Comments
 (0)