Skip to content

Commit 3aecc51

Browse files
Refactor components for improved readability and performance
- Removed unused imports in Footer, RelatedPaper, and StoredPapers components. - Added titles to anchor tags for better accessibility in Navbar. - Cleaned up spacing and formatting in various components including Searchbar and MultiSelect. - Updated comments for clarity in SideBar and UpcomingPaper components. - Enhanced button accessibility by adding titles in Searchbar and SearchbarChild components. - Improved code consistency by ensuring proper use of semicolons and formatting across multiple files. - Refactored QR component for better readability. - Updated FAQ component for improved layout and readability. - Cleaned up imports and formatting in various UI components including Dialog, Popover, and Select.
1 parent 2a60fed commit 3aecc51

33 files changed

+283
-294
lines changed

src/components/Banner.tsx

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,48 @@ import Link from "next/link";
55

66
export default function Banner() {
77
return (
8-
<>
9-
<div className="flex h-fit w-full items-center justify-center bg-[#434dba] px-6 py-3 text-center text-white sm:h-14 sm:py-0 md:sticky md:top-0 md:justify-between md:text-left z-50">
10-
<div className="flex items-center gap-x-2">
11-
<Image
12-
src={devsoc as HTMLImageElement}
13-
alt="devsoclogo"
14-
height={40}
15-
width={40}
16-
className="md:hidden"
17-
/>
18-
<span className="hidden md:block">
19-
Register for DevSOC&apos;25 and enjoy a 3 day full OD to unwind after CATs!
20-
</span>
8+
<div className="z-50 flex h-fit w-full items-center justify-center bg-[#434dba] px-6 py-3 text-center text-white sm:h-14 sm:py-0 md:sticky md:top-0 md:justify-between md:text-left">
9+
<div className="flex items-center gap-x-2">
10+
<Image
11+
src={devsoc as HTMLImageElement}
12+
alt="devsoclogo"
13+
height={40}
14+
width={40}
15+
className="md:hidden"
16+
/>
17+
<span className="hidden md:block">
18+
Register for DevSOC&apos;25 and enjoy a 3 day full OD to unwind after
19+
CATs!
20+
</span>
21+
<Link
22+
href="https://devsoc.codechefvit.com/"
23+
className="block md:hidden"
24+
rel="noopener noreferrer"
25+
target="_blank"
26+
>
27+
Register for DevSOC&apos;25
28+
</Link>
29+
</div>
30+
<div className="hidden md:block">
31+
<Button className="bg-[#AA7AE7]">
2132
<Link
33+
className="flex items-center gap-x-2"
2234
href="https://devsoc.codechefvit.com/"
23-
className="block md:hidden"
2435
rel="noopener noreferrer"
2536
target="_blank"
2637
>
27-
Register for DevSOC&apos;25
38+
<span>
39+
<Image
40+
src={devsoc as HTMLImageElement}
41+
alt="devsoclogo"
42+
height={20}
43+
width={20}
44+
/>
45+
</span>
46+
<span className="font-yerk text-xs">Register</span>
2847
</Link>
29-
</div>
30-
<div className="hidden md:block">
31-
<Button className="bg-[#AA7AE7]">
32-
<Link
33-
className="flex gap-x-2 items-center"
34-
href="https://devsoc.codechefvit.com/"
35-
rel="noopener noreferrer"
36-
target="_blank"
37-
>
38-
<span>
39-
<Image
40-
src={devsoc as HTMLImageElement}
41-
alt="devsoclogo"
42-
height={20}
43-
width={20}
44-
/>
45-
</span>
46-
<span className="font-yerk text-xs">Register</span>
47-
</Link>
48-
</Button>
49-
</div>
48+
</Button>
5049
</div>
51-
</>
50+
</div>
5251
);
5352
}

src/components/Card.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use client";
2+
23
import { useEffect, useState } from "react";
34
import { type IPaper } from "@/interface";
45
import Image from "next/image";

src/components/CatalogueContent.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,11 @@ import Card from "./Card";
99
import { extractBracketContent } from "@/util/utils";
1010
import { useRouter } from "next/navigation";
1111
import Loader from "./ui/loader";
12-
import filterIcon from "../assets/filterIcon.svg";
13-
import filterd from "@/assets/filterd.svg";
14-
import Image from "next/image";
1512
import SideBar from "../components/SideBar";
16-
import toast from "react-hot-toast";
1713
import Error from "./Error";
1814
import { Filter } from "lucide-react";
19-
import {
20-
Sheet,
21-
SheetContent,
22-
SheetDescription,
23-
SheetHeader,
24-
SheetTitle,
25-
SheetTrigger,
26-
} from "./ui/sheet";
15+
import { Sheet, SheetContent, SheetTrigger } from "./ui/sheet";
16+
2717
export async function downloadFile(url: string, filename: string) {
2818
try {
2919
const response = await axios.get(url, { responseType: "blob" });
@@ -33,7 +23,7 @@ export async function downloadFile(url: string, filename: string) {
3323
link.download = filename;
3424
link.click();
3525
window.URL.revokeObjectURL(link.href);
36-
} catch (error) { }
26+
} catch (error) {}
3727
}
3828

3929
const CatalogueContent = () => {
@@ -45,7 +35,8 @@ const CatalogueContent = () => {
4535
const years = searchParams.get("years")?.split(",");
4636
const campuses = searchParams.get("campus")?.split(",");
4737
const semesters = searchParams.get("semester")?.split(",");
48-
const answerKeyIncluded = searchParams.get("answerkey")==="true"? true: false;
38+
const answerKeyIncluded =
39+
searchParams.get("answerkey") === "true" ? true : false;
4940
// Initialize state with searchParams
5041
const [selectedExams, setSelectedExams] = useState<string[]>(exams ?? []);
5142
const [selectedSlots, setSelectedSlots] = useState<string[]>(slots ?? []);
@@ -129,7 +120,7 @@ const CatalogueContent = () => {
129120
};
130121

131122
void fetchPapers();
132-
}, [subject]); // just run on initial page render
123+
}, [subject]); // Just run on initial page render
133124

134125
// Memoized handlers
135126
const handleSelectPaper = useCallback(
@@ -201,7 +192,7 @@ const CatalogueContent = () => {
201192
answerkeyCondition
202193
);
203194
});
204-
setFilteredPapers(filtered );
195+
setFilteredPapers(filtered);
205196
},
206197
[subject, router, papers],
207198
);
@@ -222,7 +213,6 @@ const CatalogueContent = () => {
222213
setSelectedPapers([]);
223214
}, []);
224215

225-
226216
return (
227217
<div className="relative flex min-h-screen justify-center p-0 md:justify-normal">
228218
<div className="hidden w-[30%] min-w-fit md:block">

src/components/ChildrenWrapper.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
'use client';
1+
"use client";
22

3-
import { usePathname } from 'next/navigation';
4-
import React from 'react';
3+
import { usePathname } from "next/navigation";
4+
import React from "react";
55

66
function ChildrenWrapper({ children }: { children: React.ReactNode }) {
77
const pathname = usePathname();
88

9-
if (pathname.startsWith('/catalogue')) {
9+
if (pathname.startsWith("/catalogue")) {
1010
return <>{children}</>;
1111
}
1212

src/components/Error.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ import React from "react";
22

33
interface ErrorProps {
44
message?: string;
5-
filtersPulled ?: boolean;
5+
filtersPulled?: boolean;
66
}
77

8-
const Error = ({ message = "Some error occured", filtersPulled }: ErrorProps) => {
8+
const Error = ({
9+
message = "Some error occured",
10+
filtersPulled,
11+
}: ErrorProps) => {
912
return (
10-
<div className={`flex flex-1 items-center justify-center h-full ${filtersPulled ? "blur-xl" : ""}`}>
11-
<div className="-mt-32 text-center text-lg">
12-
{message}
13-
</div>
13+
<div
14+
className={`flex h-full flex-1 items-center justify-center ${filtersPulled ? "blur-xl" : ""}`}
15+
>
16+
<div className="-mt-32 text-center text-lg">{message}</div>
1417
</div>
1518
);
1619
};
1720

18-
export default Error;
21+
export default Error;

src/components/FilterDialog.tsx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,21 @@ export const FilterDialog = ({
3333
onReset: () => void;
3434
onApplyFilters: (exams: string[], slots: string[], years: string[]) => void;
3535
}) => {
36-
const [selectedExams, setSelectedExams] = useState<string[]>(initialExams ?? []);
37-
const [selectedSlots, setSelectedSlots] = useState<string[]>(initialSlots ?? []);
38-
const [selectedYears, setSelectedYears] = useState<string[]>(initialYears ?? []);
39-
const [selectedCampuses, setSelectedCampuses] = useState<string[]>(initialCampuses ?? []);
40-
const [selectedSemesters, setSelectedSemesters] = useState<string[]>(initialSemesters ?? []);
36+
const [selectedExams, setSelectedExams] = useState<string[]>(
37+
initialExams ?? [],
38+
);
39+
const [selectedSlots, setSelectedSlots] = useState<string[]>(
40+
initialSlots ?? [],
41+
);
42+
const [selectedYears, setSelectedYears] = useState<string[]>(
43+
initialYears ?? [],
44+
);
45+
const [selectedCampuses, setSelectedCampuses] = useState<string[]>(
46+
initialCampuses ?? [],
47+
);
48+
const [selectedSemesters, setSelectedSemesters] = useState<string[]>(
49+
initialSemesters ?? [],
50+
);
4151
const [open, setOpen] = useState(false);
4252

4353
useEffect(() => {
@@ -46,16 +56,24 @@ export const FilterDialog = ({
4656
setSelectedYears(initialYears ?? []);
4757
setSelectedCampuses(initialCampuses ?? []);
4858
setSelectedSemesters(initialSemesters ?? []);
49-
}, [initialExams, initialSlots, initialYears, initialCampuses, initialSemesters]);
59+
}, [
60+
initialExams,
61+
initialSlots,
62+
initialYears,
63+
initialCampuses,
64+
initialSemesters,
65+
]);
5066

5167
const exams = filterOptions.uniqueExams.map((exam) => ({
5268
label: exam,
5369
value: exam,
5470
}));
55-
const slots = filterOptions.uniqueSlots.sort((a, b) => a.localeCompare(b)).map((slot) => ({
56-
label: slot,
57-
value: slot,
58-
}));
71+
const slots = filterOptions.uniqueSlots
72+
.sort((a, b) => a.localeCompare(b))
73+
.map((slot) => ({
74+
label: slot,
75+
value: slot,
76+
}));
5977
const years = filterOptions.uniqueYears.map((year) => ({
6078
label: year,
6179
value: year,

src/components/Footer.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
"use client";
22

3-
import meta_icon from "../assets/meta_icon.svg";
4-
import x_twitter_icon from "../assets/x_twitter_icon.svg";
5-
import meta_icon_dark from "../assets/meta_icon_dark.svg";
6-
import x_twitter_icon_dark from "../assets/x_twitter_icon_dark.svg";
73
import Link from "next/link";
84
import { useTheme } from "next-themes";
95
import { useEffect, useState } from "react";

src/components/Navbar.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use client";
2+
23
import ccLogo from "../assets/codechef_logo.svg";
34
import Image from "next/image";
45
import ModeToggle from "@/components/toggle-theme";
@@ -12,7 +13,11 @@ function Navbar() {
1213
return (
1314
<div className="sticky top-0 z-10 flex h-[85px] w-full items-center justify-between gap-x-3 overflow-hidden bg-[#B2B8FF] px-2 py-6 dark:bg-[#130E1F] md:px-12">
1415
<div className="flex items-center gap-x-2 md:w-auto">
15-
<a href="https://www.codechefvit.com/" className="inline-block">
16+
<a
17+
href="https://www.codechefvit.com/"
18+
className="inline-block"
19+
title="CodeChef VIT Homepage"
20+
>
1621
<Image
1722
src={ccLogo as HTMLImageElement}
1823
alt="codechef-logo"
@@ -35,7 +40,7 @@ function Navbar() {
3540
<Link href={pathname == "/upload" ? "/" : "/upload"}>
3641
<div className="rounded-md bg-[#453D60] p-[1.5px] md:p-[2px]">
3742
<div className="flex items-center gap-1 rounded-md bg-slate-200 px-2 py-1 text-[9px] font-bold tracking-tight text-black transition-all duration-150 hover:bg-white active:scale-95 dark:bg-[#171720] dark:text-white dark:hover:bg-slate-700 sm:gap-2 sm:px-3 sm:py-2 sm:text-[10px] md:px-6 md:text-sm">
38-
<ArrowDownLeftIcon className="h-3 w-3 sm:h-4 sm:w-4 rotate-90" />
43+
<ArrowDownLeftIcon className="h-3 w-3 rotate-90 sm:h-4 sm:w-4" />
3944
<span className="text-center font-semibold">
4045
{pathname === "/upload" ? "SEARCH PAPERS" : "UPLOAD PAPERS"}
4146
</span>

src/components/RelatedPaper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use client";
2+
23
import Link from "next/link";
34
import { useEffect, useState } from "react";
45
import axios from "axios";

src/components/Searchbar/searchbar-child.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function SearchBarChild({
7777
<button
7878
type="submit"
7979
className="absolute inset-y-0 right-0 flex items-center pr-3"
80+
title="Search"
8081
>
8182
<Search className="h-5 w-5 text-black dark:text-white" />
8283
</button>

0 commit comments

Comments
 (0)