Added formatting date function for last updated

This commit is contained in:
Karen Chen
2026-02-09 15:27:58 -05:00
parent 3f93d98ea9
commit 5228f4d202
2 changed files with 14 additions and 9 deletions

View File

@@ -15,15 +15,19 @@ const homepageQuery = `{
"position": member->position
}
},
"_ohLastUpdated": *[_type=="officeHours"] | order(_updatedAt desc)[0]._updatedAt,
"ohLastUpdated": *[_type=="officeHours"] | order(_updatedAt desc)[0]._updatedAt,
"sponsors": *[_type=="sponsors"]{
name,
url,
"logo": logo.asset->url+"?h=100&fm=webp"
},
"_sponsorsLastUpdated": *[_type=="sponsors"] | order(_updatedAt desc)[0]._updatedAt
"sponsorsLastUpdated": *[_type=="sponsors"] | order(_updatedAt desc)[0]._updatedAt
}`;
function formattingDate(date: Date) {
return date.toISOString().slice(0, 10).replaceAll('-', '/');
}
export const load = async ({ url }) => {
/**
* @description Response data type based on the combined query above.
@@ -39,7 +43,7 @@ export const load = async ({ url }) => {
allOHs: officeHourResp,
sponsors: sponsorsResp,
canonical: url.href,
ohLastUpdated: homePageResp._ohLastUpdated ?? null,
sponsorsLastUpdated: homePageResp._sponsorsLastUpdated ?? null
ohLastUpdated: formattingDate(new Date(homePageResp.ohLastUpdated)),
sponsorsLastUpdated: formattingDate(new Date(homePageResp.sponsorsLastUpdated))
};
};

View File

@@ -72,12 +72,13 @@
<p class="text-ecsess-200">
Come visit us in our student lounge at ENGTR 1060 to grab a coffee (free), play Mario Kart, or
just chat about anything!
{#if data.ohLastUpdated}
<br />
<span class="text-ecsess-200/70 mb-4 inline-block italic">
Last updated: {data.ohLastUpdated}
</span>
{/if}
</p>
{#if data.ohLastUpdated}
<span class="text-ecsess-200/70 mb-4 inline-block italic">
Last updated: {new Date(data.ohLastUpdated).toISOString().slice(0, 10).replaceAll('-', '/')}
</span>
{/if}
<OhSchedule allOhs={data.allOHs} />
</div>
</Section>