From 32e0e99c681303fae5f1afe613c2cd5ad9e7478f Mon Sep 17 00:00:00 2001 From: Jashanpreetkaur Date: Fri, 19 Jun 2026 13:35:27 +0530 Subject: [PATCH] feat:add subject search functionality --- app/components/subjects.tsx | 28 +++++++++++++++++++++++++++- refactor_reading_time.js | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/components/subjects.tsx b/app/components/subjects.tsx index 588c63a..d1df90a 100644 --- a/app/components/subjects.tsx +++ b/app/components/subjects.tsx @@ -1,5 +1,6 @@ "use client"; import Link from "next/link"; +import { useState } from "react"; const subjects = { "Semester-1": [ @@ -132,6 +133,7 @@ const subjectCodes: Record = { const available = ["ep", "c", "em1", "em2", "oops", "dsc", "coa", "os", "ml", "dops", "cd", "cle", "ec", "dbms", "bme", "cns", "vlsi", "mb"]; export default function SubjectsSection() { + const [searchTerm, setSearchTerm] = useState(""); return (

Explore Subjects divided Semester-wise for your convenience.

+
+ setSearchTerm(e.target.value)} + className="w-full max-w-xl p-3 border-2 border-[#d2b48c] rounded-lg text-black text-lg" + /> +
{Object.entries(subjects).map(([semester, list]) => { + const filteredList = list.filter((subj) => + subj.toLowerCase().includes(searchTerm.toLowerCase()) + ); + + if (filteredList.length === 0) return null; const semCode = semester.toLowerCase().replace("semester-", "sem"); return (

{semester}

- {list.map((subj) => { + {filteredList.map((subj) => { const code = subjectCodes[subj]; const href = `/${semCode}/${code}/ch0`; const isAvailable = available.includes(code); @@ -190,6 +206,16 @@ export default function SubjectsSection() { })}
+{Object.values(subjects) + .flat() + .filter((subj) => + subj.toLowerCase().includes(searchTerm.toLowerCase()) + ).length === 0 && + searchTerm && ( +

+ No subjects found. +

+)}

); } diff --git a/refactor_reading_time.js b/refactor_reading_time.js index 8a835ff..ffb2091 100644 --- a/refactor_reading_time.js +++ b/refactor_reading_time.js @@ -43,4 +43,5 @@ pageFiles.forEach(file => { console.log('Updated:', file); } } + });