From 05106dbbade731be11744a00602da211c8fc6b2b Mon Sep 17 00:00:00 2001 From: MIGHTY1o1 Date: Wed, 23 Oct 2024 23:18:30 +0530 Subject: [PATCH] add searach bar to the project page --- src/app/(pages)/Projects/page.jsx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/app/(pages)/Projects/page.jsx b/src/app/(pages)/Projects/page.jsx index 91b37f9..9e50f8d 100644 --- a/src/app/(pages)/Projects/page.jsx +++ b/src/app/(pages)/Projects/page.jsx @@ -1,10 +1,19 @@ 'use client' -import React from 'react'; +import React, { useState } from 'react'; import Card from './Card.jsx'; import { projectData } from '../../../lib/Projects'; import { motion } from 'framer-motion'; function ProjectsPage() { + // State to handle the search query + const [searchQuery, setSearchQuery] = useState(''); + + // Function to filter projects based on the search query + const filteredProjects = projectData.filter((project) => + project.title.toLowerCase().includes(searchQuery.toLowerCase()) || + project.description.toLowerCase().includes(searchQuery.toLowerCase()) + ); + return (
@@ -28,9 +37,21 @@ function ProjectsPage() {
+ {/* Search Bar */} +
+ setSearchQuery(e.target.value)} + /> +
+ + {/* Projects List */}
- {projectData && projectData.length > 0 ? ( - projectData.map((project, index) => ( + {filteredProjects && filteredProjects.length > 0 ? ( + filteredProjects.map((project, index) => (