Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show arrival date in ambassador cards #151

Merged
merged 2 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/components/ambassadorCard/AmbassadorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ export default function AmbassadorCard(props: AmbassadorCardProps) {
<p>{ambassador.native.text}</p>
</div>

<div>
<h3>Arrived at Alveus</h3>
<p>
{ambassador.arrival
? formatDate(ambassador.arrival, false)
: "Unknown"}
</p>
</div>

<div className={styles.site}>
<p>
Learn more about {ambassador.name} on the{" "}
Expand Down
4 changes: 4 additions & 0 deletions src/components/ambassadorCard/ambassadorCard.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
display: flex;
flex-wrap: wrap;
gap: 0.25rem 1.5rem;

> * {
margin-right: auto;
}
}

.info {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/dateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function calculateAge(dateOfBirth: string): string {
* @param date date in the format YYYY-MM-DD or YYYY-MM or YYYY
* @returns a string of the date in the format Month DD, YYYY or Month YYYY or YYYY
*/
export function formatDate(date: string): string {
export function formatDate(date: string, approximate = true): string {
const dateArray = date.split("-");
let day = dateArray[2];
let month = dateArray[1];
Expand All @@ -60,9 +60,9 @@ export function formatDate(date: string): string {
}

if (day && month && year) return `${month} ${day}, ${year}`;
else if (month && year) return `~${month}, ${year}`;
else if (month && year) return `${approximate ? "~" : ""}${month}, ${year}`;

return `~${year}`;
return `${approximate ? "~" : ""}${year}`;
}

/**
Expand Down