Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const homepageQuery = `{
name,
url,
"logo": logo.asset->url+"?h=100&fm=webp"
}
},
"_lastUpdated": *[_type=="officeHours"] | order(_updatedAt desc)[0]._updatedAt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're renaming the variable, you can change "_lastUpdated" to a more descriptive name. I suggest "ohLastUpdated" and also put it between Line 17 and 18 so it's next to the fetching OH query.

"officeHours": *[_type=="officeHours"]{
day,
startTime,
endTime,
"member": {
"name": member->name,
"position": member->position
}
},
"sponsors": *[_type=="sponsors"]{

Great use of the pipe/order functions! I didn't know Sanity can do that

}`;

export const load = async ({ url }) => {
Expand All @@ -36,6 +37,7 @@ export const load = async ({ url }) => {
councilPhoto: councilPhotoUrl,
allOHs: officeHourResp,
sponsors: sponsorsResp,
canonical: url.href
canonical: url.href,
ohLastUpdated: homePageResp._lastUpdated ?? null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can do the time formatting/casting on the backend (this .server file)?

// What you currently have on the frontend
{new Date(data.ohLastUpdated).toLocaleString()} 

// What I'm thinking the frontend should have
{data.ohLastUpdated}

Functionality wise it's the same, but the frontend just have to get the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that i've been doubting.. how to do formatting from the backend, u could check the newest version rn

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a line that creates new Date() after getting the homePageRepsonse, and return the value in the return block.

By "backend" I meant the page.server.ts file, sorry for the confusion

};
};
7 changes: 6 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@
<Section from="from-ecsess-900" to="to-ecsess-700" via="via-ecsess-650">
<div class="w-full">
<h2 class="text-2xl font-bold" id="office-hours">Lounge Office Hours</h2>
<p class="text-ecsess-200 mb-8">
<p class="text-ecsess-200 mb-4">
Come visit us in our student lounge at ENGTR 1060 to grab a coffee (free), play Mario Kart, or
just chat about anything!
</p>
{#if data.ohLastUpdated}
<p class="text-ecsess-200/70 mb-0.5 text-sm italic">
Last updated: {new Date(data.ohLastUpdated).toLocaleString()}
</p>
{/if}
<OhSchedule allOhs={data.allOHs} />
</div>
</Section>
Expand Down