Skip to content

Commit 05faba5

Browse files
feature: add filters for campuses and make be take new tags
1 parent 9817184 commit 05faba5

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

src/app/api/upload/route.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NextResponse } from "next/server";
22
import { PDFDocument } from "pdf-lib";
3-
import { slots, years } from "@/components/select_options";
3+
import { campuses, exams, semesters, slots, years } from "@/components/select_options";
44
import { connectToDatabase } from "@/lib/mongoose";
55
import cloudinary from "cloudinary";
66
import { type ICourses, type CloudinaryUploadResult } from "@/interface";
@@ -26,6 +26,9 @@ export async function POST(req: Request) {
2626
const slot = formData.get("slot") as string;
2727
const year = formData.get("year") as string;
2828
const exam = formData.get("exam") as string;
29+
const campus = formData.get("campus") as string;
30+
const semester = formData.get("semester") as string;
31+
2932
const isPdf = formData.get("isPdf") === "true"; // Convert string to boolean
3033

3134
const { data } = await axios.get<ICourses[]>(`${process.env.SERVER_URL}/api/course-list`);
@@ -34,7 +37,10 @@ export async function POST(req: Request) {
3437
!(
3538
courses.includes(subject) &&
3639
slots.includes(slot) &&
37-
years.includes(year)
40+
years.includes(year) &&
41+
exams.includes(exam) &&
42+
campuses.includes(campus) &&
43+
semesters.includes(semester)
3844
)
3945
) {
4046
return NextResponse.json({ message: "Bad Request" }, { status: 400 });
@@ -90,6 +96,8 @@ export async function POST(req: Request) {
9096
slot,
9197
year,
9298
exam,
99+
campus,
100+
semester
93101
});
94102
await paper.save();
95103
return NextResponse.json(

src/app/upload/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ const Page = () => {
5858
toast.error("Year is required");
5959
return;
6060
}
61-
61+
if (!campus) {
62+
toast.error("Campus is required");
63+
return;
64+
}
65+
if (!semester) {
66+
toast.error("Semester is required");
67+
return;
68+
}
6269
if (!files || files.length === 0) {
6370
toast.error("No files selected");
6471
return;
@@ -97,6 +104,9 @@ const Page = () => {
97104
formData.append("slot", slot);
98105
formData.append("year", year);
99106
formData.append("exam", exam);
107+
formData.append("semester", semester);
108+
formData.append("campus", campus);
109+
100110
formData.append("isPdf", String(isPdf));
101111

102112
setIsUploading(true);

src/components/CatalogueContent.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { extractBracketContent } from "@/util/utils";
99
import { useRouter } from "next/navigation";
1010
import SearchBar from "./searchbar";
1111
import Loader from "./ui/loader";
12+
import { campuses, semesters } from "./select_options";
1213

1314
const CatalogueContent = () => {
1415
const searchParams = useSearchParams();
@@ -17,6 +18,9 @@ const CatalogueContent = () => {
1718
const exams = searchParams.get("exams")?.split(",");
1819
const slots = searchParams.get("slots")?.split(",");
1920
const years = searchParams.get("years")?.split(",");
21+
const semesters = searchParams.get("semesters")?.split(",");
22+
const campuses = searchParams.get("campuses")?.split(",");
23+
2024
const [selectedExams, setSelectedExams] = useState<string[] | undefined>(
2125
exams,
2226
);
@@ -171,6 +175,8 @@ const CatalogueContent = () => {
171175
initialExams={exams}
172176
initialSlots={slots}
173177
initialYears={years}
178+
initialCampuses={campuses}
179+
initialSemesters={semesters}
174180
onReset={handleResetFilters}
175181
onApplyFilters={handleApplyFilters}
176182
/>

src/components/FilterDialog.tsx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export const FilterDialog = ({
1717
initialExams,
1818
initialSlots,
1919
initialYears,
20+
initialCampuses,
21+
initialSemesters,
2022
onReset,
2123
onApplyFilters,
2224
}: {
@@ -25,6 +27,9 @@ export const FilterDialog = ({
2527
initialExams: string[] | undefined;
2628
initialSlots: string[] | undefined;
2729
initialYears: string[] | undefined;
30+
initialCampuses: string [] | undefined
31+
initialSemesters: string [] | undefined
32+
2833
onReset: () => void;
2934
onApplyFilters: (exams: string[], slots: string[], years: string[]) => void;
3035
}) => {
@@ -37,44 +42,62 @@ export const FilterDialog = ({
3742
const [selectedYears, setSelectedYears] = useState<string[]>(
3843
initialYears ?? [],
3944
);
45+
const [selectedCampuses, setSelectedCampuses] = useState<string[]>(
46+
initialYears ?? [],
47+
);
48+
const [selectedSemesters, setSelectedSemesters] = useState<string[]>(
49+
initialYears ?? [],
50+
);
4051
const [open, setOpen] = useState(false);
4152

4253
useEffect(() => {
4354
setSelectedExams(initialExams ?? []);
4455
setSelectedSlots(initialSlots ?? []);
4556
setSelectedYears(initialYears ?? []);
57+
setSelectedCampuses(initialCampuses ?? []);
58+
setSelectedSemesters(initialSemesters ?? [])
4659
}, [initialExams, initialSlots, initialYears]);
4760

4861
const exams = filterOptions.uniqueExams.map((exam) => ({
4962
label: exam,
5063
value: exam,
5164
}));
5265
const slots = filterOptions.uniqueSlots.map((slot) => ({
53-
label: slot,
66+
label: slot,
5467
value: slot,
5568
}));
5669
const years = filterOptions.uniqueYears.map((year) => ({
5770
label: year,
5871
value: year,
5972
}));
60-
73+
const semesters = filterOptions.uniqueSemesters.map((semester) => ({
74+
label: semester,
75+
value: semester,
76+
}));
77+
const campuses = filterOptions.uniqueCampuses.map((campus) => ({
78+
label: campus,
79+
value: campus,
80+
}));
6181
const handleFilterClick = () => {
6282
onApplyFilters(selectedExams, selectedSlots, selectedYears);
63-
setOpen(false);
83+
setOpen(false);
6484
};
6585

6686
const handleResetClick = () => {
6787
setSelectedExams([]);
6888
setSelectedSlots([]);
6989
setSelectedYears([]);
90+
setSelectedSemesters([]);
91+
92+
setSelectedCampuses([]);
7093
setOpen(false);
7194
onReset();
7295
};
7396

7497
return (
7598
<Dialog open={open} onOpenChange={setOpen}>
7699
<DialogTrigger asChild>
77-
<Button variant="outline" className="py-6 rounded-xl">
100+
<Button variant="outline" className="rounded-xl py-6">
78101
<span>
79102
<SlidersHorizontal />
80103
</span>
@@ -103,6 +126,18 @@ export const FilterDialog = ({
103126
placeholder="Years"
104127
defaultValue={selectedYears}
105128
/>
129+
<MultiSelect
130+
options={semesters}
131+
onValueChange={setSelectedSemesters}
132+
placeholder="Semesters"
133+
defaultValue={selectedSemesters}
134+
/>
135+
<MultiSelect
136+
options={campuses}
137+
onValueChange={setSelectedCampuses}
138+
placeholder="Campuses"
139+
defaultValue={selectedCampuses}
140+
/>
106141
</div>
107142
<div className="flex justify-between">
108143
<Button variant="outline" onClick={handleFilterClick}>

0 commit comments

Comments
 (0)