Skip to content

Commit

Permalink
Add links to LEAs from index
Browse files Browse the repository at this point in the history
  • Loading branch information
tewson committed Apr 9, 2024
1 parent 15faed9 commit 848d8f5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/components/AreaSelector.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import lodash from "lodash";
import { LOCAL_AUTHORITY } from "../utils";
interface Props {
dccElectoralAreaNames: string[];
Expand All @@ -14,21 +15,21 @@ const { dccElectoralAreaNames, fingalElectoralAreaNames } = Astro.props;
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg p-2 block w-full"
>
<option disabled selected>Choose your electoral area</option>
<option disabled>Dublin City Council</option>
<option disabled>{LOCAL_AUTHORITY.DUBLIN_CITY_COUNCIL}</option>
{
dccElectoralAreaNames.map((electoralAreaName) => (
<option
value={`dublin-city-council/${lodash.kebabCase(electoralAreaName)}`}
value={`${lodash.kebabCase(LOCAL_AUTHORITY.DUBLIN_CITY_COUNCIL)}/${lodash.kebabCase(electoralAreaName)}`}
>
{electoralAreaName}
</option>
))
}
<option disabled>Fingal County Council</option>
<option disabled>{LOCAL_AUTHORITY.FINGAL_COUNTY_COUNCIL}</option>
{
fingalElectoralAreaNames.map((electoralAreaName) => (
<option
value={`fingal-county-council/${lodash.kebabCase(electoralAreaName)}`}
value={`${lodash.kebabCase(LOCAL_AUTHORITY.FINGAL_COUNTY_COUNCIL)}/${lodash.kebabCase(electoralAreaName)}`}
>
{electoralAreaName}
</option>
Expand Down
19 changes: 14 additions & 5 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Layout from "../layouts/Layout.astro";
import Link from "../components/Link.astro";
import CandidateAvatar from "../components/CandidateAvatar.astro";
import AreaSelector from "../components/AreaSelector.astro";
import { getAreasByLocalAuthority } from "../utils";
import { LOCAL_AUTHORITY, getAreasByLocalAuthority } from "../utils";
import lodash from "lodash";
const electoralAreas = await airtableClient("Areas")
.select({
Expand Down Expand Up @@ -68,7 +69,7 @@ const candidatesByArea = candidates.reduce<Record<string, typeof candidates>>(
</p>
</header>
<main class="px-gutter">
<h1 class="font-bold text-2xl">Dublin City Council</h1>
<h1 class="font-bold text-2xl">{LOCAL_AUTHORITY.DUBLIN_CITY_COUNCIL}</h1>
{
dccElectoralAreaNames.map((electoralAreaName) => {
if (
Expand All @@ -80,7 +81,11 @@ const candidatesByArea = candidates.reduce<Record<string, typeof candidates>>(
return (
<>
<div>
<p>{electoralAreaName}</p>
<Link
to={`areas/${lodash.kebabCase(LOCAL_AUTHORITY.DUBLIN_CITY_COUNCIL)}/${lodash.kebabCase(electoralAreaName)}`}
>
{electoralAreaName}
</Link>
</div>
<div class="flex flex-wrap">
{candidatesByArea[electoralAreaName]?.map((candidate) => {
Expand All @@ -104,7 +109,7 @@ const candidatesByArea = candidates.reduce<Record<string, typeof candidates>>(
);
})
}
<h1 class="font-bold text-2xl">Fingal County Council</h1>
<h1 class="font-bold text-2xl">{LOCAL_AUTHORITY.FINGAL_COUNTY_COUNCIL}</h1>
{
fingalElectoralAreaNames.map((electoralAreaName) => {
if (
Expand All @@ -116,7 +121,11 @@ const candidatesByArea = candidates.reduce<Record<string, typeof candidates>>(
return (
<>
<div>
<p>{electoralAreaName}</p>
<Link
to={`areas/${lodash.kebabCase(LOCAL_AUTHORITY.FINGAL_COUNTY_COUNCIL)}/${lodash.kebabCase(electoralAreaName)}`}
>
{electoralAreaName}
</Link>
</div>
<div class="flex flex-wrap">
{candidatesByArea[electoralAreaName]?.map((candidate) => {
Expand Down
9 changes: 7 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import type { Records, FieldSet } from "airtable";

import { getLookupFieldValue, getStringFieldValue } from "./airtable-api";

export const LOCAL_AUTHORITY = {
DUBLIN_CITY_COUNCIL: "Dublin City Council",
FINGAL_COUNTY_COUNCIL: "Fingal County Council",
};

export function getCandidateFullName({
firstname,
lastname,
Expand All @@ -20,7 +25,7 @@ export function getAreasByLocalAuthority(electoralAreas: Records<FieldSet>) {
"Local Authority Name"
);

return localAuthorityName === "Dublin City Council";
return localAuthorityName === LOCAL_AUTHORITY.DUBLIN_CITY_COUNCIL;
})
.map((record) => getStringFieldValue(record, "Name"));

Expand All @@ -31,7 +36,7 @@ export function getAreasByLocalAuthority(electoralAreas: Records<FieldSet>) {
"Local Authority Name"
);

return localAuthorityName === "Fingal County Council";
return localAuthorityName === LOCAL_AUTHORITY.FINGAL_COUNTY_COUNCIL;
})
.map((record) => getStringFieldValue(record, "Name"));

Expand Down

0 comments on commit 848d8f5

Please sign in to comment.