Skip to content

Commit

Permalink
Add candidate avatar to candidate pages
Browse files Browse the repository at this point in the history
  • Loading branch information
tewson committed Apr 8, 2024
1 parent c13e199 commit b0135d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/components/CandidateAvatar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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==";
Expand All @@ -17,8 +18,10 @@ const srcUrl = profilePictureUrl
<div class="p-1">
<Link to={`candidates/${lodash.kebabCase(candidateFullName)}`}>
<img src={srcUrl} class="rounded-full w-16 h-16" />
<p class="text-xs text-center w-16">
{candidateFullName}
</p>
{
showName ? (
<p class="text-xs text-center w-16">{candidateFullName}</p>
) : null
}
</Link>
</div>
15 changes: 15 additions & 0 deletions src/pages/candidates/[candidate].astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { marked } from "marked";
import {
airtableClient,
getLookupFieldValue,
getOptionalStringFieldValue,
getStringFieldValue,
} from "../../airtable-api";
import Layout from "../../layouts/Layout.astro";
Expand All @@ -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")
Expand Down Expand Up @@ -40,6 +42,10 @@ export async function getStaticPaths() {
candidateRecord,
"Area local authority name"
);
const candidateProfilePictureUrl = getOptionalStringFieldValue(
candidateRecord,
"Profile picture"
);
const questions = questionRecords
.filter(
Expand Down Expand Up @@ -73,6 +79,7 @@ export async function getStaticPaths() {
candidateFullName,
candidateAreaName,
candidateAreaLocalAuthorityName,
candidateProfilePictureUrl,
questions,
hasAnswers,
},
Expand All @@ -84,13 +91,21 @@ const {
candidateFullName,
candidateAreaName,
candidateAreaLocalAuthorityName,
candidateProfilePictureUrl,
questions,
hasAnswers,
} = Astro.props;
---

<Layout>
<HeaderSection>
<div class="flex place-content-center">
<CandidateAvatar
candidateFullName={candidateFullName}
profilePictureUrl={candidateProfilePictureUrl}
showName={false}
/>
</div>
<HeaderTitle>{candidateFullName}</HeaderTitle>
<HeaderSubtitle>
Candidate for
Expand Down

0 comments on commit b0135d7

Please sign in to comment.