Skip to content

Commit

Permalink
Feat: main 필터 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
alreadynyeong committed Mar 22, 2024
1 parent 33b8b89 commit e778574
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions pages/projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ const Projects = () => {
const [selectedSkills, setSelectedSkills] = useState<string[]>([]);

const toggleSkill = (skill: string) => {
if (selectedSkills.includes(skill)) {
setSelectedSkills(selectedSkills.filter((s) => s !== skill));
if (skill === "Main") {
setSelectedSkills((prevSkills) =>
prevSkills.includes(skill) ? [] : [skill]
);
} else {
setSelectedSkills([...selectedSkills, skill]);
setSelectedSkills((prevSkills) =>
prevSkills.includes("Main")
? [skill]
: prevSkills.includes(skill)
? prevSkills.filter((prevSkill) => prevSkill !== skill)
: [...prevSkills, skill]
);
}
};

Expand Down Expand Up @@ -52,6 +60,12 @@ const Projects = () => {
<div>
<Skills>
FILTER
<Skill
onClick={() => toggleSkill("Main")}
active={selectedSkills.includes("Main")}
>
MAIN
</Skill>
<Skill
onClick={() => toggleSkill("React")}
active={selectedSkills.includes("React")}
Expand Down Expand Up @@ -81,11 +95,16 @@ const Projects = () => {
<ScrollContainer style={{ height: dynamicHeight }}>
{ProjectList.slice()
.reverse()
.filter(
(project) =>
selectedSkills.length === 0 ||
selectedSkills.some((skill) => project.skills.includes(skill))
)
.filter((project) => {
if (selectedSkills.includes("Main")) {
return project.main;
} else {
return (
selectedSkills.length === 0 ||
selectedSkills.some((skill) => project.skills.includes(skill))
);
}
})
.map((project) => (
<ProjectContainer key={project.id}>
<a href={`/Portfolio/project?id=${project.id}`}>
Expand Down

0 comments on commit e778574

Please sign in to comment.