Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
suvanbanerjee authored Aug 16, 2024
2 parents 159917c + eaaf3f9 commit a2f360a
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 95 deletions.
Binary file removed app/favicon.ico
Binary file not shown.
70 changes: 41 additions & 29 deletions components/Members.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Card from '@/components/ui/Card';
import CollapsibleSection from '@/components/ui/CollapsibleSection';
import { db } from "@/Firebase";
import { collection, query, where, getDocs } from "firebase/firestore";
import ClipLoader from "react-spinners/ClipLoader";

interface Member {
id: string;
Expand All @@ -17,16 +18,17 @@ interface Member {
const headings = ["Alumni", "Fourth Year", "Third Year", "Second Year", "First Year"];

export default function Members() {
// Set default open index to the index of "Alumni"
const [openIndex, setOpenIndex] = useState<number>(headings.indexOf("Alumni"));
const [data, setData] = useState<{ [key: string]: Member[] }>({});
const [loading, setLoading] = useState<boolean>(true);

const handleToggle = (index: number) => {
setOpenIndex(openIndex === index ? -1 : index);
};

useEffect(() => {
const fetchData = async () => {
setLoading(true);
try {
const fetchedData: { [key: string]: Member[] } = {};

Expand All @@ -35,13 +37,11 @@ export default function Members() {
const q = query(membersCollection, where("year", "==", heading));
const querySnapshot = await getDocs(q);

// Collect all documents
const allMembers = querySnapshot.docs.map(doc => ({
id: doc.id,
...(doc.data() as Omit<Member, 'id'>)
})) as Member[];

// Remove duplicates based on name, domain, and year
const uniqueMembers = Array.from(
new Map(
allMembers.map(member => [
Expand All @@ -51,7 +51,6 @@ export default function Members() {
).values()
);

// Sort members alphabetically by name
const sortedMembers = uniqueMembers.sort((a, b) => a.name.localeCompare(b.name));

fetchedData[heading] = sortedMembers;
Expand All @@ -60,39 +59,52 @@ export default function Members() {
setData(fetchedData);
} catch (error) {
console.error("Error fetching data: ", error);
} finally {
setLoading(false);
}
};
fetchData();
}, []);

return (
<div className="flex flex-col justify-center items-center w-full space-y-4 mt-20 pb-8 bg-black">
<h1 className="text-center font-bold text-4xl text-white"></h1>
<div className="flex flex-col justify-center items-center w-full space-y-4 mt-24 bg-black">
<h1 className="text-center font-bold text-4xl text-white">PB Members</h1>
<div className="w-full max-w-6xl px-2 ">
<div className="space-y-2">
{headings.map((heading, index) => (
<CollapsibleSection
key={index}
heading={heading}
content={
<div className='flex justify-center'>
<div className="grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-16">
{data[heading]?.map((profile, cardIndex) => (
<Card
key={cardIndex}
name={profile.name}
domain={profile.domain}
company={profile.company || ""}
/>
))}
{loading ? (
<div className="flex justify-center py-10">
<ClipLoader color={"#00C853"} loading={loading} size={50} />
</div>
) : (
<div className="space-y-2">
{headings.map((heading, index) => (
<CollapsibleSection
key={index}
heading={heading}
content={
<div className='flex justify-center'>
{heading === "First Year" && (
<p className="text-white lg:text-2xl text-xl mb-4">
Recruitment incoming soon
</p>
)}
<div className="grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-16">
{data[heading]?.map((profile, cardIndex) => (
<Card
key={cardIndex}
name={profile.name}
domain={profile.domain}
company={profile.company || ""}
/>
))}
</div>
</div>
</div>
}
isOpen={openIndex === index}
onToggle={() => handleToggle(index)}
/>
))}
</div>
}
isOpen={openIndex === index}
onToggle={() => handleToggle(index)}
/>
))}
</div>
)}
</div>
</div>
);
Expand Down
16 changes: 13 additions & 3 deletions components/forms/formContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ interface ITeamInfo {
name: string;
email: string;
phone: string;
role: string;
enrollment_id: string;
course: string;
year_of_study: string;
branch: string;
};
}

Expand Down Expand Up @@ -58,15 +63,20 @@ export const FormProvider: React.FC<{ children: React.ReactNode }> = ({
const [formData, setFormData] = useState<IFormData>({
team_info: {
team_name: "",
college_name: "",
team_size: 6,
college_name: "DSCE",
team_size: 5,
team_leader: {
name: "",
email: "",
phone: "",
enrollment_id: "",
role: "",
course: "",
year_of_study: "",
branch: "",
},
},
team_members: Array.from({ length: 6 }, () => ({
team_members: Array.from({ length: 5 }, () => ({
name: "",
email: "",
phone: "",
Expand Down
Loading

0 comments on commit a2f360a

Please sign in to comment.