import { redirect } from "next/navigation"; import { and, eq } from "drizzle-orm"; import { db } from "@/db"; import { wordProgress } from "@/db/schema"; import { getSessionUser } from "@/lib/auth"; import { buildWordTest, similarWords, wordsByDay } from "@/lib/words"; import { WordDayClient } from "../word-day"; export default async function WordDayPage({ params }: { params: Promise<{ day: string }> }) { const user = await getSessionUser(); if (!user) redirect("/join"); if (user.role !== "child") redirect("/parent"); const day = Number((await params).day); const words = wordsByDay(day); if (words.length === 0) redirect("/words"); const [prog] = await db .select() .from(wordProgress) .where(and(eq(wordProgress.childUserId, user.id), eq(wordProgress.day, day))) .limit(1); const learned: string[] = prog?.learned ? JSON.parse(prog.learned) : []; const items = words.map((w) => ({ word: w.word, meaning: w.meaning, similar: similarWords(w.word, 3).map((s) => ({ word: s.word, meaning: s.meaning })), })); return ( ); }