Skip to content

Commit

Permalink
WJ-21 - Update: TV details;
Browse files Browse the repository at this point in the history
WJ-21 - Update: Details API images and backdrops;
  • Loading branch information
Lucas Teixeira committed Nov 14, 2020
1 parent 814de74 commit aff5606
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 15 deletions.
9 changes: 7 additions & 2 deletions src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback } from 'react';
import React, { useCallback, useEffect } from 'react';
import { useLocation } from 'react-router-dom';

import { useModal } from 'components/Modal/hooks';
import ModalProps from 'components/Modal/types/ModalProps';
import StyleProps from 'components/Modal/types/StyleProps';
import { GrClose as CloseIcon } from 'react-icons/gr';
import Button from 'components/Button';
Expand All @@ -28,6 +28,7 @@ const Modal: React.FC<StyleProps> = ({
shadow,
}) => {
const { modalContent, dismissModal } = useModal();
const location = useLocation();

const handleDismiss = useCallback(() => {
if (onClose) {
Expand All @@ -38,6 +39,10 @@ const Modal: React.FC<StyleProps> = ({
dismissModal();
}, [dismissModal, onClose]);

useEffect(() => {
handleDismiss();
}, [location]); // eslint-disable-line

if (!modalContent && !children && !show) {
return null;
}
Expand Down
5 changes: 4 additions & 1 deletion src/domains/Movie/api/Details/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export const rawPopular = async (
params?: Params,
): Promise<RawResponse> => {
const response = await tmdb.get(`/movie/${movieId}`, {
params: { append_to_response: params?.appendToResponse },
params: {
append_to_response: params?.appendToResponse,
include_image_language: params?.includeImageLanguage || 'pt,en,null',
},
});

return response.data;
Expand Down
1 change: 1 addition & 0 deletions src/domains/Movie/api/Details/types/Params.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default interface Params {
appendToResponse?: string;
includeImageLanguage?: string;
}
10 changes: 6 additions & 4 deletions src/domains/Tv/api/Details/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export const rawPopular = async (
params?: Params,
): Promise<RawResponse> => {
const response = await tmdb.get(`/tv/${tvId}`, {
params: { append_to_response: params?.appendToResponse },
params: {
append_to_response: params?.appendToResponse,
include_image_language: params?.includeImageLanguage || 'pt,en,null',
},
});

return response.data;
Expand All @@ -47,11 +50,10 @@ const parseResponse = (tv: RawResponse): Response => {
popularity: tv.popularity,
voteCount: tv.vote_count,
voteAverage: tv.vote_average,
tagline: tv.tagline,
runtime: `${tv.episode_run_time} min`,

directorName: tv.credits?.crew.find(
person => person.job.toUpperCase() === 'DIRECTOR',
)?.name,
creatorName: tv.created_by[0]?.name,

releaseDate: getReleaseDate(tv),
backdrop: getBackdrop(tv),
Expand Down
1 change: 1 addition & 0 deletions src/domains/Tv/api/Details/types/Params.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default interface Params {
appendToResponse?: string;
includeImageLanguage?: string;
}
3 changes: 3 additions & 0 deletions src/domains/Tv/api/Details/types/RawResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ export default interface RawResponse {
name: string;
backdrop_path?: string;
popularity: number;
tagline: string;
episode_run_time: number;
vote_count: number;
vote_average: number;
created_by: any[];

recommendations?: {
results: Recommendations[];
};
Expand Down
2 changes: 2 additions & 0 deletions src/domains/Tv/api/Details/types/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export default interface Response {
id: number;
originalTitle: string;
popularity: number;
tagline: string;
runtime: string;
voteCount: number;
voteAverage: number;
creatorName: string;

recommendations?: Recommendations[];
credits?: Credits;
Expand Down
14 changes: 8 additions & 6 deletions src/pages/Tv/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import {
TitleContainer,
Title,
Subtitle,
Tagline,
OverviewContainer,
OverviewTitle,
Overview,
VoteAverage,
VoteAverageTitle,
Director,
DirectorTitle,
Creator,
CreatorTitle,
HeaderBackground,
} from './styles';

Expand Down Expand Up @@ -104,6 +105,7 @@ const Tv: React.FC<any> = () => {
{tv.releaseDate} | {tv.genresNames} | {tv.runtime}
</Subtitle>
</TitleContainer>
{tv.tagline && <Tagline>{`"${tv.tagline}"`}</Tagline>}
<OverviewContainer>
<OverviewTitle>Sinopse</OverviewTitle>
<Overview>{tv.overview}</Overview>
Expand All @@ -112,10 +114,10 @@ const Tv: React.FC<any> = () => {
<VoteAverageTitle>Votação do público:</VoteAverageTitle>{' '}
{tv.voteAverage}
</VoteAverage>
<Director>
<DirectorTitle>Diretor: </DirectorTitle>
{tv.directorName}
</Director>
<Creator>
<CreatorTitle>Criador: </CreatorTitle>
{tv.creatorName}
</Creator>
</TvDetailsContainer>
)}
</TvContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Tv/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ export const VoteAverageTitle = styled.span`
font-weight: 500;
`;

export const Director = styled.div`
export const Creator = styled.div`
margin-bottom: ${Size.Smallest};
`;

export const DirectorTitle = styled.span`
export const CreatorTitle = styled.span`
font-weight: 500;
`;

0 comments on commit aff5606

Please sign in to comment.