Skip to content

Commit

Permalink
WJ-21 - New: showModal entityImage action;
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Teixeira committed Nov 14, 2020
1 parent b9c104f commit 814de74
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/containers/EntityImage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const EntityImage: React.FC<Props> = ({
hideSubtitle,
showEmpty,
isLoading,
showModal,
...entity
}) => {
const history = useHistory();
Expand Down Expand Up @@ -62,6 +63,26 @@ const EntityImage: React.FC<Props> = ({
}
}, [disabled, history, entity.id, entity.mediaType, successCloseModal]);

const handleShowModal = useCallback(() => {
setModalContent({
value: (
<MediaContainer>
<Media src={entity.featuredImage || ''} height={25.3} width={16.5} />
</MediaContainer>
),
props: { hideCloseButton: true, center: true },
});
}, [entity.featuredImage, setModalContent]);

const handleClick = useCallback(() => {
if (showModal) {
handleShowModal();
return;
}

handleRedirect();
}, [showModal, handleShowModal, handleRedirect]);

// Check if entity is in favorite list and change status
useEffect(() => {
if (user) {
Expand Down Expand Up @@ -101,7 +122,7 @@ const EntityImage: React.FC<Props> = ({
size={size}
showInfo={showInfo}
disabled={disabled}
onClick={handleRedirect}
onClick={handleClick}
>
<FeaturedImage
src={entity.featuredImage || entity.backdrop}
Expand Down
1 change: 1 addition & 0 deletions src/containers/EntityImage/types/ContainerProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export default interface ContainerProps extends DefaultProps {
hideSubtitle?: boolean;
disabled?: boolean;
showEmpty?: boolean;
showModal?: boolean;
}
2 changes: 2 additions & 0 deletions src/containers/EntityImageList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const EntityImageList: React.FC<Props> = ({
disabled,
showInfo,
hideSubtitle,
showModal,
}) => {
const itemsContainer = createRef<HTMLDivElement>();
const [showPreviousButton, setShowPreviousButton] = useState(false);
Expand Down Expand Up @@ -112,6 +113,7 @@ const EntityImageList: React.FC<Props> = ({
disabled={disabled}
showInfo={showInfo}
hideSubtitle={hideSubtitle}
showModal={showModal}
{...entity}
/>
))}
Expand Down
11 changes: 10 additions & 1 deletion src/domains/Person/api/Details/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,16 @@ const parseResponse = (person: RawResponse): Response => {
Date.parse(a.originalDate) < Date.parse(b.originalDate) ? 1 : -1,
);

parsedPerson = { ...parsedPerson, knownFor, filmography };
const images = person.images?.profiles.map(image => ({
aspectRatio: image.aspect_ratio,
featuredImage: getFeaturedImage(image) || undefined,
height: image.height,
voteAverage: image.vote_average,
voteCount: image.vote_count,
width: image.width,
}));

parsedPerson = { ...parsedPerson, knownFor, filmography, images };

return parsedPerson;
};
Expand Down
11 changes: 11 additions & 0 deletions src/domains/Person/api/Details/types/RawResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ export default interface RawResponse {
imdb_id: string;
homepage?: string;

images?: {
profiles: Array<{
aspect_ratio: number;
file_path: string;
height: number;
vote_average: number;
vote_count: number;
width: number;
}>;
};

combined_credits?: { cast: RawMovie[] };
}
9 changes: 9 additions & 0 deletions src/domains/Person/api/Details/types/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export default interface Response {
knownFor?: Movie[];
filmography?: Movie[];

images?: Array<{
aspectRatio: number;
featuredImage?: string;
height: number;
voteAverage: number;
voteCount: number;
width: number;
}>;

favorite: boolean;
mediaType: number;
featuredImage?: string;
Expand Down
1 change: 1 addition & 0 deletions src/pages/Movie/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const MovieDetailsContainer = styled.div`
color: ${Color.Text};
margin-top: ${Size.Large};
width: 100%;
justify-content: space-between;
@media (min-width: 715px) {
height: 50rem;
Expand Down
10 changes: 10 additions & 0 deletions src/pages/Person/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ const Person: React.FC<any> = () => {
message="Recomendações indisponíveis."
/>

{person?.images && (
<EntityImageList
title="Fotos"
data={person.images || []}
isLoading={isLoading}
hideFavoriteButton
showModal
/>
)}

<Filmography
title="Filmografia"
data={person.filmography || []}
Expand Down
1 change: 1 addition & 0 deletions src/pages/Tv/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const TvDetailsContainer = styled.div`
color: ${Color.Text};
margin-top: ${Size.Large};
width: 100%;
justify-content: space-between;
@media (min-width: 715px) {
height: 50rem;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/helpers/Entity/getFeaturedImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { formatTmdbImage } from 'shared/helpers';

const getFeaturedImage = (value: any): string | null => {
return formatTmdbImage({
value: value.poster_path || value.profile_path,
value: value.poster_path || value.profile_path || value.file_path,
});
};

Expand Down

0 comments on commit 814de74

Please sign in to comment.