From b0135d7ac8ced18b3e9830b214a7fcf4af6ebf0c Mon Sep 17 00:00:00 2001 From: Tewson Seeoun Date: Mon, 8 Apr 2024 20:14:28 +0100 Subject: [PATCH] Add candidate avatar to candidate pages --- src/components/CandidateAvatar.astro | 11 +++++++---- src/pages/candidates/[candidate].astro | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/components/CandidateAvatar.astro b/src/components/CandidateAvatar.astro index 05a4773..ef6cb54 100644 --- a/src/components/CandidateAvatar.astro +++ b/src/components/CandidateAvatar.astro @@ -6,9 +6,10 @@ import Link from "./Link.astro"; interface Props { candidateFullName: string; profilePictureUrl?: string; + showName?: boolean; } -const { candidateFullName, profilePictureUrl } = Astro.props; +const { candidateFullName, profilePictureUrl, showName = true } = Astro.props; const srcUrl = profilePictureUrl ? `https://i0.wp.com/dublininquirer.com${new URL(profilePictureUrl).pathname}?resize=64%2C64&ssl=1` : "data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="; @@ -17,8 +18,10 @@ const srcUrl = profilePictureUrl
-

- {candidateFullName} -

+ { + showName ? ( +

{candidateFullName}

+ ) : null + }
diff --git a/src/pages/candidates/[candidate].astro b/src/pages/candidates/[candidate].astro index 396cfa3..d67ede9 100644 --- a/src/pages/candidates/[candidate].astro +++ b/src/pages/candidates/[candidate].astro @@ -5,6 +5,7 @@ import { marked } from "marked"; import { airtableClient, getLookupFieldValue, + getOptionalStringFieldValue, getStringFieldValue, } from "../../airtable-api"; import Layout from "../../layouts/Layout.astro"; @@ -13,6 +14,7 @@ import HeaderTitle from "../../components/HeaderTitle.astro"; import HeaderSubtitle from "../../components/HeaderSubtitle.astro"; import QuestionText from "../../components/QuestionText.astro"; import Link from "../../components/Link.astro"; +import CandidateAvatar from "../../components/CandidateAvatar.astro"; export async function getStaticPaths() { const candidates = await airtableClient("Candidates") @@ -40,6 +42,10 @@ export async function getStaticPaths() { candidateRecord, "Area local authority name" ); + const candidateProfilePictureUrl = getOptionalStringFieldValue( + candidateRecord, + "Profile picture" + ); const questions = questionRecords .filter( @@ -73,6 +79,7 @@ export async function getStaticPaths() { candidateFullName, candidateAreaName, candidateAreaLocalAuthorityName, + candidateProfilePictureUrl, questions, hasAnswers, }, @@ -84,6 +91,7 @@ const { candidateFullName, candidateAreaName, candidateAreaLocalAuthorityName, + candidateProfilePictureUrl, questions, hasAnswers, } = Astro.props; @@ -91,6 +99,13 @@ const { +
+ +
{candidateFullName} Candidate for