Skip to content

Commit 4fd1de3

Browse files
committed
feat: refactoring the db schema to include lessons table
1 parent 85933b2 commit 4fd1de3

File tree

7 files changed

+86
-268
lines changed

7 files changed

+86
-268
lines changed

prisma/seed.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ async function main() {
1515
// },
1616
// });
1717
// console.log({ user });
18-
19-
const lesson1 = await prisma.lessons.create({
18+
// const lesson1 = await prisma.lessons.create({
19+
// data: {
20+
// quizFileName: "lesson-4-quiz.json",
21+
// },
22+
// });
23+
// console.log({ lesson1 });
24+
const completed2 = await prisma.completedQuizzes.create({
2025
data: {
21-
quizFileName: "quiz-lesson-1.json",
26+
userId: "cll3hcuim00001wujlay766tk",
27+
lesson: "2",
28+
completed: true,
2229
},
2330
});
24-
console.log({ lesson1 });
31+
console.log({ completed2 });
2532
}
2633

2734
main()

src/pages/_app.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Imports
22
// ========================================================
3-
import React from "react";
3+
import React, { type ReactElement, type ReactNode } from "react";
4+
import { type NextPage } from "next";
5+
import { type AppProps } from "next/app";
46

5-
import { type AppType } from "next/app";
67
import { type Session } from "next-auth";
78
import { SessionProvider } from "next-auth/react";
89
import { api } from "@/utils/api";
@@ -30,9 +31,7 @@ import { ChakraProvider } from "@chakra-ui/react";
3031
import { theme } from "@/theme";
3132
import { MDXProvider } from "@mdx-js/react";
3233
import Components from "@/components/mdx/Components";
33-
import Layout from "@/components/Layout";
3434
import { env } from "@/env.mjs";
35-
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
3635

3736
// Config
3837
// ========================================================
@@ -70,31 +69,37 @@ const wagmiConfig = createConfig({
7069
publicClient,
7170
});
7271

72+
// eslint-disable-next-line @typescript-eslint/ban-types
73+
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
74+
getLayout?: (page: ReactElement) => ReactNode;
75+
};
76+
77+
type AppPropsWithLayout<P> = AppProps<P> & {
78+
Component: NextPageWithLayout<P>;
79+
};
80+
7381
// App Wrapper Component
7482
// ========================================================
75-
const MyApp: AppType<{ session: Session | null }> = ({
83+
const MyApp = ({
7684
Component,
7785
pageProps,
78-
}) => {
86+
}: AppPropsWithLayout<{ session: Session }>) => {
87+
const getLayout = Component.getLayout || ((page) => page);
88+
7989
return (
80-
<ChakraProvider theme={theme}>
81-
<WagmiConfig config={wagmiConfig}>
90+
<WagmiConfig config={wagmiConfig}>
91+
<ChakraProvider theme={theme}>
8292
<SessionProvider refetchInterval={0} session={pageProps.session}>
8393
<RainbowKitSiweNextAuthProvider>
8494
<RainbowKitProvider chains={chains} initialChain={polygonMumbai}>
8595
<MDXProvider components={Components}>
86-
<Layout>
87-
<>
88-
<Component {...pageProps} />
89-
<ReactQueryDevtools />
90-
</>
91-
</Layout>
96+
{getLayout(<Component {...pageProps} />)}
9297
</MDXProvider>
9398
</RainbowKitProvider>
9499
</RainbowKitSiweNextAuthProvider>
95100
</SessionProvider>
96-
</WagmiConfig>
97-
</ChakraProvider>
101+
</ChakraProvider>
102+
</WagmiConfig>
98103
);
99104
};
100105

src/pages/api/auth/[...nextauth].ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { authOptions } from "@/server/auth";
88
// Auth
99
// ========================================================
1010
const Auth = async (req: NextApiRequest, res: NextApiResponse) => {
11-
console.log("In [...nextauth].ts");
12-
1311
const authOpts: NextAuthOptions = authOptions({ req });
1412

1513
if (!Array.isArray(req.query.nextauth)) {

src/pages/getting-started.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import fs from "fs";
2222
import path from "path";
2323
import matter from "gray-matter";
2424
import { CONTENT_PATH } from "@/lib/constants";
25-
import { useEffect, useState } from "react";
25+
import { type ReactElement, useEffect, useState } from "react";
2626
import { api } from "@/utils/api";
2727
import { useSession } from "next-auth/react";
28+
import Layout from "@/components/Layout";
29+
import { type NextPageWithLayout } from "./_app";
2830

2931
export interface Lesson {
3032
frontMatter: any;
@@ -78,7 +80,7 @@ export interface ProjectFrontMatter {
7880
author?: string;
7981
}
8082

81-
const GettingStarted: React.FC<Lessons> = ({ lessons }) => {
83+
const GettingStartedPage: NextPageWithLayout<Lessons> = ({ lessons }) => {
8284
const [formattedLessons, setFormattedLessons] = useState<LessonProps>();
8385

8486
const [fetchNow, setFetchNow] = useState(true);
@@ -98,6 +100,8 @@ const GettingStarted: React.FC<Lessons> = ({ lessons }) => {
98100
},
99101
);
100102

103+
console.log({ completedQuizzesAllData });
104+
101105
useEffect(() => {
102106
const result: LessonProps = lessons.reduce((acc: any, curr: any) => {
103107
if (!acc[curr.path]) acc[curr.path] = [];
@@ -108,11 +112,7 @@ const GettingStarted: React.FC<Lessons> = ({ lessons }) => {
108112

109113
if (sessionData?.user !== undefined && !!completedQuizzesAllData) {
110114
const completedSlugs: string[] = completedQuizzesAllData?.map(
111-
(quiz: any) =>
112-
quiz.lesson
113-
.replace("quiz-lesson-", "")
114-
.replace("lesson-", "")
115-
.replace("-quiz", "") || [],
115+
(quiz: any) => quiz.lesson,
116116
);
117117

118118
const completedQuizzes: Project[] = result?.projects?.map(
@@ -354,4 +354,15 @@ export const getStaticProps = () => {
354354
};
355355
};
356356

357-
export default GettingStarted;
357+
GettingStartedPage.getLayout = function getLayout(page: ReactElement) {
358+
return (
359+
<Layout
360+
// title="Dapp Starterkit Marketing Page" // DEV_NOTE: This is for the next-seo per page config
361+
// description="A marketing page for your dapp." // DEV_NOTE: This is for the next-seo per page config
362+
>
363+
{page}
364+
</Layout>
365+
);
366+
};
367+
368+
export default GettingStartedPage;

src/pages/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
import type { NextPage } from "next";
21
import Hero from "@/components/Hero";
2+
import { type NextPageWithLayout } from "./_app";
3+
import Layout from "@/components/Layout";
4+
import { type ReactElement } from "react";
35

4-
const Home: NextPage = () => {
6+
const Home: NextPageWithLayout = () => {
57
return <Hero />;
68
};
79

10+
Home.getLayout = function getLayout(page: ReactElement) {
11+
return (
12+
<Layout
13+
// title="Dapp Starterkit Marketing Page" // DEV_NOTE: This is for the next-seo per page config
14+
// description="A marketing page for your dapp." // DEV_NOTE: This is for the next-seo per page config
15+
>
16+
{page}
17+
</Layout>
18+
);
19+
};
20+
821
export default Home;

src/pages/lessons/index.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import path from "path";
44
import matter from "gray-matter";
55
import { ContentBanner } from "@/components/ContentBanner";
66
import { CONTENT_PATH } from "@/lib/constants";
7+
import { type NextPageWithLayout } from "../_app";
8+
import { type ReactElement } from "react";
9+
import Layout from "@/components/Layout";
710

811
interface Lesson {
912
path: string;
@@ -20,7 +23,11 @@ interface LessonTrackMap {
2023
[key: string]: Lesson[];
2124
}
2225

23-
const Lessons: React.FC<LessonProps> = ({ lessons }: { lessons: Lesson[] }) => {
26+
const LessonsPage: NextPageWithLayout<LessonProps> = ({
27+
lessons,
28+
}: {
29+
lessons: Lesson[];
30+
}) => {
2431
const result = lessons.reduce((acc: LessonTrackMap, curr) => {
2532
if (!acc[curr.path]) {
2633
// initial an array of lessons for a given track
@@ -59,7 +66,18 @@ const Lessons: React.FC<LessonProps> = ({ lessons }: { lessons: Lesson[] }) => {
5966
);
6067
};
6168

62-
export default Lessons;
69+
LessonsPage.getLayout = function getLayout(page: ReactElement) {
70+
return (
71+
<Layout
72+
// title="Dapp Starterkit Marketing Page" // DEV_NOTE: This is for the next-seo per page config
73+
// description="A marketing page for your dapp." // DEV_NOTE: This is for the next-seo per page config
74+
>
75+
{page}
76+
</Layout>
77+
);
78+
};
79+
80+
export default LessonsPage;
6381

6482
export const getStaticProps = () => {
6583
const contentDir = path.join(CONTENT_PATH);

0 commit comments

Comments
 (0)