Skip to content

Commit

Permalink
feat(options): always sort contributors by nb contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
JalilArfaoui committed Oct 7, 2019
1 parent 382b838 commit c3133af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
7 changes: 4 additions & 3 deletions src/app/lmem/contributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export const contributorIsSubscribed = (
): boolean => Boolean(contributor.subscribed);

type SortSuggestedContributors = (contributors: Contributor[]) => Contributor[];
export const sortSuggestedContributors: SortSuggestedContributors = R.sortWith([
R.descend(R.prop('contributions'))
]);

export const sortContributorsByContributions: SortSuggestedContributors = R.sortWith(
[R.descend(R.prop('contributions'))]
);

export const findContributorIn = (contributors: Contributor[]) => (
contributor: Contributor
Expand Down
12 changes: 6 additions & 6 deletions src/app/options/store/selectors/contributors.selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { expect } from 'chai';
import { generateContributor } from 'test/fakers/generateContributor';
import {
getContributors,
getContributorsSuggestions,
getSortedContributors,
getSubscriptions,
makeGetNContributorsSuggestions
} from './contributors.selectors';
Expand All @@ -21,12 +21,12 @@ describe('options > selectors > contributors', () => {
contributors: [contributorOne, contributorTwo, contributorThree]
};

describe('getContributors', () => {
it('returns contributors state', () => {
expect(getContributors(state)).to.eql([
describe('getSortedContributors', () => {
it('returns contributors state, sorted by nb of contributors', () => {
expect(getSortedContributors(state)).to.eql([
contributorOne,
contributorTwo,
contributorThree
contributorThree,
contributorTwo
]);
});
});
Expand Down
29 changes: 17 additions & 12 deletions src/app/options/store/selectors/contributors.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { createSelector } from 'reselect';
import * as R from 'ramda';
import {
Contributor,
contributorIsSubscribed,
sortSuggestedContributors,
sortContributorsByContributions,
Contributor,
StatefulContributor
} from 'app/lmem/contributor';
import { createSelector } from 'reselect';
import * as R from 'ramda';
import { ContributorsState } from '../reducers/contributors.reducer';

export const getContributors = (state: {
interface StateWithContributors {
contributors: ContributorsState;
}): StatefulContributor[] => state.contributors;
}

export const getSubscriptions = createSelector(
const getContributors = (state: StateWithContributors): StatefulContributor[] =>
state.contributors;

export const getSortedContributors = createSelector(
[getContributors],
sortContributorsByContributions
);

export const getSubscriptions = createSelector(
[getSortedContributors],
R.filter(contributorIsSubscribed)
);

Expand All @@ -23,11 +31,8 @@ export const getNbSusbcriptions = createSelector(
);

export const getContributorsSuggestions = createSelector(
[getContributors],
R.pipe(
R.reject(contributorIsSubscribed),
sortSuggestedContributors
)
[getSortedContributors],
R.reject(contributorIsSubscribed)
);

export const makeGetNContributorsSuggestions = (n: number) =>
Expand Down

0 comments on commit c3133af

Please sign in to comment.