Skip to content

Commit

Permalink
Add custom functions
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed May 20, 2024
1 parent 2109783 commit 62a2564
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allLocations } from "@/charterafrica/lib/data/json/locations";
import { allCountries } from "@/charterafrica/lib/data/json/locations";
import {
CONTRIBUTORS_COLLECTION,
TOOL_COLLECTION,
Expand Down Expand Up @@ -173,7 +173,7 @@ async function processPageContributors(page, api, context) {
type: "select",
name: "location",
label: filterLabels.location,
options: allLocations.map((country) => ({
options: allCountries.map((country) => ({
value: country.value,
label: country.label?.[locale || "en"],
})),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allLocations } from "@/charterafrica/lib/data/json/locations";
import { allCountries } from "@/charterafrica/lib/data/json/locations";
import { ORGANIZATION_COLLECTION } from "@/charterafrica/payload/utils/collections";
import queryString from "@/charterafrica/utils/ecosystem/queryString";
import formatDateTime from "@/charterafrica/utils/formatDate";
Expand Down Expand Up @@ -146,7 +146,7 @@ async function processPageOrganisations(page, api, context) {
type: "select",
name: "location",
label: filterLabels.location,
options: allLocations.map((country) => ({
options: allCountries.map((country) => ({
value: country.value,
label: country.label?.[locale || "en"],
})),
Expand Down
14 changes: 9 additions & 5 deletions apps/charterafrica/src/lib/data/json/locations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const locations = [
const countries = [
{
name: "Afghanistan",
label: {
Expand Down Expand Up @@ -1959,6 +1959,9 @@ const locations = [
value: "Zimbabwe",
continent: "Africa",
},
];

const regions = [
{
name: "Africa",
label: {
Expand All @@ -1970,13 +1973,14 @@ const locations = [
continent: "Africa",
},
];
const locations = [...countries, ...regions];
const toOptions = ({ label, value }) => ({ label, value });

export const locationsByContinent = (continent) => {
return locations
.filter((country) => continent === country.continent)
.map(({ continent: cntnt, name, ...c }) => c);
.map(toOptions);
};

export const allLocations = locations.map(
({ continent: cntnt, name, ...c }) => c,
);
export const allCountries = countries.map(toOptions);
export const allLocations = locations.map(toOptions);

0 comments on commit 62a2564

Please sign in to comment.