-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleList.tsx
More file actions
260 lines (235 loc) · 10.3 KB
/
Copy pathModuleList.tsx
File metadata and controls
260 lines (235 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
"use client";
import { TopicWithProgress } from "@/types/exercise.types";
import Link from "next/link";
import { Container, Divider, Title2 } from "../Common/DocContent";
import { CheckCircle, Lock } from "lucide-react";
import { PropsWithChildren, useState } from "react";
import { MODULE_TOPIC_PAGE_URL } from "@/data/links";
import { dummyTopics } from "@/data/module";
import { showNotImplementedToast } from "@/utils/toast";
import { TopicProgress } from "@/db/generated/prisma";
import clsx from "clsx";
import { Tooltip } from "../ui/Tooltip";
import { Progress } from "../ui/Progress";
import { useToast } from "@/hooks/useToast";
import { ArrowUpIcon, LockIcon } from "../ui/svg";
type ModuleTopicsListProps = {
topics: TopicWithProgress[];
};
function Wrapper(props: PropsWithChildren){
return (
<div className="mx-auto max-w-4xl">
<Divider />
{props.children}
</div>
);
}
export default function ModuleTopicsList({ topics }: ModuleTopicsListProps) {
// const topics: Topic[] = dummyTopics;
let template = (
<div className="mx-auto max-w-2xl rounded-xl border border-gray-200 bg-gradient-to-br from-gray-50 to-gray-100 p-8 text-center shadow-sm dark:border-gray-700 dark:from-gray-800 dark:to-gray-900">
<div className="mb-6 inline-flex rounded-full bg-blue-50 p-4 dark:bg-blue-900/30">
<LockIcon className="h-10 w-10 text-blue-500 dark:text-blue-400" />
</div>
<h2 className="mb-3 text-2xl font-bold text-gray-900 dark:text-white md:text-3xl">
Module Locked
</h2>
<p className="mb-6 text-lg text-gray-600 dark:text-gray-300">
Complete the previous modules to unlock this content
</p>
<div className="inline-flex animate-bounce items-center gap-2 font-medium text-blue-600 dark:text-blue-400">
<ArrowUpIcon className="h-5 w-5" />
<span>Keep going - you're making progress!</span>
</div>
{/* <div className="mt-8 border-t border-gray-200 pt-6 dark:border-gray-700">
<p className="text-sm text-gray-500 dark:text-gray-400">
Currently completed: {completedModules}/{totalModules}{" "}
modules
</p>
<div className="mt-2 h-2.5 w-full rounded-full bg-gray-200 dark:bg-gray-700">
<div
className="h-2.5 rounded-full bg-blue-600"
style={{
width: `${(completedModules / totalModules) * 100}%`,
}}
/>
</div>
</div> */}
</div>
);
if (topics.length >= 1) template = (
<>
<Title2>Topics Covered in This Module</Title2>
<br />
<div className="grid gap-6 sm:grid-cols-1 md:grid-cols-2">
{topics.map((topic, idx) => (
<ModuleTopic topic={topic} key={idx} />
))}
</div>
</>
);
return (
<Wrapper>
{template}
</Wrapper>
);
}
type ModuleTopicProps = {
topic: TopicWithProgress;
className?: string;
};
// TODO: FIX!!!!
export function ModuleTopic({ topic, className }: ModuleTopicProps) {
const [isHovered, setIsHovered] = useState(false);
// const {toast} = useToast();
// if (!isTopicWithProgress(topic)) {
// console.error("Invalid topic data:", topic);
// return null;
// }
const { progress = null, locked = false } = topic;
const completed = progress?.completed ?? false;
const completionDate = progress?.completedAt
? new Date(progress.completedAt).toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
})
: null;
const showProgressBar =
progress && progress.score > 0 && progress.score <= 100;
const difficultyColor = {
Easy: "text-emerald-500",
Medium: "text-amber-500",
Hard: "text-rose-500",
}[topic.difficulty || "Easy"];
const handleLockedClick = (e: React.MouseEvent) => {
e.preventDefault();
// toast({
// title: "Topic Locked",
// description: "Complete the previous topics to unlock this content.",
// variant: "default",
// });
};
return (
<article
className={clsx(
"group relative overflow-hidden rounded-xl border transition-all",
"border-gray-200 bg-white shadow-sm hover:shadow-md dark:border-gray-700 dark:bg-gray-800",
"hover:-translate-y-1 hover:border-purple-400 hover:shadow-purple-100 dark:hover:border-purple-600 dark:hover:bg-gray-700",
locked ? "cursor-not-allowed opacity-80" : "cursor-pointer",
className,
)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
<Link
href={MODULE_TOPIC_PAGE_URL(topic.slug)}
onClick={locked ? handleLockedClick : undefined}
className="block h-full p-6"
aria-disabled={locked}
>
{/* Difficulty Badge */}
<div className="absolute left-4 top-4">
<span
className={clsx(
"inline-flex items-center rounded-full px-3 py-1 text-xs font-medium",
difficultyColor,
"bg-opacity-20 dark:bg-opacity-20",
completed
? "bg-emerald-500"
: locked
? "bg-gray-500"
: "bg-purple-500",
)}
>
{topic.difficulty || "Easy"}
</span>
</div>
{/* Status Indicator */}
<div className="absolute right-4 top-4 flex items-center gap-2">
{locked ? (
<Tooltip>
<span>Complete previous topics to unlock</span>
<div className="flex items-center gap-1 rounded-full bg-gray-100 px-3 py-1 text-xs font-medium text-gray-700 dark:bg-gray-700 dark:text-gray-300">
<Lock className="h-3 w-3" />
<span>Locked</span>
</div>
</Tooltip>
) : // </Tooltip>
completed ? (
<Tooltip>
<span>Completed on ${completionDate}</span>
<div className="flex items-center gap-1 rounded-full bg-emerald-100 px-3 py-1 text-xs font-medium text-emerald-700 dark:bg-emerald-900 dark:text-emerald-300">
<CheckCircle className="h-3 w-3" />
<span>Completed</span>
</div>
</Tooltip>
) : (
<div className="h-6 w-6 rounded-full border-2 border-gray-300 dark:border-gray-600" />
)}
</div>
{/* Content */}
<div className="mt-8 space-y-3">
<h3
className={clsx(
"text-lg font-semibold transition-colors",
"text-gray-900 group-hover:text-purple-700 dark:text-gray-100 dark:group-hover:text-purple-400",
locked && "text-gray-500 dark:text-gray-400",
)}
>
{topic.title}
</h3>
<p
className={clsx(
"line-clamp-2 text-sm",
locked
? "text-gray-400 dark:text-gray-500"
: "text-gray-600 dark:text-gray-400",
)}
>
{topic.description}
</p>
{/* Tags */}
{topic.tags?.length > 0 && (
<div className="flex flex-wrap gap-2 pt-2">
{topic.tags.map((tag) => (
<span
key={tag}
className="rounded-full bg-gray-100 px-2.5 py-0.5 text-xs text-gray-600 dark:bg-gray-700 dark:text-gray-300"
>
{tag}
</span>
))}
</div>
)}
{/* Progress Bar */}
{showProgressBar && (
<div className="pt-4">
<div className="mb-1.5 flex items-center justify-between text-xs">
<span className="text-gray-500 dark:text-gray-400">
Progress
</span>
<span className="font-medium text-purple-600 dark:text-purple-400">
{Math.round(progress.score)}%
</span>
</div>
<Progress
value={progress.score}
className="h-2 bg-gray-200 dark:bg-gray-700"
style={{ backgroundImage: 'linear-gradient(to right, #a855f7, #9333ea)' }}
/>
</div>
)}
</div>
{/* Hover Effect */}
<div
className={clsx(
"absolute inset-0 -z-10 bg-gradient-to-br from-purple-50 to-transparent opacity-0 transition-opacity",
"dark:from-purple-900/20",
isHovered && !locked && "opacity-100",
)}
/>
</Link>
</article>
);
}