Skip to content

Commit

Permalink
Fetch profile pic url from airtable
Browse files Browse the repository at this point in the history
  • Loading branch information
tewson committed Apr 8, 2024
1 parent 24ba677 commit c13e199
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/airtable-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ export function getStringFieldValue(
) {
return z.string().parse(record.get(fieldName));
}

export function getOptionalStringFieldValue(
record: Record<FieldSet>,
fieldName: string
) {
return z.string().optional().parse(record.get(fieldName));
}
8 changes: 6 additions & 2 deletions src/components/CandidateAvatar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import Link from "./Link.astro";
interface Props {
candidateFullName: string;
profilePictureUrl?: string;
}
const { candidateFullName } = Astro.props;
const { candidateFullName, profilePictureUrl } = 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==";
---

<div class="p-1">
<Link to={`candidates/${lodash.kebabCase(candidateFullName)}`}>
<img src="https://picsum.photos/64" class="rounded-full" />
<img src={srcUrl} class="rounded-full w-16 h-16" />
<p class="text-xs text-center w-16">
{candidateFullName}
</p>
Expand Down
17 changes: 15 additions & 2 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
airtableClient,
getLookupFieldValue,
getStringFieldValue,
getOptionalStringFieldValue,
} from "../airtable-api";
import Layout from "../layouts/Layout.astro";
import Link from "../components/Link.astro";
Expand Down Expand Up @@ -88,7 +89,13 @@ const candidatesByArea = candidates.reduce<Record<string, typeof candidates>>(
"Full name"
);
return (
<CandidateAvatar candidateFullName={candidateFullName} />
<CandidateAvatar
candidateFullName={candidateFullName}
profilePictureUrl={getOptionalStringFieldValue(
candidate,
"Profile picture"
)}
/>
);
})}
</div>
Expand Down Expand Up @@ -118,7 +125,13 @@ const candidatesByArea = candidates.reduce<Record<string, typeof candidates>>(
"Full name"
);
return (
<CandidateAvatar candidateFullName={candidateFullName} />
<CandidateAvatar
candidateFullName={candidateFullName}
profilePictureUrl={getOptionalStringFieldValue(
candidate,
"Profile picture"
)}
/>
);
})}
</div>
Expand Down

0 comments on commit c13e199

Please sign in to comment.