Commit e7724ad6 authored by Eugen Rochko's avatar Eugen Rochko

Sort instances by closeness to Dunbar's number (150) of active users

parent ba79ee53
......@@ -28,12 +28,21 @@ const initialState = {
},
};
const DUNBAR = 150;
const sortByDunbarsNumber = instances => instances.sort((a, b) => {
const aa = Math.abs(DUNBAR - a.active_users);
const bb = Math.abs(DUNBAR - b.active_users);
return aa > bb ? 1 : (aa < bb ? -1 : 0);
});
export default function reducer(state = initialState, action) {
switch(action.type) {
case LOCALE_CHANGE:
return { ...state, locale: action.data };
case INSTANCES_FETCH_SUCCESS:
return { ...state, instances: action.data };
return { ...state, instances: sortByDunbarsNumber(action.data) };
case FILTER_CATEGORY_CHANGE:
return { ...state, filter: { ...state.filter, category: action.data } };
case FILTER_LANGUAGE_CHANGE:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment