Skip to content

Commit

Permalink
Merge pull request #634 from CodeForAfrica/fix-member-tags
Browse files Browse the repository at this point in the history
Fix member tags
  • Loading branch information
koechkevin committed Oct 13, 2023
2 parents 21c6441 + 62213a8 commit 32cd678
Show file tree
Hide file tree
Showing 4 changed files with 3,976 additions and 1,707 deletions.
5 changes: 4 additions & 1 deletion apps/codeforafrica/src/components/OurTeam/OurTeam.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ const OurTeam = React.forwardRef(function OurTeam(

const handleChangeTag = (_, value) => {
const newValue =
(value && tags.find((t) => equalsIgnoreCase(value, t))) || ALL_TAG;
(value &&
!equalsIgnoreCase(value, ALL_TAG.slug) &&
tags.find((t) => equalsIgnoreCase(value, t.slug))) ||
ALL_TAG;
setTag(newValue);
setPage(1);
setAction("tag");
Expand Down
31 changes: 21 additions & 10 deletions apps/codeforafrica/src/lib/data/blockify/ourTeam.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
import { countries } from "@/codeforafrica/lib/data/json/countries";
import { getMembers } from "@/codeforafrica/lib/data/utils/members";
import { sortTags, ALL_TAG } from "@/codeforafrica/lib/data/utils/tags";
import equalsIgnoreCase from "@/codeforafrica/utils/equalsIgnoreCase";

const getCountryFromCode = (alpha3) =>
countries.find((c) => equalsIgnoreCase(c.alpha3, alpha3)) ?? null;

function getTeamTags(docs) {
const tags = sortTags(docs.map((item) => item.team).filter(Boolean));
return [ALL_TAG, ...tags];
}

function getCountryTags(docs) {
const tags = sortTags(
docs.map(({ country }) => getCountryFromCode(country)).filter(Boolean),
);
return [ALL_TAG, ...tags];
}

async function getTags(fields, docs) {
return fields.map((field) => {
if (field === "team") {
return {
field: "Team",
tags:
[
"All",
...new Set(docs.map((item) => item[field].name).filter(Boolean)),
] ?? [],
tags: getTeamTags(docs),
};
}
const uniqueTags =
["All", ...new Set(docs.map((item) => item[field]).filter(Boolean))] ??
[];
return {
field: `${field.charAt(0).toUpperCase()}${field.slice(1)}`,
tags: uniqueTags,
field: "Country",
tags: getCountryTags(docs),
};
});
}
Expand Down
Loading

0 comments on commit 32cd678

Please sign in to comment.