1 | import { useMatch } from 'react-location' |
||
2 | import { Helmet } from 'react-helmet' |
||
3 | import { YoutubeVideo } from 'entities/YoutubeVideo' |
||
4 | import { Text, LoadingTape, Separator } from 'shared/ui' |
||
5 | import { IMAGE_BACKDROP } from 'shared/config/images' |
||
6 | |||
7 | import { IMovieDetailsVideos, IGenres, IMovieCast } from 'types/common' |
||
8 | import type { LocationGenerics } from 'app/Routes' |
||
9 | |||
10 | import styles from './movie.module.scss' |
||
11 | |||
12 | const Movie = () => { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
13 | const { |
||
14 | data: { movie }, |
||
15 | isLoading, |
||
16 | } = useMatch<LocationGenerics>() |
||
17 | |||
18 | const { results } = movie?.videos as IMovieDetailsVideos |
||
19 | |||
20 | const HeroImage = `${import.meta.env.APP_IMAGE_URL}/${IMAGE_BACKDROP.L}${ |
||
21 | movie?.backdrop_path |
||
22 | }` |
||
23 | |||
24 | console.log(movie) |
||
25 | const trailer = results?.filter( |
||
26 | ({ type }: { type: string }) => type === 'Trailer', |
||
27 | )[0] |
||
28 | |||
29 | const renderedGenres = movie?.genres.map( |
||
30 | ({ id, name }: IGenres, idx: number, self: IGenres[]) => { |
||
31 | return ( |
||
32 | <span className={styles.genreItem} key={id}> |
||
0 ignored issues
–
show
|
|||
33 | <Text tag="h3">{name}</Text> |
||
0 ignored issues
–
show
|
|||
34 | {idx !== self.length - 1 && <Separator>⚪</Separator>} |
||
0 ignored issues
–
show
|
|||
35 | </span> |
||
36 | ) |
||
37 | }, |
||
38 | ) |
||
39 | |||
40 | const renderedCast = movie?.credits?.cast.map((item: IMovieCast) => {}) |
||
0 ignored issues
–
show
|
|||
41 | |||
42 | const SEO = () => ( |
||
0 ignored issues
–
show
|
|||
43 | <Helmet |
||
0 ignored issues
–
show
|
|||
44 | defaultTitle="Moviez Rules" |
||
0 ignored issues
–
show
|
|||
45 | titleTemplate="Moviez Rules - %s" |
||
0 ignored issues
–
show
|
|||
46 | title={movie?.title} |
||
0 ignored issues
–
show
|
|||
47 | meta={[{ name: 'description', content: `${movie?.overview}` }]} |
||
0 ignored issues
–
show
|
|||
48 | link={[ |
||
0 ignored issues
–
show
|
|||
49 | { rel: 'preconnect', href: 'https://i.ytimg.com' }, |
||
50 | { rel: 'preconnect', href: 'https://www.youtube.com' }, |
||
51 | { rel: 'preload', as: 'image', href: `${HeroImage}` }, |
||
52 | ]} |
||
53 | /> |
||
54 | ) |
||
55 | |||
56 | return ( |
||
57 | <> |
||
0 ignored issues
–
show
|
|||
58 | {SEO()} |
||
0 ignored issues
–
show
|
|||
59 | {isLoading ? ( |
||
0 ignored issues
–
show
|
|||
60 | <LoadingTape /> |
||
0 ignored issues
–
show
|
|||
61 | ) : ( |
||
62 | <div |
||
0 ignored issues
–
show
|
|||
63 | className={styles.wrapper} |
||
0 ignored issues
–
show
|
|||
64 | style={{ backgroundImage: `url(${HeroImage})` }} |
||
0 ignored issues
–
show
|
|||
65 | > |
||
66 | <div className={styles.rowHalf}> |
||
0 ignored issues
–
show
|
|||
67 | {trailer && ( |
||
0 ignored issues
–
show
|
|||
68 | <YoutubeVideo embedId={trailer?.key} title={trailer?.name} /> |
||
0 ignored issues
–
show
|
|||
69 | )} |
||
70 | <div className={styles.content}> |
||
0 ignored issues
–
show
|
|||
71 | <Text tag="h1">{movie?.title}</Text> |
||
0 ignored issues
–
show
|
|||
72 | <div className={styles.genres}>{renderedGenres}</div> |
||
0 ignored issues
–
show
|
|||
73 | <Text>{movie?.overview}</Text> |
||
0 ignored issues
–
show
|
|||
74 | </div> |
||
75 | </div> |
||
76 | </div> |
||
77 | )} |
||
78 | </> |
||
79 | ) |
||
80 | } |
||
81 | |||
82 | export default Movie |
||
83 |