wire up pages
This commit is contained in:
37
frontend/src/app/categories/page.tsx
Normal file
37
frontend/src/app/categories/page.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { getCategories } from "@/lib/api";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export default async function CategoriesPage() {
|
||||||
|
const { items: categories } = await getCategories();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<h1 className="text-3xl font-bold">Categories</h1>
|
||||||
|
<p className="text-[var(--muted-foreground)]">
|
||||||
|
Browse questions by data structure or algorithm category.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||||
|
{categories.map((category) => (
|
||||||
|
<Link
|
||||||
|
key={category.id}
|
||||||
|
href={`/questions?category=${category.slug}`}
|
||||||
|
className="p-6 rounded-lg border border-[var(--border)] bg-[var(--card)] hover:border-[var(--primary)] transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between mb-2">
|
||||||
|
<h3 className="font-semibold">{category.name}</h3>
|
||||||
|
<span className="text-sm text-[var(--muted-foreground)]">
|
||||||
|
{category.question_count} questions
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{category.description && (
|
||||||
|
<p className="text-sm text-[var(--muted-foreground)]">
|
||||||
|
{category.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
23
frontend/src/app/error.tsx
Normal file
23
frontend/src/app/error.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
export default function Error({
|
||||||
|
reset,
|
||||||
|
}: {
|
||||||
|
error: Error & { digest?: string };
|
||||||
|
reset: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="text-center py-12">
|
||||||
|
<h1 className="text-4xl font-bold mb-4">Something went wrong</h1>
|
||||||
|
<p className="text-[var(--muted-foreground)] mb-6">
|
||||||
|
An error occurred while loading this page.
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={() => reset()}
|
||||||
|
className="inline-block px-6 py-3 bg-[var(--primary)] text-[var(--primary-foreground)] rounded-lg font-medium hover:opacity-90 transition-opacity"
|
||||||
|
>
|
||||||
|
Try Again
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
40
frontend/src/app/globals.css
Normal file
40
frontend/src/app/globals.css
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--background: #ffffff;
|
||||||
|
--foreground: #171717;
|
||||||
|
--card: #ffffff;
|
||||||
|
--card-foreground: #171717;
|
||||||
|
--primary: #3b82f6;
|
||||||
|
--primary-foreground: #ffffff;
|
||||||
|
--secondary: #f3f4f6;
|
||||||
|
--secondary-foreground: #171717;
|
||||||
|
--muted: #f3f4f6;
|
||||||
|
--muted-foreground: #6b7280;
|
||||||
|
--border: #e5e7eb;
|
||||||
|
--ring: #3b82f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--background: #0a0a0a;
|
||||||
|
--foreground: #ededed;
|
||||||
|
--card: #171717;
|
||||||
|
--card-foreground: #ededed;
|
||||||
|
--primary: #3b82f6;
|
||||||
|
--primary-foreground: #ffffff;
|
||||||
|
--secondary: #262626;
|
||||||
|
--secondary-foreground: #ededed;
|
||||||
|
--muted: #262626;
|
||||||
|
--muted-foreground: #a3a3a3;
|
||||||
|
--border: #262626;
|
||||||
|
--ring: #3b82f6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--background);
|
||||||
|
color: var(--foreground);
|
||||||
|
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||||
|
"Helvetica Neue", Arial, sans-serif;
|
||||||
|
}
|
||||||
59
frontend/src/app/layout.tsx
Normal file
59
frontend/src/app/layout.tsx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { Providers } from "./providers";
|
||||||
|
import "./globals.css";
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "CodeTutor - Coding Interview Preparation",
|
||||||
|
description:
|
||||||
|
"Master coding interviews with curated questions, detailed explanations, and optimal solutions.",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<body className="min-h-screen antialiased">
|
||||||
|
<Providers>
|
||||||
|
<header className="border-b border-[var(--border)] bg-[var(--card)]">
|
||||||
|
<nav className="container mx-auto px-4 py-4 flex items-center justify-between">
|
||||||
|
<Link
|
||||||
|
href="/"
|
||||||
|
className="text-xl font-bold text-[var(--primary)]"
|
||||||
|
>
|
||||||
|
CodeTutor
|
||||||
|
</Link>
|
||||||
|
<div className="flex items-center gap-6">
|
||||||
|
<Link
|
||||||
|
href="/questions"
|
||||||
|
className="text-[var(--muted-foreground)] hover:text-[var(--foreground)] transition-colors"
|
||||||
|
>
|
||||||
|
Questions
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/categories"
|
||||||
|
className="text-[var(--muted-foreground)] hover:text-[var(--foreground)] transition-colors"
|
||||||
|
>
|
||||||
|
Categories
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/patterns"
|
||||||
|
className="text-[var(--muted-foreground)] hover:text-[var(--foreground)] transition-colors"
|
||||||
|
>
|
||||||
|
Patterns
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<main className="container mx-auto px-4 py-8">{children}</main>
|
||||||
|
<footer className="border-t border-[var(--border)] mt-auto py-6 text-center text-[var(--muted-foreground)] text-sm">
|
||||||
|
CodeTutor - Coding Interview Preparation
|
||||||
|
</footer>
|
||||||
|
</Providers>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
18
frontend/src/app/not-found.tsx
Normal file
18
frontend/src/app/not-found.tsx
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export default function NotFound() {
|
||||||
|
return (
|
||||||
|
<div className="text-center py-12">
|
||||||
|
<h1 className="text-4xl font-bold mb-4">404</h1>
|
||||||
|
<p className="text-[var(--muted-foreground)] mb-6">
|
||||||
|
The page you're looking for doesn't exist.
|
||||||
|
</p>
|
||||||
|
<Link
|
||||||
|
href="/"
|
||||||
|
className="inline-block px-6 py-3 bg-[var(--primary)] text-[var(--primary-foreground)] rounded-lg font-medium hover:opacity-90 transition-opacity"
|
||||||
|
>
|
||||||
|
Go Home
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
103
frontend/src/app/page.tsx
Normal file
103
frontend/src/app/page.tsx
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { getStats } from "@/lib/api";
|
||||||
|
|
||||||
|
export default async function HomePage() {
|
||||||
|
let stats;
|
||||||
|
try {
|
||||||
|
stats = await getStats();
|
||||||
|
} catch {
|
||||||
|
stats = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-12">
|
||||||
|
<section className="text-center py-12">
|
||||||
|
<h1 className="text-4xl font-bold mb-4">Master Coding Interviews</h1>
|
||||||
|
<p className="text-[var(--muted-foreground)] text-lg max-w-2xl mx-auto mb-8">
|
||||||
|
Curated collection of coding interview questions with detailed
|
||||||
|
explanations, common pitfalls, and optimal solutions.
|
||||||
|
</p>
|
||||||
|
<Link
|
||||||
|
href="/questions"
|
||||||
|
className="inline-block px-6 py-3 bg-[var(--primary)] text-[var(--primary-foreground)] rounded-lg font-medium hover:opacity-90 transition-opacity"
|
||||||
|
>
|
||||||
|
Browse Questions
|
||||||
|
</Link>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{stats && (
|
||||||
|
<section className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||||
|
<div className="p-6 rounded-lg border border-[var(--border)] bg-[var(--card)]">
|
||||||
|
<div className="text-3xl font-bold text-[var(--primary)]">
|
||||||
|
{stats.total_questions}
|
||||||
|
</div>
|
||||||
|
<div className="text-[var(--muted-foreground)]">
|
||||||
|
Total Questions
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="p-6 rounded-lg border border-[var(--border)] bg-[var(--card)]">
|
||||||
|
<div className="text-3xl font-bold text-[var(--primary)]">
|
||||||
|
{stats.by_category.length}
|
||||||
|
</div>
|
||||||
|
<div className="text-[var(--muted-foreground)]">Categories</div>
|
||||||
|
</div>
|
||||||
|
<div className="p-6 rounded-lg border border-[var(--border)] bg-[var(--card)]">
|
||||||
|
<div className="text-3xl font-bold text-[var(--primary)]">
|
||||||
|
{stats.by_pattern.length}
|
||||||
|
</div>
|
||||||
|
<div className="text-[var(--muted-foreground)]">
|
||||||
|
Algorithmic Patterns
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{stats && (
|
||||||
|
<section className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||||
|
<div className="p-4 rounded-lg border border-green-200 bg-green-50 dark:border-green-900 dark:bg-green-900/20">
|
||||||
|
<div className="text-2xl font-bold text-green-600 dark:text-green-400">
|
||||||
|
{stats.by_difficulty.easy}
|
||||||
|
</div>
|
||||||
|
<div className="text-green-700 dark:text-green-300">Easy</div>
|
||||||
|
</div>
|
||||||
|
<div className="p-4 rounded-lg border border-yellow-200 bg-yellow-50 dark:border-yellow-900 dark:bg-yellow-900/20">
|
||||||
|
<div className="text-2xl font-bold text-yellow-600 dark:text-yellow-400">
|
||||||
|
{stats.by_difficulty.medium}
|
||||||
|
</div>
|
||||||
|
<div className="text-yellow-700 dark:text-yellow-300">Medium</div>
|
||||||
|
</div>
|
||||||
|
<div className="p-4 rounded-lg border border-red-200 bg-red-50 dark:border-red-900 dark:bg-red-900/20">
|
||||||
|
<div className="text-2xl font-bold text-red-600 dark:text-red-400">
|
||||||
|
{stats.by_difficulty.hard}
|
||||||
|
</div>
|
||||||
|
<div className="text-red-700 dark:text-red-300">Hard</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<section className="space-y-4">
|
||||||
|
<h2 className="text-2xl font-bold">Quick Links</h2>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<Link
|
||||||
|
href="/categories"
|
||||||
|
className="p-6 rounded-lg border border-[var(--border)] bg-[var(--card)] hover:border-[var(--primary)] transition-colors"
|
||||||
|
>
|
||||||
|
<h3 className="font-semibold mb-2">Browse by Category</h3>
|
||||||
|
<p className="text-[var(--muted-foreground)] text-sm">
|
||||||
|
Arrays, Trees, Graphs, Dynamic Programming, and more
|
||||||
|
</p>
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/patterns"
|
||||||
|
className="p-6 rounded-lg border border-[var(--border)] bg-[var(--card)] hover:border-[var(--primary)] transition-colors"
|
||||||
|
>
|
||||||
|
<h3 className="font-semibold mb-2">Browse by Pattern</h3>
|
||||||
|
<p className="text-[var(--muted-foreground)] text-sm">
|
||||||
|
Two Pointers, Sliding Window, BFS, DFS, Backtracking, and more
|
||||||
|
</p>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
63
frontend/src/app/patterns/[slug]/page.tsx
Normal file
63
frontend/src/app/patterns/[slug]/page.tsx
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import { getPattern, getQuestions } from "@/lib/api";
|
||||||
|
import { QuestionCard } from "@/components/questions/question-card";
|
||||||
|
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||||
|
import { notFound } from "next/navigation";
|
||||||
|
|
||||||
|
export default async function PatternDetailPage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ slug: string }>;
|
||||||
|
}) {
|
||||||
|
const { slug } = await params;
|
||||||
|
|
||||||
|
let pattern;
|
||||||
|
let questions;
|
||||||
|
try {
|
||||||
|
[pattern, questions] = await Promise.all([
|
||||||
|
getPattern(slug),
|
||||||
|
getQuestions({ pattern: slug, limit: 50 }),
|
||||||
|
]);
|
||||||
|
} catch {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-4xl mx-auto space-y-8">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold mb-2">{pattern.name}</h1>
|
||||||
|
<p className="text-[var(--muted-foreground)]">
|
||||||
|
{pattern.question_count} questions using this pattern
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{pattern.description && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Description</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>{pattern.description}</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{pattern.when_to_use && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>When to Use</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="whitespace-pre-wrap">
|
||||||
|
{pattern.when_to_use}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h2 className="text-xl font-semibold">Questions</h2>
|
||||||
|
<div className="grid gap-4">
|
||||||
|
{questions.items.map((question) => (
|
||||||
|
<QuestionCard key={question.id} question={question} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
38
frontend/src/app/patterns/page.tsx
Normal file
38
frontend/src/app/patterns/page.tsx
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { getPatterns } from "@/lib/api";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export default async function PatternsPage() {
|
||||||
|
const { items: patterns } = await getPatterns();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<h1 className="text-3xl font-bold">Algorithmic Patterns</h1>
|
||||||
|
<p className="text-[var(--muted-foreground)]">
|
||||||
|
Master common problem-solving patterns to recognize and apply them in
|
||||||
|
interviews.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
{patterns.map((pattern) => (
|
||||||
|
<Link
|
||||||
|
key={pattern.id}
|
||||||
|
href={`/patterns/${pattern.slug}`}
|
||||||
|
className="p-6 rounded-lg border border-[var(--border)] bg-[var(--card)] hover:border-[var(--primary)] transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between mb-2">
|
||||||
|
<h3 className="font-semibold">{pattern.name}</h3>
|
||||||
|
<span className="text-sm text-[var(--muted-foreground)]">
|
||||||
|
{pattern.question_count} questions
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{pattern.description && (
|
||||||
|
<p className="text-sm text-[var(--muted-foreground)] mb-3">
|
||||||
|
{pattern.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
22
frontend/src/app/providers.tsx
Normal file
22
frontend/src/app/providers.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
import { useState, type ReactNode } from "react";
|
||||||
|
|
||||||
|
export function Providers({ children }: { children: ReactNode }) {
|
||||||
|
const [queryClient] = useState(
|
||||||
|
() =>
|
||||||
|
new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
staleTime: 60 * 1000,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
229
frontend/src/app/questions/[slug]/page.tsx
Normal file
229
frontend/src/app/questions/[slug]/page.tsx
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
import { getQuestion } from "@/lib/api";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||||
|
import { CodeBlock } from "@/components/ui/code-block";
|
||||||
|
import { getDifficultyColor, capitalize } from "@/lib/utils";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { notFound } from "next/navigation";
|
||||||
|
|
||||||
|
export default async function QuestionDetailPage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ slug: string }>;
|
||||||
|
}) {
|
||||||
|
const { slug } = await params;
|
||||||
|
|
||||||
|
let question;
|
||||||
|
try {
|
||||||
|
question = await getQuestion(slug);
|
||||||
|
} catch {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-4xl mx-auto space-y-8">
|
||||||
|
<div>
|
||||||
|
<div className="flex items-start justify-between gap-4 mb-4">
|
||||||
|
<h1 className="text-3xl font-bold">{question.title}</h1>
|
||||||
|
<Badge className={getDifficultyColor(question.difficulty)}>
|
||||||
|
{capitalize(question.difficulty)}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap gap-2 mb-4">
|
||||||
|
{question.categories.map((cat) => (
|
||||||
|
<Link key={cat.id} href={`/questions?category=${cat.slug}`}>
|
||||||
|
<Badge variant="outline">{cat.name}</Badge>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
{question.patterns.map((pat) => (
|
||||||
|
<Link key={pat.id} href={`/patterns/${pat.slug}`}>
|
||||||
|
<Badge>{pat.name}</Badge>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{question.leetcode_url && (
|
||||||
|
<a
|
||||||
|
href={question.leetcode_url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="text-[var(--primary)] hover:underline text-sm"
|
||||||
|
>
|
||||||
|
View on LeetCode
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Problem</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="prose dark:prose-invert max-w-none">
|
||||||
|
<div className="whitespace-pre-wrap">{question.description}</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{question.constraints && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Constraints</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<pre className="text-sm whitespace-pre-wrap">
|
||||||
|
{question.constraints}
|
||||||
|
</pre>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{question.examples && question.examples.length > 0 && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Examples</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
{question.examples.map((example, i) => (
|
||||||
|
<div
|
||||||
|
key={i}
|
||||||
|
className="p-4 rounded bg-[var(--secondary)] space-y-2"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<span className="font-medium">Input: </span>
|
||||||
|
<code>{example.input}</code>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span className="font-medium">Output: </span>
|
||||||
|
<code>{example.output}</code>
|
||||||
|
</div>
|
||||||
|
{example.explanation && (
|
||||||
|
<div className="text-sm text-[var(--muted-foreground)]">
|
||||||
|
{example.explanation}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{question.explanation && (
|
||||||
|
<>
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Approach</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="whitespace-pre-wrap">
|
||||||
|
{question.explanation.approach}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Intuition</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="whitespace-pre-wrap">
|
||||||
|
{question.explanation.intuition}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Complexity Analysis</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-2">
|
||||||
|
<div>
|
||||||
|
<span className="font-medium">Time: </span>
|
||||||
|
{question.explanation.time_complexity}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span className="font-medium">Space: </span>
|
||||||
|
{question.explanation.space_complexity}
|
||||||
|
</div>
|
||||||
|
{question.explanation.complexity_explanation && (
|
||||||
|
<div className="text-sm text-[var(--muted-foreground)] mt-2 whitespace-pre-wrap">
|
||||||
|
{question.explanation.complexity_explanation}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{question.explanation.common_pitfalls &&
|
||||||
|
question.explanation.common_pitfalls.length > 0 && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Common Pitfalls</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
{question.explanation.common_pitfalls.map((pitfall, i) => (
|
||||||
|
<div key={i} className="p-4 rounded bg-[var(--secondary)]">
|
||||||
|
<h4 className="font-medium mb-2">{pitfall.title}</h4>
|
||||||
|
<p className="text-sm whitespace-pre-wrap">
|
||||||
|
{pitfall.description}
|
||||||
|
</p>
|
||||||
|
{pitfall.wrong_approach && (
|
||||||
|
<div className="mt-2 text-sm">
|
||||||
|
<span className="text-red-500">Wrong: </span>
|
||||||
|
<code>{pitfall.wrong_approach}</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{pitfall.correct_approach && (
|
||||||
|
<div className="mt-1 text-sm">
|
||||||
|
<span className="text-green-500">Correct: </span>
|
||||||
|
<code>{pitfall.correct_approach}</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{question.explanation.key_takeaways &&
|
||||||
|
question.explanation.key_takeaways.length > 0 && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Key Takeaways</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<ul className="list-disc list-inside space-y-1">
|
||||||
|
{question.explanation.key_takeaways.map((takeaway, i) => (
|
||||||
|
<li key={i}>{takeaway}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{question.solutions.length > 0 && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Solutions</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-6">
|
||||||
|
{question.solutions.map((solution) => (
|
||||||
|
<div key={solution.id}>
|
||||||
|
<div className="flex items-center gap-2 mb-2">
|
||||||
|
<h4 className="font-medium">{solution.approach_name}</h4>
|
||||||
|
{solution.is_optimal && (
|
||||||
|
<Badge className="bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400">
|
||||||
|
Optimal
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{solution.explanation && (
|
||||||
|
<p className="text-sm text-[var(--muted-foreground)] mb-3">
|
||||||
|
{solution.explanation}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<CodeBlock code={solution.code} language={solution.language} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
159
frontend/src/app/questions/page.tsx
Normal file
159
frontend/src/app/questions/page.tsx
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
import { getQuestions, getCategories, getPatterns } from "@/lib/api";
|
||||||
|
import { QuestionCard } from "@/components/questions/question-card";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
interface SearchParams {
|
||||||
|
difficulty?: string;
|
||||||
|
category?: string;
|
||||||
|
pattern?: string;
|
||||||
|
search?: string;
|
||||||
|
page?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function QuestionsPage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<SearchParams>;
|
||||||
|
}) {
|
||||||
|
const params = await searchParams;
|
||||||
|
const [questionsResponse, categoriesResponse, patternsResponse] =
|
||||||
|
await Promise.all([
|
||||||
|
getQuestions({
|
||||||
|
difficulty: params.difficulty,
|
||||||
|
category: params.category,
|
||||||
|
pattern: params.pattern,
|
||||||
|
search: params.search,
|
||||||
|
page: params.page ? parseInt(params.page) : 1,
|
||||||
|
}),
|
||||||
|
getCategories(),
|
||||||
|
getPatterns(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const difficulties = ["easy", "medium", "hard"];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<h1 className="text-3xl font-bold">Questions</h1>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap gap-4 p-4 rounded-lg bg-[var(--secondary)]">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="text-sm text-[var(--muted-foreground)]">
|
||||||
|
Difficulty
|
||||||
|
</label>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Link
|
||||||
|
href="/questions"
|
||||||
|
className={`px-3 py-1 rounded text-sm ${
|
||||||
|
!params.difficulty
|
||||||
|
? "bg-[var(--primary)] text-[var(--primary-foreground)]"
|
||||||
|
: "bg-[var(--card)] hover:bg-[var(--muted)]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
All
|
||||||
|
</Link>
|
||||||
|
{difficulties.map((d) => (
|
||||||
|
<Link
|
||||||
|
key={d}
|
||||||
|
href={`/questions?difficulty=${d}`}
|
||||||
|
className={`px-3 py-1 rounded text-sm capitalize ${
|
||||||
|
params.difficulty === d
|
||||||
|
? "bg-[var(--primary)] text-[var(--primary-foreground)]"
|
||||||
|
: "bg-[var(--card)] hover:bg-[var(--muted)]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{d}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="text-sm text-[var(--muted-foreground)]">
|
||||||
|
Category
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
defaultValue={params.category || ""}
|
||||||
|
className="px-3 py-1 rounded text-sm bg-[var(--card)] border border-[var(--border)]"
|
||||||
|
onChange={(e) => {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
if (e.target.value) {
|
||||||
|
url.searchParams.set("category", e.target.value);
|
||||||
|
} else {
|
||||||
|
url.searchParams.delete("category");
|
||||||
|
}
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="">All Categories</option>
|
||||||
|
{categoriesResponse.items.map((cat) => (
|
||||||
|
<option key={cat.id} value={cat.slug}>
|
||||||
|
{cat.name} ({cat.question_count})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="text-sm text-[var(--muted-foreground)]">
|
||||||
|
Pattern
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
defaultValue={params.pattern || ""}
|
||||||
|
className="px-3 py-1 rounded text-sm bg-[var(--card)] border border-[var(--border)]"
|
||||||
|
onChange={(e) => {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
if (e.target.value) {
|
||||||
|
url.searchParams.set("pattern", e.target.value);
|
||||||
|
} else {
|
||||||
|
url.searchParams.delete("pattern");
|
||||||
|
}
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="">All Patterns</option>
|
||||||
|
{patternsResponse.items.map((pat) => (
|
||||||
|
<option key={pat.id} value={pat.slug}>
|
||||||
|
{pat.name} ({pat.question_count})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-sm text-[var(--muted-foreground)]">
|
||||||
|
Showing {questionsResponse.items.length} of {questionsResponse.total}{" "}
|
||||||
|
questions
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-4">
|
||||||
|
{questionsResponse.items.map((question) => (
|
||||||
|
<QuestionCard key={question.id} question={question} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{questionsResponse.pages > 1 && (
|
||||||
|
<div className="flex justify-center gap-2">
|
||||||
|
{Array.from({ length: questionsResponse.pages }, (_, i) => i + 1).map(
|
||||||
|
(page) => (
|
||||||
|
<Link
|
||||||
|
key={page}
|
||||||
|
href={`/questions?page=${page}${
|
||||||
|
params.difficulty ? `&difficulty=${params.difficulty}` : ""
|
||||||
|
}${params.category ? `&category=${params.category}` : ""}${
|
||||||
|
params.pattern ? `&pattern=${params.pattern}` : ""
|
||||||
|
}`}
|
||||||
|
className={`px-3 py-1 rounded ${
|
||||||
|
page === questionsResponse.page
|
||||||
|
? "bg-[var(--primary)] text-[var(--primary-foreground)]"
|
||||||
|
: "bg-[var(--secondary)] hover:bg-[var(--muted)]"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{page}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user