diff --git a/src/app/api/upcoming-papers/route.ts b/src/app/api/upcoming-papers/route.ts index 72d52e9..9c76428 100644 --- a/src/app/api/upcoming-papers/route.ts +++ b/src/app/api/upcoming-papers/route.ts @@ -1,30 +1,16 @@ import { NextResponse } from "next/server"; import { connectToDatabase } from "@/lib/database/mongoose"; -import UpcomingSlot from "@/db/upcoming-slot"; import UpcomingSubject from "@/db/upcoming-paper"; -import { calculateCorrespondingSlots } from "@/lib/utils/slot-calculation"; export const dynamic = "force-dynamic"; export async function GET() { try { await connectToDatabase(); - const upcomingSlot = await UpcomingSlot.find(); - const slot = upcomingSlot[0]?.slot; - - if (!slot) { - return NextResponse.json( - { - message: "No slot found.", - }, - { status: 404 }, - ); - } - - const correspondingSlots = calculateCorrespondingSlots(slot); - const selectedSubjects = await UpcomingSubject.find({ - slots: { $in: correspondingSlots }, - }); + const selectedSubjects = await UpcomingSubject.find() + .sort({ _id: 1 }) + .limit(16) + .lean(); if (selectedSubjects.length === 0) { return NextResponse.json( @@ -47,4 +33,4 @@ export async function GET() { { status: 500 }, ); } -} \ No newline at end of file +} diff --git a/src/app/request/page.tsx b/src/app/request/page.tsx index 2529d90..97367f6 100644 --- a/src/app/request/page.tsx +++ b/src/app/request/page.tsx @@ -52,11 +52,7 @@ export default function PaperRequest() { "/api/upcoming-papers", ); - const randomPapers = [...response.data] - .sort(() => Math.random() - 0.5) - .slice(0, 8); - - setDisplayPapers(randomPapers); + setDisplayPapers(response.data); } catch (error) { console.error("Failed to fetch papers:", error); } finally { diff --git a/src/components/CatalogueContent.tsx b/src/components/CatalogueContent.tsx index 340cc51..df84ff6 100644 --- a/src/components/CatalogueContent.tsx +++ b/src/components/CatalogueContent.tsx @@ -177,31 +177,6 @@ const CatalogueContentInner = ({ subject }: { subject: string | null }) => { void fetchPapers(); }, [subject, isMounted, setPapers, setFilterOptions]); - useEffect(() => { - if (!papers.length) return; - - const filtered = [...papers]; - - if (sortOption === "asc") { - filtered.sort((a, b) => a.year.localeCompare(b.year)); - } else if (sortOption === "desc") { - filtered.sort((a, b) => b.year.localeCompare(a.year)); - } - - setFilteredPapers(filtered); - }, [ - papers, - selectedExams, - selectedSlots, - selectedYears, - selectedSemesters, - selectedCampuses, - selectedAnswerKeyIncluded, - sortOption, - setFilteredPapers, - setAppliedFilters, - ]); - useEffect(() => { if (!papers.length) return; @@ -255,6 +230,7 @@ const CatalogueContentInner = ({ subject }: { subject: string | null }) => { selectedSemesters, selectedCampuses, selectedAnswerKeyIncluded, + sortOption, setFilteredPapers, setAppliedFilters, ]); diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 4ec806a..c59b7b4 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -104,7 +104,7 @@ export default function Footer() { {/* Events */}

Events

- DevSOC + DevSOC CookOff Clueminati
diff --git a/src/components/PinnedPapersCarousel.tsx b/src/components/PinnedPapersCarousel.tsx index 3ee010a..ec90d28 100644 --- a/src/components/PinnedPapersCarousel.tsx +++ b/src/components/PinnedPapersCarousel.tsx @@ -199,18 +199,19 @@ function PinnedPapersCarousel() { ) : ( chunkedPapers.map((paperGroup, index) => { - const placeholdersNeeded = - (chunkSize - paperGroup.length) % chunkSize; + const columns = chunkSize === 2 ? 1 : chunkSize === 4 ? 2 : 4; + const rows = Math.max(1, Math.ceil(paperGroup.length / columns)); + const placeholdersNeeded = columns * rows - paperGroup.length; return ( {paperGroup.map((paper, subIndex) => paper.subject === "add_subject_button" ? ( @@ -264,4 +265,4 @@ function PinnedPapersCarousel() { ); } -export default PinnedPapersCarousel; +export default PinnedPapersCarousel; \ No newline at end of file diff --git a/src/components/ReportButton.tsx b/src/components/ReportButton.tsx index 80cd7f8..8453351 100644 --- a/src/components/ReportButton.tsx +++ b/src/components/ReportButton.tsx @@ -10,10 +10,12 @@ export default function ReportButton(){ const { paperId, subject, exam, slot, year } = usePaper(); const [open, setOpen] = useState(false); return ( - <> + <> diff --git a/src/components/ShareButton.tsx b/src/components/ShareButton.tsx index 60fc3c1..e06c7a6 100644 --- a/src/components/ShareButton.tsx +++ b/src/components/ShareButton.tsx @@ -30,7 +30,7 @@ export default function ShareButton() { return ( - @@ -47,6 +47,7 @@ export default function ShareButton() { type="submit" size="sm" className="flex w-fit items-center justify-between gap-5 px-3" + title="Copy link to clipboard" onClick={async () => { await toast.promise( navigator.clipboard.writeText(paperPath), // This is a promise diff --git a/src/components/SideBar.tsx b/src/components/SideBar.tsx index f5dc1cf..a3b535b 100644 --- a/src/components/SideBar.tsx +++ b/src/components/SideBar.tsx @@ -19,8 +19,9 @@ function SideBar() { handleApplyFilters, } = useFilters(); const exams = - filterOptions?.unique_exams.map((exam) => ({ label: exam, value: exam })) ?? - []; + filterOptions?.unique_exams + .sort((a, b) => a.localeCompare(b)) + .map((exam) => ({ label: exam, value: exam })) ?? []; const slots = filterOptions?.unique_slots .sort((a, b) => a.localeCompare(b, undefined, { numeric: true })) diff --git a/src/components/UpcomingPaper.tsx b/src/components/UpcomingPaper.tsx index 4da6923..275fb0b 100644 --- a/src/components/UpcomingPaper.tsx +++ b/src/components/UpcomingPaper.tsx @@ -105,7 +105,7 @@ export default function PaperCard({ subject, slots }: PaperCardProps) { {
- {slots?.map((slotValue, index) => ( + {[...slots].sort().map((slotValue, index) => ( {slotValue} ))}
diff --git a/src/components/multi-select.tsx b/src/components/multi-select.tsx index 1e5a78a..ae11f1b 100644 --- a/src/components/multi-select.tsx +++ b/src/components/multi-select.tsx @@ -307,7 +307,9 @@ export const MultiSelect = React.forwardRef< (Select All) - {options.map((option) => { + {options + .sort((a, b) => a.label.localeCompare(b.label)) + .map((option) => { const isSelected = selectedValues.includes(option.value); return ( {isFullscreen ? : } @@ -121,6 +122,7 @@ const Controls = memo(function Controls({documentId, toggleFullscreen, isFullscr @@ -131,6 +133,7 @@ const Controls = memo(function Controls({documentId, toggleFullscreen, isFullscr onClick={zoomOut} disabled={typeof zoomLevel === "number" && zoomLevel <= 0.25} className="h-10 w-10 rounded p-0 text-white bg-[#6536c1] transition hover:bg-[#7d4fc7] disabled:bg-gray-400" + title="Zoom out" > @@ -143,6 +146,7 @@ const Controls = memo(function Controls({documentId, toggleFullscreen, isFullscr onClick={zoomIn} disabled={typeof zoomLevel === "number" && zoomLevel >= 3} className="h-10 w-10 rounded p-0 text-white bg-[#6536c1] transition hover:bg-[#7d4fc7] disabled:bg-gray-400" + title="Zoom in" >