Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user search category then display that category #228

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 51 additions & 28 deletions client/src/components/Home/SectionSecond.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState, useEffect } from "react";

const SectionSecond = () => {
// Sample data for categories
Expand Down Expand Up @@ -61,39 +61,62 @@ const SectionSecond = () => {
},
];

const [searchInput, setSearchInput] = useState("");
const [searchResults, setSearchResults] = useState(categories);

useEffect(() => {
const trimmedInput = searchInput.trim().toLowerCase();
const results = categories.filter(
(category) => category.title.toLowerCase().includes(trimmedInput)
);
setSearchResults(results);
}, [searchInput]);

return (

<div className=" container mx-auto py-8">
<h3 className="text-center font-bold text-3xl mb-6">
Search by Category
</h3>
<p className="text-center underline font-semibold text-sm mb-8 text-gray-700"> Search your career opportunity with our categories</p>
<div className="container mx-auto py-8">
<h3 className="text-center font-bold text-3xl mb-6">Search by Category</h3>
<p className="text-center underline font-semibold text-sm mb-8 text-gray-700">
Search your career opportunity with our categories
</p>

<div className="grid sm:grid-cols-2 lg:grid-cols-4 gap-6">
{categories.map((category) => (
<div
key={category.id}
className="card bg-white border border-gray-300 rounded-lg shadow-lg overflow-hidden w-[320px] h-[370px] mx-auto transition-transform duration-300 hover:scale-105"
>
<img
src={category.imageUrl}
alt={category.title}
className="w-full h-[250px] object-cover"
/>
<div className="p-4 text-center">
<h2 className="text-xl font-semibold mb-2 ">{category.title}</h2>
<div className="flex justify-between items-center">
<p className="text-gray-700">{category.positions}</p>
<button className="bg-blue-500 text-white px-4 py-1 rounded-lg transition-transform duration-300 hover:bg-blue-600">View</button>
<div className="text-center mb-6">
<input
type="text"
value={searchInput}
onChange={(e) => setSearchInput(e.target.value)}
className="border border-gray-300 rounded-lg px-4 py-2 mr-2"
placeholder="Enter category name"
/>
</div>

<div className="grid sm:grid-cols-2 lg:grid-cols-4 gap-6">
{searchResults.length > 0 ? (
searchResults.map((category) => (
<div
key={category.id}
className="card bg-white border border-gray-300 rounded-lg shadow-lg overflow-hidden w-[320px] h-[370px] mx-auto transition-transform duration-300 hover:scale-105"
>
<img
src={category.imageUrl}
alt={category.title}
className="w-full h-[250px] object-cover"
/>
<div className="p-4 text-center">
<h2 className="text-xl font-semibold mb-2">{category.title}</h2>
<div className="flex justify-between items-center">
<p className="text-gray-700">{category.positions}</p>
<button className="bg-blue-500 text-white px-4 py-1 rounded-lg transition-transform duration-300 hover:bg-blue-600">
View
</button>
</div>
</div>
</div>
</div>

))}
))
) : (
<p className="text-center text-red-500">Item not found</p>
)}
</div>
</div>


);
};

Expand Down
Loading