sort subscribed communities when fetching

This commit is contained in:
Sadaqat Ali 2022-06-30 22:50:29 +05:00
parent 7820a52fa7
commit 87dc6853cb
2 changed files with 7 additions and 1 deletions

View File

@ -46,7 +46,7 @@ export const fetchSubscribedCommunities = (username) => {
dispatch({ type: FETCH_SUBSCRIBED_COMMUNITIES }); dispatch({ type: FETCH_SUBSCRIBED_COMMUNITIES });
getSubscriptions(username) getSubscriptions(username)
.then((res) => { .then((res) => {
res.forEach((item) => item.push(true)); res.forEach((item) => item.push(true)).sort((a, b) => a[1].localeCompare(b[1])); //add true value for subscribe status and sort alphabatically
dispatch(fetchSubscribedCommunitiesSuccess(res)); dispatch(fetchSubscribedCommunitiesSuccess(res));
}) })
.catch((err) => dispatch(fetchSubscribedCommunitiesFail(err))); .catch((err) => dispatch(fetchSubscribedCommunitiesFail(err)));

View File

@ -1,5 +1,11 @@
import { SubscribedCommunity } from '../redux/reducers/cacheReducer'; import { SubscribedCommunity } from '../redux/reducers/cacheReducer';
/**
* Accepts Array of subscription items arrays as 1st argument, community cache map as second argument.
* Returns single array with union of both lists, sorted alphabatically
* Example subList = [['id', 'title', 'role', 'label', 'true/false'],['id', 'title', 'role', 'label', 'true/false']]
*
**/
export const mergeSubCommunitiesCacheInSubList = ( export const mergeSubCommunitiesCacheInSubList = (
subList: any[], subList: any[],
cacheMap: Map<string, SubscribedCommunity>, cacheMap: Map<string, SubscribedCommunity>,