generated from Filgeary/template_CRA-React18-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Filgeary:feat/add-single-character-page
feat: add single character page
- Loading branch information
Showing
24 changed files
with
364 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react' | ||
import { IMAGE_VARIANT } from '../../constants' | ||
import { transformCharacter } from '../../utils/apiAdapter' | ||
import styles from './CharacterProfile.module.css' | ||
|
||
/** | ||
* @param {object} props | ||
* @param {import('../../types/ICharacter').ICharacter | null | undefined} props.character | ||
*/ | ||
const CharacterProfile = ({ character }) => { | ||
if (!character) return <h2>No Character!</h2> | ||
|
||
const { name, thumbnail, description } = | ||
transformCharacter(character, IMAGE_VARIANT['300x450']) ?? {} | ||
|
||
return ( | ||
<article | ||
data-testid='characterProfile' | ||
className='p-3 d-grid align-items-start gap-5' | ||
> | ||
<div className={styles.wrapper}> | ||
<figure> | ||
<img | ||
src={thumbnail} | ||
alt={name} | ||
width={300} | ||
height={450} | ||
/> | ||
</figure> | ||
|
||
<section className='d-flex flex-column gap-4 h-100 p-0 px-2 font-light'> | ||
<h2 className='text-gradient f-size-250'>{name}</h2> | ||
<p>{description}</p> | ||
</section> | ||
</div> | ||
|
||
<hr | ||
style={{ width: '60%', background: 'var(--cra-bg-grey)', border: 'none', height: '2px' }} | ||
/> | ||
</article> | ||
) | ||
} | ||
|
||
export default CharacterProfile |
21 changes: 21 additions & 0 deletions
21
src/components/CharacterProfile/CharacterProfile.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.wrapper { | ||
display: grid; | ||
align-items: start; | ||
grid-template-columns: 1fr 2fr; | ||
} | ||
|
||
@media (max-width: 1199px) { | ||
/* desktop (<= 1199) */ | ||
} | ||
|
||
@media (max-width: 1023px) { | ||
/* tablet (<= 1023) */ | ||
} | ||
|
||
@media (max-width: 767px) { | ||
/* mobile -> tablet (<= 767) */ | ||
} | ||
|
||
@media (max-width: 425px) { | ||
/* only mobile (<= 425) */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import React from 'react' | ||
import characterResponseJson from '../../__fixtures/api/characterById.json' | ||
import CharacterProfile from './CharacterProfile' | ||
|
||
/** | ||
* @type {import('../../types/ICharacter').ICharacterDataWrapper} | ||
*/ | ||
const characterResponseObj = JSON.parse(JSON.stringify(characterResponseJson)) | ||
const character = characterResponseObj?.data?.results?.at(0) | ||
|
||
describe('CharacterProfile', () => { | ||
it('should render properly', () => { | ||
render(<CharacterProfile character={character} />) | ||
|
||
expect(screen.getByTestId('characterProfile')).toBeInTheDocument() | ||
expect(screen.getByRole('heading', { name: /guardians of the galaxy/i })).toBeInTheDocument() | ||
expect(screen.getByRole('img', { name: /guardians of the galaxy/i })).toBeInTheDocument() | ||
|
||
// full description | ||
expect( | ||
screen.getByText( | ||
/a group of cosmic adventurers brought together by star-lord, the guardians of the galaxy protect the universe from threats all across space\. the team also includes drax, gamora, groot and rocket raccoon!/i, | ||
), | ||
).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import CharacterProfile from './CharacterProfile' | ||
export default CharacterProfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/containers/CharacterProfileContainer/CharacterProfileContainer.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import CharacterProfile from '../../components/CharacterProfile' | ||
import ErrorMessage from '../../components/_shared/ErrorMessage' | ||
import Spinner from '../../components/_shared/Spinner' | ||
import { useFetchCharacterById } from '../../hooks/useFetchCharacterById' | ||
|
||
// import styles from './CharacterProfileContainer.module.css' | ||
|
||
/** | ||
* @param {object} props | ||
* @param {string} props.id | ||
*/ | ||
const CharacterProfileContainer = ({ id }) => { | ||
const { responseData, isLoading, isError, errorMsg } = useFetchCharacterById(id) | ||
|
||
// @ts-ignore | ||
const character = responseData?.data?.results?.at(0) // TODO: add types | ||
|
||
return ( | ||
<div style={{ minHeight: 250 }}> | ||
{isLoading && <Spinner />} | ||
{isError && <ErrorMessage text={errorMsg} />} | ||
{!isError && !isLoading && <CharacterProfile character={character} />} | ||
</div> | ||
) | ||
} | ||
|
||
export default CharacterProfileContainer |
17 changes: 17 additions & 0 deletions
17
src/containers/CharacterProfileContainer/CharacterProfileContainer.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* styles */ | ||
|
||
@media (max-width: 1199px) { | ||
/* desktop (<= 1199) */ | ||
} | ||
|
||
@media (max-width: 1023px) { | ||
/* tablet (<= 1023) */ | ||
} | ||
|
||
@media (max-width: 767px) { | ||
/* mobile -> tablet (<= 767) */ | ||
} | ||
|
||
@media (max-width: 425px) { | ||
/* only mobile (<= 425) */ | ||
} |
Oops, something went wrong.