Skip to content

Commit

Permalink
fix: remove manual memo
Browse files Browse the repository at this point in the history
  • Loading branch information
mwskwong committed Jun 18, 2024
1 parent 6b02b99 commit 2eed665
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
26 changes: 12 additions & 14 deletions src/components/home/self-learning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Typography,
} from '@mui/joy';
import { Search, X } from 'lucide-react';
import { type FC, useDeferredValue, useMemo, useState } from 'react';
import { type FC, useDeferredValue, useState } from 'react';

import { Image } from '../image';

Expand All @@ -41,19 +41,17 @@ export const SelfLearning: FC<SelfLearningProps> = ({
}) => {
const [search, setSearch] = useState('');
const deferredSearch = useDeferredValue(search);
const filteredCourses = useMemo(
() =>
courses.filter(({ name, institution, categories }) => {
const searchStr = deferredSearch.toLowerCase();
return (
Boolean(name?.toLowerCase().includes(searchStr)) ||
Boolean(institution?.name?.toLowerCase().includes(searchStr)) ||
categories?.some((category) =>
category.toLowerCase().includes(searchStr),
)
);
}),
[courses, deferredSearch],
const filteredCourses = courses.filter(
({ name, institution, categories }) => {
const searchStr = deferredSearch.toLowerCase();
return (
Boolean(name?.toLowerCase().includes(searchStr)) ||
Boolean(institution?.name?.toLowerCase().includes(searchStr)) ||
categories?.some((category) =>
category.toLowerCase().includes(searchStr),
)
);
},
);

return (
Expand Down
26 changes: 11 additions & 15 deletions src/components/home/skill-set.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type StackProps,
Typography,
} from '@mui/joy';
import { type FC, useDeferredValue, useMemo, useState } from 'react';
import { type FC, useDeferredValue, useState } from 'react';

import { Icon } from '../contentful';

Expand All @@ -26,20 +26,16 @@ export interface SkillSetProps extends Omit<StackProps, 'children'> {
export const SkillSet: FC<SkillSetProps> = ({ skillSet = [], ...props }) => {
const [proficiency, setProficiency] = useState<[number, number]>([1, 5]);
const deferredProficiency = useDeferredValue(proficiency);
const filteredSkillSet = useMemo(
() =>
skillSet
.map(({ skills, ...category }) => ({
...category,
skills: skills.filter(
({ proficiency = 0 }) =>
proficiency >= deferredProficiency[0] &&
proficiency <= deferredProficiency[1],
),
}))
.filter(({ skills }) => skills.length > 0),
[deferredProficiency, skillSet],
);
const filteredSkillSet = skillSet
.map(({ skills, ...category }) => ({
...category,
skills: skills.filter(
({ proficiency = 0 }) =>
proficiency >= deferredProficiency[0] &&
proficiency <= deferredProficiency[1],
),
}))
.filter(({ skills }) => skills.length > 0);

return (
<Stack spacing={2} {...props}>
Expand Down

0 comments on commit 2eed665

Please sign in to comment.