forked from Ammar-64/oop-movie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
167 lines (151 loc) · 3.76 KB
/
index.js
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//the API documentation site https://developers.themoviedb.org/3/
class App {
static async run(arg = "now_playing") {
const movies = await APIService.fetchMovies(arg);
HomePage.renderMovies(movies);
}
static async runGenres(id) {
const movies = await APIService.fetchMoviesByGenres(id);
HomePage.renderMovies(movies);
}
static async runPopularActors() {
const popularActors = await APIService.popularActors();
ActorsPage.renderActorsSection(popularActors);
}
static async runSearch(string) {
const searchResult = await APIService.fetchSearchResult(string);
HomePage.renderMovies(searchResult);
}
static runAboutPage() {
AboutPage.renderAboutPage();
}
}
// selectors
const topRated = document.querySelector("#topRated");
const popular = document.querySelector("#popular");
const releaseDate = document.querySelector("#releaseDate");
const upcoming = document.querySelector("#Upcoming");
const nowPlaying = document.querySelector("#nowPlaying");
const genresMenu = document.querySelector("#genres");
const actorList = document.querySelector("#actorList");
const homePage = document.querySelector("#homePage");
const searchBtn = document.querySelector("#search-btn");
const searchInput = document.querySelector("#search-input");
const aboutPage = document.querySelector("#about");
let genres = {
28: "Action",
12: "Adventure",
16: "Animation",
35: "Comedy",
80: "Crime",
99: "Documentary",
18: "Drama",
10751: "Family",
14: "Fantasy",
36: "History",
27: "Horror",
10402: "Music",
9648: "Mystery",
10749: "Romance",
878: "Science Fiction",
10770: "TV Movie",
53: "Thriller",
10752: "War",
37: "Western",
};
// event listeners
genresMenu.addEventListener("click", (e) => {
App.runGenres(e.target.id);
});
aboutPage.addEventListener("click", (e) => {
App.runAboutPage();
});
searchBtn.addEventListener("click", (e) => {
e.preventDefault();
App.runSearch(searchInput.value);
searchInput.value = "";
});
homePage.addEventListener("click", (e) => {
App.run();
});
actorList.addEventListener("click", (e) => {
App.runPopularActors();
});
topRated.addEventListener("click", (e) => {
App.run("top_rated");
});
popular.addEventListener("click", (e) => {
App.run("popular");
});
releaseDate.addEventListener("click", (e) => {
App.run("latest");
});
upcoming.addEventListener("click", (e) => {
App.run("upcoming");
});
nowPlaying.addEventListener("click", (e) => {
App.run("now_playing");
});
window.scrollTo(0, 0);
document.addEventListener("DOMContentLoaded", (e) => {
App.run();
});
// switch (e.target.id) {
// case "action":
// App.runGenres("28");
// break;
// case "sci-fi":
// App.runGenres("878");
// break;
// case "adeventure":
// App.runGenres("12");
// break;
// case "animation":
// App.runGenres("16");
// break;
// case "comedy":
// App.runGenres("35");
// break;
// case "crime":
// App.runGenres("80");
// break;
// case "documentary":
// App.runGenres("99");
// break;
// case "drama":
// App.runGenres("18");
// break;
// case "fantasy":
// App.runGenres("14");
// break;
// case "history":
// App.runGenres("36");
// break;
// case "family":
// App.runGenres("10751");
// break;
// case "horror":
// App.runGenres("27");
// break;
// case "music":
// App.runGenres("10402");
// break;
// case "mystery":
// App.runGenres("9648");
// break;
// case "romance":
// App.runGenres("10749");
// break;
// case "tv-movie":
// App.runGenres("10770");
// break;
// case "thriller":
// App.runGenres("53");
// break;
// case "war":
// App.runGenres("10752");
// break;
// case "western":
// App.runGenres("37");
// break;
// }