Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/app/frq-grading/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use client";

import FRQGradingRenderer from "@/components/frq/gradingRenderer";
import { db } from "@/lib/firebase";
import type { FRQSubmission } from "@/types/frq";
import { doc, getDoc } from "firebase/firestore";
import { useEffect, useState } from "react";

type PageProps = {
params: {
id: string;
};
};

const Page = ({ params }: PageProps) => {
const [frq, setFrq] = useState<FRQSubmission | null>(null);
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
const fetchFrq = async () => {
try {
const docRef = doc(db, "ungraded-frqs", params.id);
const docSnap = await getDoc(docRef);

if (docSnap.exists()) {
setFrq({
id: docSnap.id,
...(docSnap.data() as FRQSubmission),
});
} else {
setFrq(null);
}
} catch (error) {
console.error("Error fetching FRQ:", error);
setFrq(null);
} finally {
setIsLoading(false);
}
};

void fetchFrq();
}, [params.id]);

if (isLoading) {
return <div>Loading...</div>;
}

return <FRQGradingRenderer frq={frq ?? null} />;
};

export default Page;
47 changes: 47 additions & 0 deletions src/app/frq-grading/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use client";

import Link from "next/link";
import { db } from "@/lib/firebase";
import { collection, getDocs } from "firebase/firestore";
import { useEffect, useState } from "react";

const Page = () => {
const [frqIds, setFrqIds] = useState<string[] | null>(null);

useEffect(() => {
const fetchFrqs = async () => {
const collectionRef = collection(db, "ungraded-frqs");
const snapshot = await getDocs(collectionRef);
setFrqIds(snapshot.docs.map((doc) => doc.id));
};

fetchFrqs().catch((error) => {
console.error("Error fetching ungraded FRQs:", error);
setFrqIds([]);
});
}, []);

if (frqIds === null) {
return <div>Loading...</div>;
}

return (
<div>
<h1>Ungraded FRQs</h1>

{frqIds.length === 0 ? (
<p>No ungraded FRQs found.</p>
) : (
<ul>
{frqIds.map((id) => (
<li key={id}>
<Link href={`/frq-grading/${id}`}>{id}</Link>
</li>
))}
</ul>
)}
</div>
);
};

export default Page;
15 changes: 15 additions & 0 deletions src/components/frq/gradingRenderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { FRQSubmission } from "@/types/frq";

type FRQGradingRendererProps = {
frq: FRQSubmission | null;
};

const FRQGradingRenderer = ({ frq }: FRQGradingRendererProps) => {
if (!frq) {
return <div>FRQ not found.</div>;
}

return <div>FRQ found. Grading page loaded successfully.</div>;
};

export default FRQGradingRenderer;