@@ -2,52 +2,57 @@ import { api } from "~/trpc/server";
22import Title from "../title" ;
33import Subtitle from "../subtitle" ;
44import { auth } from "~/server/auth" ;
5+ import Unauthorized from "../unauthorized" ;
6+ import SolvedToggle from "./solvedToggle" ;
7+ import { IoIosStar } from "react-icons/io" ;
8+ import Link from "next/link" ;
59
6- const WeekInfo = async ( { id} : { id : string } ) => {
7- const week = await api . week . getWeekPublic ( { id : id } ) ;
8- console . log ( week ) ;
10+ const WeekInfo = async ( { id } : { id : string } ) => {
911 const session = await auth ( ) ;
1012 const userId = session ?. user ?. id ;
1113 const leetcodeUser = session ?. user ?. leetcodeUser ;
1214
13- // Only call backend if needed information exists.
15+ if ( ! session ?. user ) {
16+ return < Unauthorized /> ;
17+ }
18+
1419 if ( userId && leetcodeUser ) {
1520 await api . leetcode . checkNewCompletions ( {
1621 userId : userId ,
1722 leetcodeUser : leetcodeUser ,
1823 } ) ;
1924 }
20-
25+ const week = await api . week . getWeekPublic ( { id : id } ) ;
2126 return (
2227 < div >
2328 { week ? (
2429 < div >
2530 < Title label = { "Week " + week . number + " - " + week . title } />
2631
2732 < div className = "flex flex-col gap-10" >
28- < div className = "flex flex-row justify-between" >
29- < div >
33+ < div className = "flex flex-row justify-between gap-10 " >
34+ < div className = "" >
3035 < Subtitle label = "Overview" />
3136 < div className = "font-main text-primary-foreground" >
3237 { week . description }
3338 </ div >
39+ < ul className = "text-white list-disc pl-4" >
40+ { week . resources . map ( ( resource , index ) => (
41+ < li key = { index } className = "text-primary-foreground " >
42+ { resource }
43+ </ li >
44+ ) ) }
45+ </ ul >
3446 </ div >
3547
36- < div className = "w-1/3 rounded-xl bg-primary-light p-4" >
48+ < div className = "rounded-xl bg-primary-light p-4 w-max " >
3749 < Subtitle label = "Resources" />
38- < div className = "font-main text-sm text-primary-foreground" >
39- { /* {week.resources.map((resource, index) => (
40- <div key={index} className="mb-2">
41- <a
42- href={resource}
43- target="_blank"
44- rel="noopener noreferrer"
45- className="hover:underline"
46- >
47- {resource}
48- </a>
49- </div>
50- ))} */ }
50+ < div className = "font-main text-sm text-primary-foreground flex flex-col pr-5" >
51+ { week . detailResources . map ( ( resource , index ) => (
52+ < Link href = { resource . url } key = { index } target = "_blank" rel = "noopener noreferrer" className = "underline hover:text-gray-100 text-nowrap" >
53+ { resource . title }
54+ </ Link >
55+ ) ) }
5156 </ div >
5257 </ div >
5358 </ div >
@@ -64,12 +69,6 @@ const WeekInfo = async ({id}: { id: string }) => {
6469 </ tr >
6570 </ thead >
6671 < tbody >
67- { /* <tr className="text-white ">
68- <td> <a href="https://leetcode.com/" target="_blank" className="hover:underline"> Hello </a> </td>
69- <td> Hi </td>
70- <td> Hi </td>
71- <td> Hi </td>
72- </tr> */ }
7372 { week . problems . map ( ( problem ) => (
7473 < tr key = { problem . id } className = "text-white" >
7574 < td >
@@ -79,15 +78,26 @@ const WeekInfo = async ({id}: { id: string }) => {
7978 rel = "noopener noreferrer"
8079 className = "hover:underline"
8180 >
82- { problem . name }
81+ < div className = "flex flex-row items-center gap-2" >
82+ { problem . recommended && (
83+ < IoIosStar />
84+ ) }
85+ { problem . name }
86+ </ div >
8387 </ a >
8488 </ td >
8589 < td > { problem . level } </ td >
8690 < td > { problem . solvedBy ?. length ?? 0 } </ td >
8791 < td >
88- { userId && problem . solvedBy ?. some ( ( u ) => u . id === userId )
89- ? "Solved"
90- : "Unsolved" }
92+ { userId ? (
93+ < SolvedToggle
94+ problemId = { problem . id }
95+ initialSolved = { problem . solvedBy ?. some ( ( u ) => u . id === userId ) ?? false }
96+ userId = { userId }
97+ />
98+ ) : (
99+ < span className = "text-gray-400" > Login required</ span >
100+ ) }
91101 </ td >
92102 </ tr >
93103 ) ) }
0 commit comments