diff --git a/package.json b/package.json index d7b368e..2634b68 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "db:generate":"drizzle-kit generate", + "db:migrate":"drizzle-kit migrate" }, "dependencies": { "@planetscale/database": "^1.18.0", diff --git a/src/pages/api/randomQuote.ts b/src/app/api/v1/quote/random/route.ts similarity index 55% rename from src/pages/api/randomQuote.ts rename to src/app/api/v1/quote/random/route.ts index 0e4928a..5e6c843 100644 --- a/src/pages/api/randomQuote.ts +++ b/src/app/api/v1/quote/random/route.ts @@ -1,8 +1,8 @@ -import { NextApiRequest, NextApiResponse } from 'next'; -import { db } from '@/db/index'; -import { quotes } from '@/db/schema'; +import { db } from "@/db/index"; +import { quotes } from "@/db/schema"; -export default async function handler(req: NextApiRequest, res: NextApiResponse) { +export const dynamic = 'force-dynamic' // defaults to auto +export async function GET(request: Request) { try { // Fetch all quotes const allQuotes = await db.select({ @@ -14,12 +14,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) if (allQuotes.length > 0) { const randomIndex = Math.floor(Math.random() * allQuotes.length); const randomQuote = allQuotes[randomIndex]; - res.status(200).json(randomQuote); + + return new Response(JSON.stringify(randomQuote) ) } else { - res.status(404).json({ error: "No quotes found" }); + return new Response("Error", { + status: 403 + }) } } catch (error) { console.error("Failed to fetch quote:", error); - res.status(500).json({ error: "Failed to fetch quote" }); + return new Response("Error" , { + status: 500 + }) } -} +} \ No newline at end of file diff --git a/src/app/layout.tsx b/src/app/layout.tsx index b5a25ed..b16ff59 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -2,6 +2,8 @@ import type { Metadata } from "next"; import { Inter } from "next/font/google"; import "./globals.css"; import Header from "@/components/Header"; +import ThemeProvider from "@/lib/ThemeProvider"; +import BodyTheme from "@/components/BodyTheme"; const inter = Inter({ subsets: ["latin"] }); @@ -18,8 +20,12 @@ export default function RootLayout({ return ( -
-
{children}
+ +
+ + {children} + + ); diff --git a/src/app/page.tsx b/src/app/page.tsx index d576fea..ea42fe4 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -10,7 +10,7 @@ export default function Page() {

Motivational

Quotes

- +
diff --git a/src/components/BodyTheme.tsx b/src/components/BodyTheme.tsx new file mode 100644 index 0000000..4f66ab8 --- /dev/null +++ b/src/components/BodyTheme.tsx @@ -0,0 +1,12 @@ +"use client" + +import React, { PropsWithChildren, useContext } from 'react' +import { ThemeContext } from '@/lib/ThemeProvider' + +export default function BodyTheme({children}:PropsWithChildren) { + const {theme} = useContext(ThemeContext) + + return ( +
{children}
+ ) +} diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 30f5b38..918796d 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,17 +1,11 @@ +"use client" import Logo from "./Logo"; +import { ThemeContext } from "@/lib/ThemeProvider"; +import { useContext } from "react"; export default function Header() { - // return ( - //
- // - //
- // ); + const theme= useContext(ThemeContext) + return (
@@ -86,7 +80,7 @@ export default function Header() {
-