Skip to content

Commit bfebb37

Browse files
committed
feat: refactor lessons table, relationship and related code issues
1 parent 675d49f commit bfebb37

19 files changed

+528
-366
lines changed

prisma/schema.prisma

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ model CompletedQuizzes {
5151

5252
model Lessons {
5353
id String @id @default(cuid())
54-
lessonNumber Int @unique @default(autoincrement())
54+
projectLessonNumber Int? @unique
55+
fundamentalLessonName String?
5556
quizFileName String
5657
}

prisma/seed.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ async function main() {
1515
// },
1616
// });
1717
// console.log({ user });
18-
// const newLesson = await prisma.lessons.create({
19-
// data: {
20-
// quizFileName: "quiz-lesson-4.json",
21-
// },
22-
// });
23-
// console.log({ newLesson });
18+
const newLesson = await prisma.lessons.create({
19+
data: {
20+
quizFileName: "quiz-eth-intro-1.json",
21+
projectLessonNumber: null,
22+
fundamentalLessonName: "eth-intro-part-1",
23+
},
24+
});
25+
console.log({ newLesson });
2426
// const deletedCompletedLog = await prisma.completedQuizzes.deleteMany({});
2527
// console.log({ deletedCompletedLog });
2628
// const completed2 = await prisma.completedQuizzes.create({
@@ -31,6 +33,14 @@ async function main() {
3133
// },
3234
// });
3335
// console.log({ completed2 });
36+
// const updateLesson2 = await prisma.lessons.update({
37+
// where: { id: "clm60bwug00001w43vws1c3iv" },
38+
// data: {
39+
// quizFileName: "quiz-lesson-2.json",
40+
// lessonNumber: 2,
41+
// },
42+
// });
43+
// console.log({ updateLesson2 });
3444
}
3545

3646
main()

src/components/mdx/QuizStatusChecker.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const QuizStatusChecker = ({ quiz }: QuizStatusCheckerTye) => {
1919
const { completedQuizzesIds, allLessonsData } = useAppContext();
2020

2121
// Requests
22-
2322
useMemo(() => {
2423
if (allLessonsData?.length && completedQuizzesIds?.length) {
2524
const actualLessonId: string = allLessonsData?.find(

src/contexts/AppContextProvider.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ export function AppContextProvider({ children }: IProps) {
102102
const projectsWithCompleteStatus = projects.map((lesson) => {
103103
const currentLessonId = allLessonsData.find(
104104
(lessonData) =>
105-
lessonData.lessonNumber.toString() === lesson.slug.toString(), // DEV_NOTE: forcing .toString() to avoid type errors
105+
lessonData.projectLessonNumber?.toString() ===
106+
lesson.slug.toString(), // DEV_NOTE: forcing .toString() to avoid type errors
106107
)?.id;
107108

108109
const completed = currentLessonId
@@ -121,6 +122,35 @@ export function AppContextProvider({ children }: IProps) {
121122
// eslint-disable-next-line react-hooks/exhaustive-deps
122123
}, [completedQuizzesIds]);
123124

125+
useEffect(() => {
126+
if (allLessonsData && fundamentals && completedQuizzesIds.length !== 0) {
127+
const fundamentalsWithCompleteStatus = fundamentals.map((lesson) => {
128+
const currentLessonId = allLessonsData.find(
129+
(lessonData) =>
130+
lessonData.fundamentalLessonName?.toString() ===
131+
lesson.slug.toString(), // DEV_NOTE: forcing .toString() to avoid type errors
132+
)?.id;
133+
134+
const completed = currentLessonId
135+
? completedQuizzesIds.includes(currentLessonId)
136+
: false; // DEV_NOTE: if the lesson is not found, it is not completed
137+
return { ...lesson, completed };
138+
});
139+
140+
setFundamentals(fundamentalsWithCompleteStatus);
141+
} else if (
142+
allLessonsData &&
143+
fundamentals &&
144+
completedQuizzesIds.length === 0
145+
) {
146+
const fundamentalsWithCompleteStatus = fundamentals.map((lesson) => {
147+
return { ...lesson, completed: false };
148+
});
149+
setFundamentals(fundamentalsWithCompleteStatus);
150+
}
151+
// eslint-disable-next-line react-hooks/exhaustive-deps
152+
}, [completedQuizzesIds]);
153+
124154
return (
125155
<AppContext.Provider
126156
value={{

src/pages/lessons/fundamentals/cli_lesson.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { LessonHeader } from "../../../components/mdx/LessonHeader";
1111
import Layout from "../../../components/Layout";
1212

1313
<Layout
14-
title="Dapp Page"
15-
description="A page for your dapp."
14+
title="Getting Started with the command line interface"
15+
description="Learn the basics of using a console/terminal/shell for Ubuntu, Mac and Windows WSL."
1616
>
1717
<LessonHeader title="Navigating in a CLI for beginners" />
1818

src/pages/lessons/fundamentals/code-editors.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { LessonHeader } from "../../../components/mdx/LessonHeader";
1010
import Layout from "../../../components/Layout";
1111

1212
<Layout
13-
title="Dapp Page"
14-
description="A page for your dapp."
13+
title="Code Editors (IDEs)"
14+
description="Popular Code Editors (IDEs)"
1515
>
1616
<LessonHeader title="Code Editors (IDEs)" />
1717

src/pages/lessons/fundamentals/connect-with-rpc.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { LessonHeader } from "../../../components/mdx/LessonHeader";
99
import Layout from "../../../components/Layout";
1010

1111
<Layout
12-
title="Dapp Page"
13-
description="A page for your dapp."
12+
title="Connect with RPC mini-lesson"
13+
description="Connecting to Networks via RPC."
1414
>
1515
<LessonHeader title="Connecting to a Network via RPC" />
1616

src/pages/lessons/fundamentals/decentralized-storage.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { LessonHeader } from "../../../components/mdx/LessonHeader";
99
import Layout from "../../../components/Layout";
1010

1111
<Layout
12-
title="Dapp Page"
13-
description="A page for your dapp."
12+
title="Decentralized Storage"
13+
description="Overview on decentralized storage protocols."
1414
>
1515
<LessonHeader title="Decentralized Storage with Arweave and IPFS/Filecoin" />
1616

0 commit comments

Comments
 (0)