Skip to content

Commit

Permalink
feat: return date instead of ISO string from queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mwskwong committed Dec 26, 2024
1 parent 31073fe commit 2b23589
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 29 deletions.
13 changes: 3 additions & 10 deletions src/app/education/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,17 @@ const EducationPage = async () => {
{educations.map(
({
id,
from,
to,
program,
school,

supportingDocuments,
...education
}) => (
<Timeline.Item
key={id}
from={new Date(from)}
media={supportingDocuments}
organization={school}
title={program}
to={to ? new Date(to) : undefined}
{...education}
/>
),
)}
Expand All @@ -107,7 +104,6 @@ const EducationPage = async () => {
id,
name,
institution,
description,
completedOn,
certificate,
categories,
Expand All @@ -131,10 +127,7 @@ const EducationPage = async () => {
{name}
</Heading>
<Text as="p" color="gray" mt="2" size="2">
{dateFormatter.format(new Date(completedOn))}
</Text>
<Text as="p" className="line-clamp-3" mt="4">
{description}
Completed on {dateFormatter.format(completedOn)}
</Text>
{categories ? (
<Flex gap="3" mt="auto" pt="4">
Expand Down
7 changes: 3 additions & 4 deletions src/app/experience/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,23 @@ const ExperiencePage = async () => {
{experiences.map(
({
id,
from,
to,

jobTitle,
company,
jobDuties,
skills,
projects = [],
supportingDocuments = [],
...experience
}) => (
<Timeline.Item
key={id}
descriptions={jobDuties}
from={new Date(from)}
media={[...projects, ...supportingDocuments]}
organization={company}
tags={skills}
title={jobTitle}
to={to ? new Date(to) : undefined}
{...experience}
/>
),
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/home/featured-articles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const FeaturedArticles: FC<FeaturedArticlesProps> = async (props) => {
</Heading>
<Text as="p">{description}</Text>
<Text color="gray" size="2">
{dateFormatter.format(new Date(createdAt))}
{dateFormatter.format(createdAt)}
</Text>
</Flex>
</Flex>
Expand Down
7 changes: 2 additions & 5 deletions src/components/home/recent-education.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@ export const RecentEducation: FC<RecentEducationProps> = async (props) => {
{recentEducations.map(
({
id,
from,
to,
program,
school,

supportingDocuments = [],
...education
}) => (
<Timeline.Item
key={id}
columns={{ sm: '4', md: '' }}
from={new Date(from)}
gap={{ sm: '4', md: '' }}
media={supportingDocuments}
organization={school}
title={program}
to={to ? new Date(to) : undefined}
{...education}
/>
),
)}
Expand Down
6 changes: 2 additions & 4 deletions src/components/home/recent-experience.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,24 @@ export const RecentExperience: FC<RecentExperienceProps> = async (props) => {
{recentExperiences.map(
({
id,
from,
to,
jobTitle,
company,
jobDuties,
skills,
projects = [],
supportingDocuments = [],
...experience
}) => (
<Timeline.Item
key={id}
columns={{ sm: '4', md: '' }}
descriptions={jobDuties}
from={new Date(from)}
gap={{ sm: '4', md: '' }}
media={[...projects, ...supportingDocuments]}
organization={company}
tags={skills}
title={jobTitle}
to={to ? new Date(to) : undefined}
{...experience}
/>
),
)}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/contentful-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ export type CourseCategory =
| 'Operating System'
| 'Project Management'
| 'Security';

export interface CourseSkeleton {
contentTypeId: 'course';
fields: {
name: EntryFieldTypes.Symbol;
institution: EntryFieldTypes.EntryLink<OrganizationSkeleton>;
certificate?: EntryFieldTypes.AssetLink;
categories?: EntryFieldTypes.Array<EntryFieldTypes.Symbol<CourseCategory>>;
completedOn: EntryFieldTypes.Date;
};
}
12 changes: 7 additions & 5 deletions src/lib/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export const getExperiences = async () => {
return items.map((item) => ({
id: item.sys.id,
...item.fields,
from: new Date(item.fields.from),
to: item.fields.to && new Date(item.fields.to),
company: item.fields.company && {
name: item.fields.company.fields.name,
url: item.fields.company.fields.url,
Expand Down Expand Up @@ -136,6 +138,8 @@ export const getEducations = async () => {
return items.map((item) => ({
id: item.sys.id,
...item.fields,
from: new Date(item.fields.from),
to: item.fields.to && new Date(item.fields.to),
school: item.fields.school && {
name: item.fields.school.fields.name,
url: item.fields.school.fields.url,
Expand Down Expand Up @@ -168,8 +172,8 @@ export const getArticles = async () => {

return items.map((item) => ({
id: item.sys.id,
createdAt: item.sys.createdAt,
updatedAt: item.sys.updatedAt,
createdAt: new Date(item.sys.createdAt),
updatedAt: new Date(item.sys.updatedAt),
coverPhoto:
item.fields.coverPhoto?.fields.file &&
`https:${item.fields.coverPhoto.fields.file.url}`,
Expand Down Expand Up @@ -234,8 +238,6 @@ export const getCourses = async () => {
item.fields.certificate?.fields.file &&
`https:${item.fields.certificate.fields.file.url}`,
categories: item.fields.categories,
description:
'This five-day instructor-led course provides students who administer and maintain SQL Server databases with the knowledge and skills to administer a SQL server database infrastructure. Additionally, it will be of use to individuals who develop applications that deliver content from SQL Server databases.', // TODO: real description
completedOn: new Date().toISOString(),
completedOn: new Date(item.fields.completedOn),
}));
};

0 comments on commit 2b23589

Please sign in to comment.