Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Club Leader on the top #305

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/pages/members/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ const GET_MEMBERS = gql`
}
`;

/**
* Sort the member so that leader should be on top
*/
const sortMembers = (a, b) => {
const isALeader = checkForLeader(a);
const isBLeader = checkForLeader(b);
if (isALeader === isBLeader) {
return 0;
} else if (isALeader < isBLeader) {
return 1;
} else {
return -1;
}
};

/**
* Check the member for being a leader or not
*/
const checkForLeader = member => {
return member.clubs
? member.clubs.length > 0 &&
member.clubs.some(club => {
return club.role === "admin" || club.role === "club_owner";
})
: member.role && (member.role === "admin" || member.role === "club_owner");
};

// TODO: Refactor this component to leverage only the <Query> component
// from the apollo library (along with the refetch and fetchMore
// properties of the Query component in order to cover load more and search
Expand Down Expand Up @@ -103,6 +130,7 @@ class Members extends React.PureComponent {
onMembersFetched = data => {
this.setState(state => {
const shownMembers = state.shownMembers.concat(data.users.users);
shownMembers.sort(sortMembers);
return {
shownMembersCount: shownMembers.length,
shownMembers: shownMembers,
Expand Down