diff --git a/src/app/(dashboard)/generate-pro /page.tsx b/src/app/(dashboard)/generate-pro /page.tsx
new file mode 100644
index 0000000..251abb6
--- /dev/null
+++ b/src/app/(dashboard)/generate-pro /page.tsx
@@ -0,0 +1,13 @@
+import Generate from "@/components/core/generate";
+
+export default function GeneratePage() {
+ return (
+ //
+ //
Generate Flashcards
+ //
+ //
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/src/app/flashcards/[id] /page.tsx b/src/app/flashcards/[id] /page.tsx
new file mode 100644
index 0000000..c2f74be
--- /dev/null
+++ b/src/app/flashcards/[id] /page.tsx
@@ -0,0 +1,173 @@
+// app/flashcards/[id]/page.tsx
+
+'use client';
+
+import { useEffect, useState } from 'react';
+import { useRouter, useParams } from 'next/navigation';
+import { deleteFlashcardSet, fetchFlashcardsBySet } from '@/firebase/firestore/utils';
+import { Button } from '@/components/ui/button';
+import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
+import { RefreshCw, ArrowRight, ArrowLeft, ChevronLeft, Loader2, Trash } from 'lucide-react';
+import type { Flashcard } from '@/types';
+import { useUser } from '@clerk/clerk-react';
+
+export default function FlashcardSetPage() {
+ const [flashcards, setFlashcards] = useState([]);
+ const [loading, setLoading] = useState(true);
+ const [currentIndex, setCurrentIndex] = useState(0);
+ const [flip, setFlip] = useState(false);
+ const router = useRouter();
+ const { id } = useParams();
+ const { user, isLoaded } = useUser(); // Add isLoaded to check if user data is loaded
+
+ useEffect(() => {
+ if (id && isLoaded && user) {
+ const fetchData = async () => {
+ try {
+ const userId = user.id; // Get the actual userId from Clerk
+ const fetchedFlashcards = await fetchFlashcardsBySet(userId, id as string);
+ setFlashcards(fetchedFlashcards);
+ } catch (error) {
+ console.error('Error fetching flashcards:', error);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ fetchData();
+ }
+ }, [id, isLoaded, user]);
+
+ const currentCard = flashcards[currentIndex];
+
+ const handleFlip = () => setFlip(!flip);
+
+ const handleNext = () => {
+ setCurrentIndex((prevIndex) => (prevIndex + 1) % flashcards.length);
+ setFlip(false);
+ };
+
+ const handlePrevious = () => {
+ setCurrentIndex((prevIndex) => (prevIndex - 1 + flashcards.length) % flashcards.length);
+ setFlip(false);
+ };
+
+ // Key Events
+ useEffect(() => {
+ const handleKeyDown = (event: { key: string; }) => {
+ if (event.key === 'ArrowRight') {
+ handleNext();
+ } else if (event.key === 'ArrowLeft') {
+ handlePrevious();
+ } else if (event.key === ' ' || event.key === 'Enter') {
+ handleFlip();
+ }
+ };
+
+ document.addEventListener('keydown', handleKeyDown);
+
+ // Cleanup function
+ return () => {
+ document.removeEventListener('keydown', handleKeyDown);
+ };
+ },);
+
+ if (loading) return (
+
+
+
+ );
+
+ const handleDeleteSet = async () => {
+ try {
+ if (isLoaded && user) {
+ const userId = user.id; // Get the actual userId from Clerk
+ await deleteFlashcardSet(userId, id as string);
+ router.push('/flashcards'); // Redirect to flashcard sets page after deletion
+ }
+ } catch (error) {
+ console.error('Error deleting flashcard set:', error);
+ }
+ };
+
+ return (
+
+ {/* Back button in top-left corner */}
+
+
+ {flashcards.length > 0 ? (
+
+
+
+ Flashcards
+ {currentCard && (
+
+ Card {currentIndex + 1} of {flashcards.length}
+
+ )}
+
+
+
+
+ {currentCard ? (
+ <>
+ {currentCard.question}
+ {flip && {currentCard.answer}
}
+ >
+ ) : (
+ No flashcards available.
+ )}
+
+
+
+
+
+
+ ) : (
+
No flashcards found for this set.
+ )}
+
+ );
+}
diff --git a/src/app/result /page.tsx b/src/app/result /page.tsx
new file mode 100644
index 0000000..025166e
--- /dev/null
+++ b/src/app/result /page.tsx
@@ -0,0 +1,83 @@
+'use client'
+
+import { useRouter, useSearchParams } from 'next/navigation'
+import { useEffect, useState } from 'react'
+import { Card, CardContent } from "@/components/ui/card"
+import { Button } from "@/components/ui/button"
+import { Loader2 } from 'lucide-react'
+import Link from 'next/link'
+
+interface Session {
+ payment_status: string;
+ // Add other session properties as needed
+}
+
+export default function ResultPage() {
+ const router = useRouter()
+ const searchParams = useSearchParams()
+ const session_id = searchParams.get('session_id')
+ const [loading, setLoading] = useState(true)
+ const [session, setSession] = useState(null)
+ const [error, setError] = useState(null)
+
+ useEffect(() => {
+ const fetchCheckoutSession = async () => {
+ if (!session_id) return
+ try {
+ const res = await fetch(`/api/checkout-sessions?session_id=${session_id}`)
+ const sessionData = await res.json()
+ if (res.ok) {
+ setSession(sessionData)
+ } else {
+ setError(sessionData.error)
+ }
+ } catch (err) {
+ setError('An error occurred while retrieving the session.')
+ } finally {
+ setLoading(false)
+ }
+ }
+ fetchCheckoutSession()
+ }, [session_id])
+
+ if (loading) {
+ return (
+
+
+
+ )
+ }
+
+ return (
+
+
+
Payment Result
+
+
+
+
+
+
+ {error ? (
+ {error}
+ ) : session?.payment_status === 'paid' ? (
+ <>
+ Thank you for your purchase!
+ Session ID: {session_id}
+
+ We have received your payment. You will receive an email with the order details shortly.
+
+ >
+ ) : (
+ <>
+ Payment failed
+
+ Your payment was not successful. Please try again.
+
+ >
+ )}
+
+
+
+ )
+}
\ No newline at end of file
diff --git a/src/config /site.ts b/src/config /site.ts
new file mode 100644
index 0000000..1a362cc
--- /dev/null
+++ b/src/config /site.ts
@@ -0,0 +1,17 @@
+import { SiteConfig } from "@/types";
+
+const site_url = process.env.NEXT_PUBLIC_APP_URL;
+
+export const siteConfig: SiteConfig = {
+ name: "AI Flashcards App",
+ description:
+ "AI Flashcards App is a flashcard app that uses OpenAI API to generate flashcards. Users can create flashcards based ona topic. The app is powered by Next.js and Tailwind CSS.",
+ url: "site_url",
+ ogImage: `${site_url}/_static/og.jpg`,
+ links: {
+ twitter: "https://twitter.com/00tush_",
+ github: "https://github.com/tushcmd/ai-flashcards",
+ portfolio: "https://tushdev.co",
+ },
+ mailSupport: "muturidavid854@gmail.com",
+};
\ No newline at end of file