Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

fix day numbers and also make query to get challenges much more succinct (#1662)

Amanuel Odicho111dc1621fc6
diff --git a/apps/aot/src/app/events/[year]/page.tsx b/apps/aot/src/app/events/[year]/page.tsx
index c6325a54..3df616d9 100644
--- a/apps/aot/src/app/events/[year]/page.tsx
+++ b/apps/aot/src/app/events/[year]/page.tsx
@@ -37,7 +37,7 @@ export default async function EventByYearLandingPage({ params }: Props) {
const daysThatHavePassed = activeEventChallenges.length;
const inactiveEventChallenges = Array.from({ length: 25 - daysThatHavePassed }, (_, i) => ({
- id: daysThatHavePassed + i + 1,
+ day: daysThatHavePassed + i + 1,
hasSolved: false,
active: false,
})) as Challenge[];
@@ -60,15 +60,15 @@ export default async function EventByYearLandingPage({ params }: Props) {
</h1> */}
<ul className="z-10 flex flex-col items-center gap-2 sm:gap-3 md:gap-4">
{groupedDays.map((group, index) => (
- <div key={index} className="flex gap-2 sm:gap-3 md:gap-4">
+ <div key={`row-${index}`} className="flex gap-2 sm:gap-3 md:gap-4">
{group.map((day) => (
<>
{day.active ? (
- <Link key={day.id} href={`/events/${year}/${day.id}`}>
- <DayActive day={day.id} hasSolved={day.hasSolved} />
+ <Link key={`day-active-${day.day}`} href={`/events/${year}/${day.day}`}>
+ <DayActive day={day.day} hasSolved={day.hasSolved} />
</Link>
) : (
- <DayInactive day={day.id} key={day.id} />
+ <DayInactive key={`day-inactive-${day.day}`} day={day.day} />
)}
</>
))}
@@ -77,8 +77,9 @@ export default async function EventByYearLandingPage({ params }: Props) {
<div className="-mt-[4.5rem] flex">
{lastThree.map((day, index) => (
- <div
- key={day.id}
+ <Link
+ href={`/events/${year}/${day.day}`}
+ key={day.day}
className={`group relative h-12 w-12 cursor-pointer rounded-2xl duration-300 hover:bg-white/20 ${
index == 2 && 'ml-20 mr-12'
}`}
@@ -95,9 +96,9 @@ export default async function EventByYearLandingPage({ params }: Props) {
height={64}
/>
<div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 font-bold">
- {day.id}
+ {day.day}
</div>
- </div>
+ </Link>
))}
</div>
</ul>
diff --git a/apps/aot/src/server/api/routers/event.ts b/apps/aot/src/server/api/routers/event.ts
index a0f108ba..8f09d883 100644
--- a/apps/aot/src/server/api/routers/event.ts
+++ b/apps/aot/src/server/api/routers/event.ts
@@ -98,24 +98,17 @@ export const eventRouter = createTRPCRouter({
lte: currentAdventDay - 1,
},
},
- include: {
+ select: {
+ orderId: true,
challenge: {
- include: {
+ select: {
submission: {
where: {
userId: ctx.session?.user?.id || '',
isSuccessful: true,
},
- select: {
- isSuccessful: true,
- },
take: 1,
},
- user: {
- select: {
- name: true,
- },
- },
},
},
},
@@ -123,13 +116,10 @@ export const eventRouter = createTRPCRouter({
},
});
- return challenges?.trackChallenges.map((trackChallenge) => {
- const { submission, ...challenge } = trackChallenge.challenge;
- return {
- ...challenge,
- hasSolved: trackChallenge.challenge.submission.length > 0,
- active: true,
- };
- });
+ return challenges?.trackChallenges.map((trackChallenge) => ({
+ day: trackChallenge.orderId + 1,
+ hasSolved: trackChallenge.challenge.submission.length > 0,
+ active: true,
+ }));
}),
});