Skip to content

Commit

Permalink
Sprint 32 (#533)
Browse files Browse the repository at this point in the history
* Resolves #410
  • Loading branch information
raschdiaz committed Dec 24, 2020
1 parent 4aced14 commit 74cc570
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
21 changes: 13 additions & 8 deletions screens/Contact/ContactsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,18 @@ class ContactsScreen extends React.Component {
renderFooter = () => {
return (
<View style={styles.loadMoreFooterText}>
{this.props.isConnected && !this.state.filtered && (
<TouchableOpacity
onPress={() => {
this.onRefresh(true);
}}>
<Text style={styles.loadMoreFooterText}>{i18n.t('notificationsScreen.loadMore')}</Text>
</TouchableOpacity>
)}
{this.props.isConnected &&
!this.state.filtered &&
this.state.offset + this.state.limit < this.props.totalContacts && (
<TouchableOpacity
onPress={() => {
this.onRefresh(true);
}}>
<Text style={styles.loadMoreFooterText}>
{i18n.t('notificationsScreen.loadMore')}
</Text>
</TouchableOpacity>
)}
</View>
);
};
Expand Down Expand Up @@ -466,6 +470,7 @@ const mapStateToProps = (state) => ({
contactSettings: state.contactsReducer.settings,
isConnected: state.networkConnectivityReducer.isConnected,
contactFilters: state.usersReducer.contactFilters,
totalContacts: state.contactsReducer.total,
});
const mapDispatchToProps = (dispatch) => ({
getAllContacts: (domain, token, offset, limit, sort) => {
Expand Down
21 changes: 13 additions & 8 deletions screens/Group/GroupsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,18 @@ class GroupsScreen extends React.Component {
renderFooter = () => {
return (
<View style={styles.loadMoreFooterText}>
{this.props.isConnected && !this.state.filtered && (
<TouchableOpacity
onPress={() => {
this.onRefresh(true);
}}>
<Text style={styles.loadMoreFooterText}>{i18n.t('notificationsScreen.loadMore')}</Text>
</TouchableOpacity>
)}
{this.props.isConnected &&
!this.state.filtered &&
this.state.offset + this.state.limit < this.props.totalGroups && (
<TouchableOpacity
onPress={() => {
this.onRefresh(true);
}}>
<Text style={styles.loadMoreFooterText}>
{i18n.t('notificationsScreen.loadMore')}
</Text>
</TouchableOpacity>
)}
</View>
);
};
Expand Down Expand Up @@ -445,6 +449,7 @@ const mapStateToProps = (state) => ({
groupSettings: state.groupsReducer.settings,
isConnected: state.networkConnectivityReducer.isConnected,
groupFilters: state.usersReducer.groupFilters,
totalGroups: state.groupsReducer.total,
});
const mapDispatchToProps = (dispatch) => ({
getAllGroups: (domain, token, offset, limit, sort) => {
Expand Down
10 changes: 8 additions & 2 deletions store/reducers/contacts.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const initialState = {
shareSettings: {},
savedShare: false,
tags: [],
total: 0,
};

export default function contactsReducer(state = initialState, action) {
Expand All @@ -47,9 +48,10 @@ export default function contactsReducer(state = initialState, action) {
loading: true,
};
case actions.CONTACTS_GETALL_SUCCESS: {
let { contacts, offline } = action,
let { contacts, offline, offset, total } = action,
newContacts = [],
currentContacts = newState.contacts ? [...newState.contacts] : [];
currentContacts = newState.contacts ? [...newState.contacts] : [],
newTotal = total ? total : newState.total;
if (offline) {
newContacts = [...contacts];
} else {
Expand All @@ -68,6 +70,9 @@ export default function contactsReducer(state = initialState, action) {
localContacts = currentContacts.filter(
(currentContact) => !sharedTools.isNumeric(currentContact.ID),
);
if (offset === 0) {
persistedMappedContacts = [];
}
// Merge persisted contacts with db contacts
let dataBaseContacts = [...persistedMappedContacts, ...mappedContacts].sort((a, b) => {
// Sort contacts 'desc'
Expand All @@ -78,6 +83,7 @@ export default function contactsReducer(state = initialState, action) {
return {
...newState,
contacts: newContacts,
total: newTotal,
loading: false,
};
}
Expand Down
10 changes: 8 additions & 2 deletions store/reducers/groups.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const initialState = {
loadingShare: false,
shareSettings: {},
savedShare: false,
total: 0,
};

export default function groupsReducer(state = initialState, action) {
Expand Down Expand Up @@ -93,9 +94,10 @@ export default function groupsReducer(state = initialState, action) {
loading: true,
};
case actions.GROUPS_GETALL_SUCCESS: {
let { groups, offline } = action,
let { groups, offline, offset, total } = action,
newGroups = [],
currentGroups = newState.groups ? [...newState.groups] : [];
currentGroups = newState.groups ? [...newState.groups] : [],
newTotal = total ? total : newState.total;
if (offline) {
newGroups = [...groups];
} else {
Expand All @@ -112,6 +114,9 @@ export default function groupsReducer(state = initialState, action) {
localGroups = currentGroups.filter(
(currentGroup) => !sharedTools.isNumeric(currentGroup.ID),
);
if (offset === 0) {
persistedMappedGroups = [];
}
// Merge persisted groups with db groups
let dataBaseGroups = [...persistedMappedGroups, ...mappedGroups].sort((a, b) => {
// Sort contacts 'desc'
Expand All @@ -122,6 +127,7 @@ export default function groupsReducer(state = initialState, action) {
return {
...newState,
groups: newGroups,
total: newTotal,
loading: false,
};
}
Expand Down
2 changes: 2 additions & 0 deletions store/sagas/contacts.sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function* getAll({ domain, token, offset, limit, sort }) {
yield put({
type: actions.CONTACTS_GETALL_SUCCESS,
contacts: jsonData.posts,
offset,
total: parseInt(jsonData.total),
});
} else {
yield put({
Expand Down
2 changes: 2 additions & 0 deletions store/sagas/groups.sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function* getAll({ domain, token, offset, limit, sort }) {
yield put({
type: actions.GROUPS_GETALL_SUCCESS,
groups: jsonData.posts,
offset,
total: parseInt(jsonData.total),
});
} else {
yield put({
Expand Down

0 comments on commit 74cc570

Please sign in to comment.