From 99091016606a9e6c681c223fe5ccbd47c962face Mon Sep 17 00:00:00 2001 From: Gubar Nikita Date: Fri, 26 Jul 2024 15:22:53 +0300 Subject: [PATCH] fix Summary skills --- src/pages/Summary/Summary.jsx | 36 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/pages/Summary/Summary.jsx b/src/pages/Summary/Summary.jsx index 6640df00..20b1cfd4 100644 --- a/src/pages/Summary/Summary.jsx +++ b/src/pages/Summary/Summary.jsx @@ -58,6 +58,25 @@ export const Summary = () => { }); }, []); + const addSkill = (skill) => { + const isSkillFound = selectedSkills.some( + (item) => item.skill_id == skill.id + ); + + if (!isSkillFound) { + setSelectedSkills((prevValue) => [ + ...prevValue, + { skill: skill, skill_id: skill.id } + ]); + } + }; + + const deleteSkill = (skill) => { + setSelectedSkills((prevValue) => + prevValue.filter((item) => item.skill_id !== skill.skill_id) + ); + }; + function setSkills() { apiRequest("/resume/edit-skills", { method: "PUT", @@ -157,13 +176,7 @@ export const Summary = () => { deleteIcon - setSelectedSkills((prevValue) => - prevValue.filter( - (item) => item.skill_id !== skill.skill_id - ) - ) - } + onClick={() => deleteSkill(skill)} /> ); @@ -184,12 +197,7 @@ export const Summary = () => { {skillsList.map((skill) => { return (

- setSelectedSkills((prevValue) => [ - ...prevValue, - { skill: skill, skill_id: skill.id } - ]) - } + onClick={() => addSkill(skill)} key={skill.id} className="select-skills__item" > @@ -205,7 +213,7 @@ export const Summary = () => {

{selectedSkills && selectedSkills.map((skill, index) => ( - + {skill.skill.name} {selectedSkills.length > index + 1 && ","}