From 82259104222e8f0f1e09016035f5236cf3964c73 Mon Sep 17 00:00:00 2001 From: Artem Trofymovych Date: Sun, 26 Nov 2023 15:17:00 +0100 Subject: [PATCH] develop --- src/components/PersonLink.tsx | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/components/PersonLink.tsx b/src/components/PersonLink.tsx index db75291f6..039b345df 100644 --- a/src/components/PersonLink.tsx +++ b/src/components/PersonLink.tsx @@ -8,26 +8,14 @@ type Props = { person: Person }; -function findPersonFather(newPeople: Person[], selectedPerson: Person) { - const father = newPeople.find(p => p.name === selectedPerson.fatherName); - - return father?.slug; -} - -function findPersonMother(newPeople: Person[], selectedPerson: Person) { - const mother = newPeople.find(p => p.name === selectedPerson.motherName); - - return mother?.slug; -} - export const PersonLink: React.FC = ({ person }) => { const { personSlug } = useParams(); const { people, } = useContext(PeopleContext); - const motherSlug = findPersonMother(people, person); - const fatherSlug = findPersonFather(people, person); + const motherSlug = people.find(p => p.name === person.motherName)?.slug; + const fatherSlug = people.find(p => p.name === person.fatherName)?.slug; return ( = ({ person }) => { {person.sex} {person.born} {person.died} - {findPersonMother(people, person) + {motherSlug ? ( = ({ person }) => { ) : {person.motherName ? person.motherName : '-'}} - {findPersonFather(people, person) + {fatherSlug ? (