From 9ef1d62e31b9ea96d2cd2811394e1a0a49858eb7 Mon Sep 17 00:00:00 2001 From: Vladyslav Prokhasko Date: Tue, 22 Aug 2023 17:15:07 +0300 Subject: [PATCH 1/4] solution --- README.md | 2 +- src/App.jsx | 21 +++++------------- src/components/Person/Person.jsx | 37 +++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3424ccb86..d049794f3 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,4 @@ and use it 3 times inside the `App` instead of static markup. ## Instructions - Implement a solution following the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline). - Open one more terminal and run tests with `npm test` to ensure your solution is correct. -- Replace `` with your Github username in the [DEMO LINK](https://.github.io/react_person/) and add it to the PR description. +- Replace `` with your Github username in the [DEMO LINK](https://00Mass00.github.io/react_person/) and add it to the PR description. diff --git a/src/App.jsx b/src/App.jsx index dcf8509c8..b3da25285 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,6 +1,8 @@ import React from 'react'; import './App.scss'; +import { Person } from './components/Person/Person'; + export const misha = { name: 'Misha', age: 37, @@ -25,21 +27,8 @@ export const alex = { export const App = () => (
-
-

My name is Misha

-

I am 37

-

Natasha is my wife

-
- -
-

My name is Olya

-

Maksym is my husband

-
- -
-

My name is Alex

-

I am 25

-

I am not married

-
+ + +
); diff --git a/src/components/Person/Person.jsx b/src/components/Person/Person.jsx index eccf156a3..1372e23a1 100644 --- a/src/components/Person/Person.jsx +++ b/src/components/Person/Person.jsx @@ -1 +1,36 @@ -// export const Person = ({ person }) => (); +export const Person = ({ person }) => { + const { + name, + age, + sex, + isMarried, + partnerName, + } = person; + + const getPartner = () => { + if (isMarried) { + return sex === 'm' + ? 'wife' + : 'husband'; + } + + return 'I am not married'; + }; + + return ( +
+

+ {`My name is ${name}`} +

+ + {age &&

{`I am ${age}`}

} + +

+ {partnerName + ? `${partnerName} is my ${getPartner()}` + : getPartner() + } +

+
+ ); +}; From f3497388344c27e564b10442187530cacc86f2d6 Mon Sep 17 00:00:00 2001 From: Vladyslav Prokhasko Date: Tue, 22 Aug 2023 22:28:27 +0300 Subject: [PATCH 2/4] fix solution --- src/components/Person/Person.jsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/Person/Person.jsx b/src/components/Person/Person.jsx index 1372e23a1..20f905a68 100644 --- a/src/components/Person/Person.jsx +++ b/src/components/Person/Person.jsx @@ -1,3 +1,7 @@ +const MALE = 'm'; +const WIFE = 'wife'; +const HUSBAND = 'husband'; + export const Person = ({ person }) => { const { name, @@ -9,9 +13,9 @@ export const Person = ({ person }) => { const getPartner = () => { if (isMarried) { - return sex === 'm' - ? 'wife' - : 'husband'; + return sex === MALE + ? WIFE + : HUSBAND; } return 'I am not married'; @@ -23,12 +27,14 @@ export const Person = ({ person }) => { {`My name is ${name}`} - {age &&

{`I am ${age}`}

} + {age && ( +

{`I am ${age}`}

+ )}

{partnerName ? `${partnerName} is my ${getPartner()}` - : getPartner() + : 'I am not married' }

From 475d02a5cd4720e4ec6e3e5a078d2f8e822198fa Mon Sep 17 00:00:00 2001 From: Vladyslav Prokhasko Date: Tue, 22 Aug 2023 22:46:46 +0300 Subject: [PATCH 3/4] fix solution --- src/components/Person/Person.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Person/Person.jsx b/src/components/Person/Person.jsx index 20f905a68..c03156b18 100644 --- a/src/components/Person/Person.jsx +++ b/src/components/Person/Person.jsx @@ -1,6 +1,7 @@ const MALE = 'm'; const WIFE = 'wife'; const HUSBAND = 'husband'; +const NOT_MARRIED_PERSON = 'I am not married'; export const Person = ({ person }) => { const { @@ -18,7 +19,7 @@ export const Person = ({ person }) => { : HUSBAND; } - return 'I am not married'; + return NOT_MARRIED_PERSON; }; return ( @@ -34,7 +35,7 @@ export const Person = ({ person }) => {

{partnerName ? `${partnerName} is my ${getPartner()}` - : 'I am not married' + : NOT_MARRIED_PERSON }

From f37bf2eb46e2542c3371df192b5fcaa9ac388796 Mon Sep 17 00:00:00 2001 From: Vladyslav Prokhasko Date: Wed, 23 Aug 2023 13:00:44 +0300 Subject: [PATCH 4/4] optimized version --- src/components/Person/Person.jsx | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/components/Person/Person.jsx b/src/components/Person/Person.jsx index c03156b18..856a830c5 100644 --- a/src/components/Person/Person.jsx +++ b/src/components/Person/Person.jsx @@ -1,7 +1,17 @@ const MALE = 'm'; const WIFE = 'wife'; const HUSBAND = 'husband'; -const NOT_MARRIED_PERSON = 'I am not married'; +const NOT_MARRIED_PERSON_MESSAGE = 'I am not married'; + +const getPartner = (isMarried, sex) => { + if (isMarried) { + return sex === MALE + ? WIFE + : HUSBAND; + } + + return NOT_MARRIED_PERSON_MESSAGE; +}; export const Person = ({ person }) => { const { @@ -12,31 +22,20 @@ export const Person = ({ person }) => { partnerName, } = person; - const getPartner = () => { - if (isMarried) { - return sex === MALE - ? WIFE - : HUSBAND; - } - - return NOT_MARRIED_PERSON; - }; + const partnerInfo = partnerName + ? `${partnerName} is my ${getPartner(isMarried, sex)}` + : NOT_MARRIED_PERSON_MESSAGE; return (

{`My name is ${name}`}

- {age && (

{`I am ${age}`}

)} -

- {partnerName - ? `${partnerName} is my ${getPartner()}` - : NOT_MARRIED_PERSON - } + {partnerInfo}

);