Skip to content

Commit

Permalink
feat: using useMemo for company list
Browse files Browse the repository at this point in the history
  • Loading branch information
Jirapat Treesuwan committed Nov 12, 2024
1 parent 2f0037a commit d76a85f
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/modules/home/_components/search-company.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useState } from 'react';
import { useMemo, useState } from 'react';
import type { Company } from '../_types';
import { GradientCard } from '@/shared/components';
import { Input } from '@/shared/components/ui/input';
Expand All @@ -14,8 +14,24 @@ type Props = {
};

export function SearchCompany({ companies }: Props) {
'use client';
const [searchValue, setSearchValue] = useState<string>('');
const companyList = useMemo(() => {
return companies
.filter((company: Company) =>
company.name.toLowerCase().includes(searchValue),
)
.map((company: Company, index: number) => {
return (
<TabsTrigger
value={dayMapper.get(company.date) ?? DayValueTrigger.FIRST_DAY}
className="text-filling-animation flex w-full flex-shrink-0 cursor-pointer py-2"
key={`${company.name}-${index}`}
>
{company.name}
</TabsTrigger>
);
});
}, [searchValue, companies]);

return (
<>
Expand All @@ -33,25 +49,7 @@ export function SearchCompany({ companies }: Props) {
</GradientCard>

<ScrollArea className="h-[65svh] pr-5 text-sm sm:text-base lg:h-[300px]">
<TabsList>
{companies
.filter((company: Company) =>
company.name.toLowerCase().includes(searchValue),
)
.map((company: Company, index: number) => {
return (
<TabsTrigger
value={
dayMapper.get(company.date) ?? DayValueTrigger.FIRST_DAY
}
className="text-filling-animation flex w-full flex-shrink-0 cursor-pointer py-2"
key={`${company.name}-${index}`}
>
{company.name}
</TabsTrigger>
);
})}
</TabsList>
<TabsList>{companyList}</TabsList>
</ScrollArea>
</>
);
Expand Down

0 comments on commit d76a85f

Please sign in to comment.