-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemp
106 lines (97 loc) · 3.44 KB
/
temp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { dataMovie, dataTrailer, IMG_URL } from './API/api';
import { modalHandle } from './modalHandle';
const movieList = document.getElementById('gallery-list');
const movieDetail = document.getElementById('modal-movie-detail');
const movieTrailer = document.getElementById('modal-movie-trailer');
const movieDataMarkup = (movie, videoName) => {
const {
poster_path,
title,
vote_average,
vote_count,
popularity,
original_title,
genres,
overview,
id,
} = movie;
return `
<div class="movie__tumb">
<img
src=${IMG_URL}${poster_path}
width="375"
height="478"
alt="${title}"
/>
</div>
<div class="movie__content">
<div class="movie__body">
<h2 class="movie__title">${title}</h2>
<ul class="movie__stats stats">
<li class="stats__row">
<span class="stats__name">Vote / Votes</span>
<span class="statss__value">
<span class="stats__vote">${
Math.round(vote_average * 10) / 10
}</span>
/
<span class="stats__votes">${vote_count}</span>
</span>
</li>
<li class="stats__row">
<span class="stats__name">Popularity</span>
<span class="stats__value">${
Math.round(popularity * 10) / 10
}</span>
</li>
<li class="stats__row">
<span class="stats__name">Original Title</span>
<sapn class="stats__value stats__value--uppercase">
${original_title}
</sapn>
</li>
<li class="stats__row">
<span class="stats__name">Genre</span>
<span class="stats__value">${genres
.map(genre => genre.name)
.join(', ')}</span>
</li>
</ul>
<h3 class="movie__sub-title">About</h3>
<p class="movie__description">
${overview}
</p>
<button class="movie__button-trailer" data-movie-tailer-id="${id}">${videoName}</button>
</div>
<div class="movie__actions">
<button type="button" class="movie__button">Add to watched</button>
<button type="button" class="movie__button">Add to Queue</button>
</div>
</div>
`;
};
const movieTrailerMarkup = ({ key, name }) => {
// console.log(trailer.results);
return `<iframe class="modal-trailer__youtube" width="100%" height="100%" src="https://www.youtube.com/embed/${key}?autoplay=0&enablejsapi=1" title="${name}" frameborder="0" allow="accelerometer"; loading="lazy"; autoplay; clipboard-write; encrypted-media; allowfullscreen></iframe>`;
};
const renderMarkup = (container, markup) => {
container.innerHTML = markup;
};
movieList.addEventListener('click', async event => {
event.preventDefault();
const id = event.target.closest('.card__item').dataset.movieId;
const movie = await dataMovie(id);
const trailer = await dataTrailer(id);
const video =
trailer.results.find(
result =>
result.name ===
('Official Trailer' || 'Teaser Trailer' || 'Official Teaser')
) || trailer.results[0];
renderMarkup(movieDetail, movieDataMarkup(movie, video.name));
renderMarkup(movieTrailer, movieTrailerMarkup(video));
const trailerBtn = document.querySelector('[data-movie-tailer-id]');
trailerBtn.addEventListener('click', () => {
modalHandle('movie-trailer', movieTrailer);
});
});