Skip to content

Commit

Permalink
`Refactor OurAlumni component to fetch alumni data from API and remov…
Browse files Browse the repository at this point in the history
…e Profile component`
  • Loading branch information
abhishekraoas committed Feb 7, 2025
1 parent d669433 commit b16a0bc
Show file tree
Hide file tree
Showing 15 changed files with 427 additions and 467 deletions.
1 change: 0 additions & 1 deletion client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default function App() {
useEffect(() => {
// Embed chatbot configuration
window.embeddedChatbotConfig = {
chatbotId: "",
chatbotId: "dQH5I7s2VhH8olxL6Cy3G",
domain: "www.chatbase.co",
};
Expand Down
127 changes: 50 additions & 77 deletions client/src/components/OurAlumni.jsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,38 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import UserCard from "./UserCards";
import Search from "./Search";

const OurAlumni = () => {
const users = [
{
name: "AbhiShek Rao",
email: "[email protected]",
avatar: "https://i.postimg.cc/q7HVzS6f/Abhi.jpg",
city: "Gorakhpur",
role: "Web Developer",
passOut: "MCA 2025",
skills: ["JavaScript", "React", "Node.js"],
bio: "Passionate web developer with a love for building interactive applications.",
worksAt: "TechSoft Pvt. Ltd.",
},
{
name: "Satish Pandey",
email: "[email protected]",
avatar: "https://i.postimg.cc/q7HVzS6f/Abhi.jpg",
city: "Lucknow",
role: "Data Scientist",
passOut: "MCA 2024",
skills: ["Python", "Machine Learning", "Data Analysis"],
bio: "Data scientist with a knack for uncovering insights from data.",
worksAt: "DataMinds Corp.",
},
{
name: "Suryam Shrivastav",
email: "[email protected]",
avatar: "https://i.postimg.cc/q7HVzS6f/Abhi.jpg",
city: "Delhi",
role: "UX Designer",
passOut: "MCA 2023",
skills: ["Figma", "Sketch", "User Research"],
bio: "Creative UX designer focused on enhancing user experiences.",
worksAt: "DesignHub",
},
{
name: "Suryam Shrivastav",
email: "[email protected]",
avatar: "https://i.postimg.cc/q7HVzS6f/Abhi.jpg",
city: "Delhi",
role: "UX Designer",
passOut: "MCA 2023",
skills: ["Figma", "Sketch", "User Research"],
bio: "Creative UX designer focused on enhancing user experiences.",
worksAt: "DesignHub",
},
{
name: "Suryam Shrivastav",
email: "[email protected]",
avatar: "https://i.postimg.cc/q7HVzS6f/Abhi.jpg",
city: "Delhi",
role: "UX Designer",
passOut: "MCA 2023",
skills: ["Figma", "Sketch", "User Research"],
bio: "Creative UX designer focused on enhancing user experiences.",
worksAt: "DesignHub",
},
];

export const OurAlumni = () => {
const [alumni, setAlumni] = useState([]);
const [filteredUsers, setFilteredUsers] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

const API = "http://localhost:3000/api/alumni";

const fetchAlumni = async () => {
try {
const res = await fetch(API);
const data = await res.json();
// console.log(data); // Debug API response
setAlumni(data || []); // Adjust based on API structure
setFilteredUsers(data || []);
setLoading(false);
} catch (error) {
console.error("Error fetching alumni data:", error);
setLoading(false);
setError(error.message);
}
};

const [filteredUsers, setFilteredUsers] = useState(users);
useEffect(() => {
fetchAlumni();
}, []);


const handleSearch = (query, filter) => {
const lowerCaseQuery = query.toLowerCase();
const filtered = users.filter((user) => {
const filtered = alumni.filter((user) => {
if (filter === "name") {
return user.name.toLowerCase().includes(lowerCaseQuery);
} else if (filter === "city") {
Expand All @@ -82,24 +48,31 @@ const OurAlumni = () => {
});
setFilteredUsers(filtered);
};


if (loading) {
return <p className="text-center">Loading alumni data...</p>;
}

if (error) {
return <p className="text-center text-red-500">Error: {error}</p>;
}

return (
<div className="container mx-auto px-4 pt-4">
<h1 className="text-3xl font-bold text-center mb-4">Our Alumni</h1>
<Search onSearch={handleSearch} />
<div className="flex flex-wrap -mx-4">
{filteredUsers.length > 0 ? (
filteredUsers.map((user, index) => (
<div className="w-full md:w-1/2 xl:w-1/3 px-4 mb-8" key={index}>
<UserCard user={user} />
</div>
))
) : (
<p className="text-center w-full">No alumni found.</p>
)}
</div>
<div className="container mx-auto px-4 pt-4">
<h1 className="text-3xl font-bold text-center mb-4">Our Alumni</h1>
<Search onSearch={handleSearch} />
<div className="flex flex-wrap -mx-4">
{filteredUsers.length > 0 ? (
filteredUsers.map((user, index) => (
<div className="w-full md:w-1/2 xl:w-1/3 px-4 mb-8" key={index}>
<UserCard user={user} />
</div>
))
) : (
<p className="text-center w-full">No alumni found.</p>
)}
</div>
</div>
);
};

Expand Down
163 changes: 0 additions & 163 deletions client/src/components/Profile.jsx

This file was deleted.

Loading

0 comments on commit b16a0bc

Please sign in to comment.