lifetracker/apps/web/app/dashboard/day/[dateQuery]/page.tsx

35 lines
1020 B
TypeScript

import { notFound } from "next/navigation";
import { api } from "@/server/api/client";
import { TRPCError } from "@trpc/server";
import DayView from "@/components/dashboard/days/DayView";
import spacetime from "spacetime";
import { useTimezone } from "@lifetracker/shared-react/hooks/timezones";
export default async function DayPage({ params }: { params: { dateQuery: string }; }) {
const { dateQuery } = await params;
let day;
const tzName = await api.users.getTimezone();
console.log(`Displaying ${spacetime.now(tzName).format("yyyy-MM-dd")} in ${tzName}.`);
try {
day = await api.days.get({
dateQuery: spacetime(dateQuery, tzName).format("yyyy-MM-dd"),
timezone: tzName,
});
} catch (e) {
if (e instanceof TRPCError) {
if (e.code == "NOT_FOUND") {
notFound();
}
}
throw e;
}
return (
<>
<DayView
day={day}
/>
</>
);
}