Skip to content

Commit 227bd1c

Browse files
thumbnail
1 parent c518af4 commit 227bd1c

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

src/app/api/papers/route.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { NextResponse } from "next/server";
1+
import { NextResponse, NextRequest } from "next/server";
22
import { connectToDatabase } from "@/lib/mongoose";
33
import Paper from "@/db/papers";
44
import Cryptr from "cryptr";
55
import { type IPaper } from "@/interface";
66

7+
78
const cryptr = new Cryptr(process.env.CRYPTO_SECRET ?? "default_crypto_secret");
89

910
export const dynamic = "force-dynamic";
1011

11-
export async function GET(req: Request) {
12+
export async function GET(req: NextRequest) {
1213
try {
1314
await connectToDatabase();
14-
const url = new URL(req.url);
15-
const subject = url.searchParams.get("subject");
15+
const url = req.nextUrl.searchParams;
16+
const subject = url.get("subject");
17+
console.log("Subject:", subject);
18+
const escapeRegExp = (text: string) => {
19+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20+
};
21+
const escapedSubject = escapeRegExp(subject!);
1622

1723
if (!subject) {
1824
return NextResponse.json(
@@ -22,8 +28,9 @@ export async function GET(req: Request) {
2228
}
2329

2430
const papers: IPaper[] = await Paper.find({
25-
subject: { $regex: new RegExp(`^${subject}$`, "i") },
31+
subject: { $regex: new RegExp(`${escapedSubject}`, "i") },
2632
});
33+
console.log("Papers:", papers);
2734

2835
if (papers.length === 0) {
2936
return NextResponse.json(

src/app/catalogue/page.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ interface Paper {
2020
_id: string;
2121
exam: string;
2222
finalUrl: string;
23+
thumbnailUrl: string;
2324
slot: string;
2425
subject: string;
2526
year: string;
2627
}
27-
interface Filters{
28+
interface Filters {
2829
paper: Paper;
29-
uniqueExams: string [];
30-
uniqueSlots: string [];
31-
uniqueYears: string []
30+
uniqueExams: string[];
31+
uniqueSlots: string[];
32+
uniqueYears: string[];
3233
}
3334
const cryptr = new Cryptr(
3435
process.env.NEXT_PUBLIC_CRYPTO_SECRET ?? "default_crypto_secret",
@@ -41,7 +42,7 @@ const CatalogueContent = () => {
4142
const [papers, setPapers] = useState<Paper[]>([]);
4243
const [error, setError] = useState<string | null>(null);
4344
const [loading, setLoading] = useState<boolean>(false);
44-
const [filterOptions, setFilterOptions] = useState<Filters []>([]);
45+
const [filterOptions, setFilterOptions] = useState<Filters[]>([]);
4546
useEffect(() => {
4647
if (subject) {
4748
const fetchPapers = async () => {
@@ -83,29 +84,27 @@ const CatalogueContent = () => {
8384

8485
return (
8586
<div className="min-h-screen bg-gray-50 p-8">
86-
8787
<button
8888
onClick={() => router.push("/")}
8989
className="mb-4 rounded-md bg-blue-500 px-4 py-2 text-white"
90-
>
90+
>
9191
Back to Search
9292
</button>
93-
<Dialog>
94-
<DialogTrigger className=" rounded-lg bg-[#7480FF] px-8 py-3 text-white">Filter</DialogTrigger>
95-
<DialogContent>
96-
<DialogHeader>
97-
<DialogTitle>Choose your filters</DialogTitle>
98-
<DialogDescription>
99-
{}
100-
</DialogDescription>
101-
</DialogHeader>
102-
</DialogContent>
103-
</Dialog>
93+
<Dialog>
94+
<DialogTrigger className=" rounded-lg bg-[#7480FF] px-8 py-3 text-white">
95+
Filter
96+
</DialogTrigger>
97+
<DialogContent>
98+
<DialogHeader>
99+
<DialogTitle>Choose your filters</DialogTitle>
100+
<DialogDescription>{}</DialogDescription>
101+
</DialogHeader>
102+
</DialogContent>
103+
</Dialog>
104104

105105
{/* <h1 className="mb-4 text-2xl font-bold">Papers for {subject}</h1> */}
106106
{error && <p className="text-red-500">{error}</p>}
107107

108-
109108
{loading ? (
110109
<p>Loading papers...</p>
111110
) : papers.length > 0 ? (
@@ -142,7 +141,7 @@ function Card({ paper }: { paper: Paper }) {
142141
className={`space-y-1 rounded-md border border-black border-opacity-50 ${checked ? "bg-[#EEF2FF]" : "bg-white"} p-4 `}
143142
>
144143
<Image
145-
src={paper.finalUrl}
144+
src={paper.thumbnailUrl}
146145
alt={paper.subject}
147146
// layout="responsive"
148147
width={320} // Adjust width to maintain aspect ratio if needed
@@ -171,13 +170,15 @@ function Card({ paper }: { paper: Paper }) {
171170
<p className="text-sm">Select</p>
172171
</div>
173172
<div className="flex gap-2">
174-
<Eye />
175173
<a
176174
href={paper.finalUrl}
177175
target="_blank"
178176
rel="noopener noreferrer"
179177
// className="text-blue-500 hover:underline"
180178
>
179+
<Eye />
180+
</a>
181+
<a href={paper.finalUrl} download>
181182
<Download />
182183
</a>
183184
</div>

0 commit comments

Comments
 (0)