Skip to content

Commit

Permalink
added fn for sort team data by Firstname
Browse files Browse the repository at this point in the history
  • Loading branch information
Solankimimoh committed Sep 17, 2024
1 parent 60b35ce commit 42eb49f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/team/page.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import TitleWithSubtitle from '@/components/elements/TitleWithSubtitle';
import PillButton from '@/components/elements/PillButton';
import SpeakerCard from '@/components/elements/SpeakerCard';
import { team } from '@/data/data';
import TeamMemberCard from '@/components/elements/TeamMemberCard';
import { sortTeamByFirstName } from '@/lib/utils';

export default function Home() {

const sortedTeam = sortTeamByFirstName(team); // Use the imported function

return (
<div id="speakers" className="flex flex-col gap-6 text-center items-center justify-center my-24">
<TitleWithSubtitle
Expand All @@ -14,7 +16,7 @@ export default function Home() {
subTitleClassName="max-w-xl" />

<ul className=" py-6 grid grid-cols-2 sm:grid-cols-2 md:grid-cols-3 gap-6 max-w-7xl mx-auto">
{team.map(member => (
{sortedTeam.map(member => (
<li key={member.name} className="flex items-start">
<TeamMemberCard member={member} />
</li>
Expand Down
10 changes: 10 additions & 0 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export function clsx(...classes) {
return classes.filter(Boolean).join(' ');
}

export function sortTeamByFirstName(team) {
return team.sort((a, b) => {
const firstNameA = a.name.split(' ')[0].toLowerCase();
const firstNameB = b.name.split(' ')[0].toLowerCase();
if (firstNameA < firstNameB) return -1;
if (firstNameA > firstNameB) return 1;
return 0;
});
}

0 comments on commit 42eb49f

Please sign in to comment.