diff --git a/app.js b/app.js new file mode 100644 index 0000000..15c81aa --- /dev/null +++ b/app.js @@ -0,0 +1,56 @@ +const searchInput = document.querySelector("#searchInput"); +const searchButton = document.querySelector("#searchButton"); +const moviesContainer = document.querySelector("#movies"); +let sortAscending = true; + +searchButton.addEventListener("click", function () { + const query = searchInput.value; + searchMovies(query); +}); +function searchMovies(query) { + const apiKey = "befb4c19dd0617e7560221c0a7d21d93"; + const url = `https://api.themoviedb.org/3/search/movie?api_key=${apiKey}&query=${query} + `; + fetch(url) + .then((res) => res.json()) + .then((data) => { + const movies = data.results; + // console.log(movies); + displayMovies(movies); + }) + .catch((err) => console.log(err)); +} + +function displayMovies(movies) { + moviesContainer.innerHTML = ""; + searchInput.value = ""; + //bunu yapmamızın sebebi html içeriğini temizlemek için kullanıyoruz, ikinci bi arama yapıldığında tamamen sıfırdan yapması için yani çıkan sonuçlar üst üste binmesin diye. + movies.forEach((movie) => { + // const poster = movie.poster_path; + // console.log(poster); + const movieItems = document.createElement("div"); // bunu gelecek olan film bilgisini göstermesi için oluşturuyoruz. + movieItems.classList.add("movie"); // burada da ona bi classlist atıyoruz ki gelen film özelliklerini css ile düzenliyoruz + + const moviePoster = movie.poster_path + ? `https://image.tmdb.org/t/p/w500${movie.poster_path}` + : "no_image_available.png"; //resim yoksa sayfanın daha düzenli gözükmesini sağlıyor- if'li uzun kullanım yerine ternary olarak yapıldı + // console.log(moviePoster); burada img linkleri geldi + + // const movieText = movie.title; + const movieText = ` + ${movie.title} +

${movie.title}

+

${movie.release_date}

+ `; + + movieItems.innerHTML = movieText; + //Bu satır, movieItems adında oluşturulmuş olan HTML div elemanının içeriğini ayarlar. movieText değişkeni, filmle ilgili dinamik olarak oluşturulan HTML içeriğini içerir.Bu kod, movieItems elemanına movieText değişkenindeki HTML içeriğini ekler, böylece filmle ilgili görseller ve bilgiler bu div içinde görünür. + moviesContainer.appendChild(movieItems); + // Bu işlem, movieItems elemanının DOM'da görünmesini sağlar. Bu kod, moviesContainer elemanına movieItems elemanını ekler. Böylece, movieItems içinde oluşturulan HTML içeriği moviesContainer içinde görünür ve sayfada doğru şekilde yer alır. + }); +} +searchInput.addEventListener("keydown", (e) => { + if (e.key === "Enter") { + searchMovies(searchInput.value); + } +}); diff --git a/index.html b/index.html new file mode 100644 index 0000000..695ac12 --- /dev/null +++ b/index.html @@ -0,0 +1,22 @@ + + + + + + + Movie Search App + + + + +
+

Movie Search App

+ + + +
+
+ + + + \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..b4120e6 --- /dev/null +++ b/style.css @@ -0,0 +1,61 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + padding: 0; +} + +.container { + text-align: center; +} + +#searchInput { + padding: 10px; + width: 300px; +} + +#searchButton { + padding: 10px 20px; + margin-left: 10px; +} + +#movies { + margin-top: 20px; + display: flex; + flex-wrap: wrap; + justify-content: center; + /* çıkan sonuç çok olduğunda resimler input'u kapatıyordu, bu sebeple aşağıdaki kodlar yazıldı */ + overflow-y: auto; + max-height: 700px; + max-width: 100%; +} + +/* after js */ +.movie { + background-color: #fff; + border: 1px solid #ddd; + border-radius: 5px; + margin: 10px; + padding: 10px; + width: 200px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +.movie img { + width: 100%; + border-radius: 5px; +} + +.movie h3 { + font-size: 18px; + margin: 10px 0 0 0; +} + +.movie p { + font-size: 14px; + color: #555; +} \ No newline at end of file