Skip to content

Commit c70dec6

Browse files
authored
Merge pull request #504 from CodeChefVIT/staging
fix: minor tweaks
2 parents 8087d92 + 9d5e0d3 commit c70dec6

11 files changed

Lines changed: 33 additions & 64 deletions

File tree

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
11
import { NextResponse } from "next/server";
22
import { connectToDatabase } from "@/lib/database/mongoose";
3-
import UpcomingSlot from "@/db/upcoming-slot";
43
import UpcomingSubject from "@/db/upcoming-paper";
5-
import { calculateCorrespondingSlots } from "@/lib/utils/slot-calculation";
64

75
export const dynamic = "force-dynamic";
86

97
export async function GET() {
108
try {
119
await connectToDatabase();
12-
const upcomingSlot = await UpcomingSlot.find();
13-
const slot = upcomingSlot[0]?.slot;
14-
15-
if (!slot) {
16-
return NextResponse.json(
17-
{
18-
message: "No slot found.",
19-
},
20-
{ status: 404 },
21-
);
22-
}
23-
24-
const correspondingSlots = calculateCorrespondingSlots(slot);
25-
const selectedSubjects = await UpcomingSubject.find({
26-
slots: { $in: correspondingSlots },
27-
});
10+
const selectedSubjects = await UpcomingSubject.find()
11+
.sort({ _id: 1 })
12+
.limit(16)
13+
.lean();
2814

2915
if (selectedSubjects.length === 0) {
3016
return NextResponse.json(
@@ -47,4 +33,4 @@ export async function GET() {
4733
{ status: 500 },
4834
);
4935
}
50-
}
36+
}

src/app/request/page.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ export default function PaperRequest() {
5252
"/api/upcoming-papers",
5353
);
5454

55-
const randomPapers = [...response.data]
56-
.sort(() => Math.random() - 0.5)
57-
.slice(0, 8);
58-
59-
setDisplayPapers(randomPapers);
55+
setDisplayPapers(response.data);
6056
} catch (error) {
6157
console.error("Failed to fetch papers:", error);
6258
} finally {

src/components/CatalogueContent.tsx

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,31 +177,6 @@ const CatalogueContentInner = ({ subject }: { subject: string | null }) => {
177177
void fetchPapers();
178178
}, [subject, isMounted, setPapers, setFilterOptions]);
179179

180-
useEffect(() => {
181-
if (!papers.length) return;
182-
183-
const filtered = [...papers];
184-
185-
if (sortOption === "asc") {
186-
filtered.sort((a, b) => a.year.localeCompare(b.year));
187-
} else if (sortOption === "desc") {
188-
filtered.sort((a, b) => b.year.localeCompare(a.year));
189-
}
190-
191-
setFilteredPapers(filtered);
192-
}, [
193-
papers,
194-
selectedExams,
195-
selectedSlots,
196-
selectedYears,
197-
selectedSemesters,
198-
selectedCampuses,
199-
selectedAnswerKeyIncluded,
200-
sortOption,
201-
setFilteredPapers,
202-
setAppliedFilters,
203-
]);
204-
205180
useEffect(() => {
206181
if (!papers.length) return;
207182

@@ -255,6 +230,7 @@ const CatalogueContentInner = ({ subject }: { subject: string | null }) => {
255230
selectedSemesters,
256231
selectedCampuses,
257232
selectedAnswerKeyIncluded,
233+
sortOption,
258234
setFilteredPapers,
259235
setAppliedFilters,
260236
]);

src/components/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default function Footer() {
104104
{/* Events */}
105105
<div className="flex w-full flex-col gap-2 text-black dark:text-white lg:w-[15%]">
106106
<h3 className="font-jost text-xl font-semibold">Events</h3>
107-
<Link href="https://devsoc25.codechefvit.com" target="_blank">DevSOC</Link>
107+
<Link href="https://devsoc26.codechefvit.com" target="_blank">DevSOC</Link>
108108
<Link href="https://gravitas.codechefvit.com" target="_blank">CookOff</Link>
109109
<Link href="https://gravitas.codechefvit.com" target="_blank">Clueminati</Link>
110110
</div>

src/components/PinnedPapersCarousel.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,19 @@ function PinnedPapersCarousel() {
199199
</CarouselItem>
200200
) : (
201201
chunkedPapers.map((paperGroup, index) => {
202-
const placeholdersNeeded =
203-
(chunkSize - paperGroup.length) % chunkSize;
202+
const columns = chunkSize === 2 ? 1 : chunkSize === 4 ? 2 : 4;
203+
const rows = Math.max(1, Math.ceil(paperGroup.length / columns));
204+
const placeholdersNeeded = columns * rows - paperGroup.length;
204205
return (
205206
<CarouselItem
206207
key={`carousel-item-${index}`}
207208
className={`grid ${
208-
chunkSize === 2
209-
? "grid-cols-1 grid-rows-2"
210-
: chunkSize === 4
211-
? "grid-cols-2 grid-rows-2"
209+
columns === 1
210+
? "grid-cols-1"
211+
: columns === 2
212+
? "grid-cols-2"
212213
: "grid-cols-4"
213-
} gap-4 lg:auto-rows-fr`}
214+
} ${rows === 1 ? "grid-rows-1" : "grid-rows-2"} gap-4 lg:auto-rows-fr`}
214215
>
215216
{paperGroup.map((paper, subIndex) =>
216217
paper.subject === "add_subject_button" ? (
@@ -264,4 +265,4 @@ function PinnedPapersCarousel() {
264265
);
265266
}
266267

267-
export default PinnedPapersCarousel;
268+
export default PinnedPapersCarousel;

src/components/ReportButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ export default function ReportButton(){
1010
const { paperId, subject, exam, slot, year } = usePaper();
1111
const [open, setOpen] = useState(false);
1212
return (
13-
<>
13+
<>
1414
<Button
15+
1516
onClick={() => setOpen(true)}
1617
className="h-10 w-10 rounded p-0 text-white transition hover:bg-red-600 bg-red-500"
18+
title="Report this paper"
1719
>
1820
<FaFlag className="text-sm" />
1921
</Button>

src/components/ShareButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function ShareButton() {
3030
return (
3131
<Dialog>
3232
<DialogTrigger asChild>
33-
<Button className="aspect-square h-10 w-10 p-0 rounded text-white bg-[#6536c1] transition hover:bg-[#7d4fc7]">
33+
<Button className="aspect-square h-10 w-10 p-0 rounded text-white bg-[#6536c1] transition hover:bg-[#7d4fc7]" title="Share this paper">
3434
<FaShare />
3535
</Button>
3636
</DialogTrigger>
@@ -47,6 +47,7 @@ export default function ShareButton() {
4747
type="submit"
4848
size="sm"
4949
className="flex w-fit items-center justify-between gap-5 px-3"
50+
title="Copy link to clipboard"
5051
onClick={async () => {
5152
await toast.promise(
5253
navigator.clipboard.writeText(paperPath), // This is a promise

src/components/SideBar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ function SideBar() {
1919
handleApplyFilters,
2020
} = useFilters();
2121
const exams =
22-
filterOptions?.unique_exams.map((exam) => ({ label: exam, value: exam })) ??
23-
[];
22+
filterOptions?.unique_exams
23+
.sort((a, b) => a.localeCompare(b))
24+
.map((exam) => ({ label: exam, value: exam })) ?? [];
2425
const slots =
2526
filterOptions?.unique_slots
2627
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))

src/components/UpcomingPaper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default function PaperCard({ subject, slots }: PaperCardProps) {
105105

106106
{
107107
<div className="mt-4 flex flex-wrap gap-2 font-play">
108-
{slots?.map((slotValue, index) => (
108+
{[...slots].sort().map((slotValue, index) => (
109109
<Capsule key={index}>{slotValue}</Capsule>
110110
))}
111111
</div>

src/components/multi-select.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ export const MultiSelect = React.forwardRef<
307307
</div>
308308
<span>(Select All)</span>
309309
</CommandItem>
310-
{options.map((option) => {
310+
{options
311+
.sort((a, b) => a.label.localeCompare(b.label))
312+
.map((option) => {
311313
const isSelected = selectedValues.includes(option.value);
312314
return (
313315
<CommandItem

0 commit comments

Comments
 (0)