Updated how groups are fetched, loaded

• Updated:
- how groups are fetched, loaded by setting flags for isLoading, isFetched per tab (new, admin, member, featured)

• Todo:
- Reload on group added, group removal
This commit is contained in:
mgabdev
2020-06-04 18:48:24 -04:00
parent acbc717c59
commit 4f7728b2fa
4 changed files with 75 additions and 23 deletions

View File

@@ -133,20 +133,27 @@ export function fetchGroupRelationshipsFail(error) {
};
export const fetchGroups = (tab) => (dispatch, getState) => {
if (!me) return;
if (!me) return
dispatch(fetchGroupsRequest());
// Don't refetch or fetch when loading
const isLoading = getState().getIn(['group_lists', tab, 'loading'])
const isFetched = getState().getIn(['group_lists', tab, 'fetched'])
if (isLoading || isFetched) return
dispatch(fetchGroupsRequest(tab))
api(getState).get('/api/v1/groups?tab=' + tab)
.then(({ data }) => {
dispatch(fetchGroupsSuccess(data, tab));
dispatch(fetchGroupRelationships(data.map(item => item.id)));
dispatch(fetchGroupsSuccess(data, tab))
dispatch(fetchGroupRelationships(data.map(item => item.id)))
})
.catch(err => dispatch(fetchGroupsFail(err)));
};
.catch((err) => dispatch(fetchGroupsFail(err, tab)))
}
export const fetchGroupsRequest = () => ({
export const fetchGroupsRequest = (tab) => ({
type: GROUPS_FETCH_REQUEST,
tab,
});
export const fetchGroupsSuccess = (groups, tab) => ({
@@ -155,9 +162,10 @@ export const fetchGroupsSuccess = (groups, tab) => ({
tab,
});
export const fetchGroupsFail = error => ({
export const fetchGroupsFail = (error, tab) => ({
type: GROUPS_FETCH_FAIL,
error,
tab,
});
export function joinGroup(id) {