-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List 1 #1
base: master
Are you sure you want to change the base?
List 1 #1
Changes from 7 commits
905da8d
5e19324
e14c399
1f1fce6
26862fb
3e77b25
6f0f04c
b3e630f
b42e676
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,83 @@ | ||
import './style.css' | ||
import axios from "axios"; | ||
const key = "f9d119ddc9f2ae7c8b2c34f1d5910a87"; | ||
const api = `https://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=${key}`; | ||
const imgUrl = "https://image.tmdb.org/t/p/w500"; | ||
const searchUrl = `https://api.themoviedb.org/3/search/movie?api_key=${key}`; | ||
const app = document.querySelector("#app"); | ||
const movieData = document.querySelector(".movie-card"); | ||
const movieSearch = document.querySelector(".search-bar"); | ||
const errorDiv = document.querySelector(".no-movie-found"); | ||
let query = ""; | ||
|
||
document.querySelector('#app').innerHTML = ` | ||
<h1>Hello Vite!</h1> | ||
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a> | ||
` | ||
async function getMovieFromApi(query) { | ||
const url = query === "" ? api : searchUrl + "&query=" + query; | ||
const response = await axios.get(url); | ||
const movieData = response.data.results.slice(0, 15); | ||
if (movieData.length) { | ||
app.style.display = "block"; | ||
showMovieData(movieData); | ||
errorDiv.style.display = "none"; | ||
} else { | ||
app.style.display = "none"; | ||
errorDiv.style.display = "block"; | ||
} | ||
} | ||
|
||
getMovieFromApi(query); | ||
|
||
movieSearch.addEventListener("keyup", (event) => { | ||
event.preventDefault(); | ||
query = event.target.value; | ||
getMovieFromApi(query); | ||
}); | ||
|
||
const showMovieData = (data) => { | ||
let count = 0; | ||
data.forEach((movie) => { | ||
const { poster_path, title } = movie; | ||
const div = document.createElement("div"); | ||
div.classList.add("card"); | ||
|
||
if (poster_path != null) { | ||
hhkk28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let imgData = document.createElement(`img`); | ||
imgData.src = imgUrl + poster_path; | ||
imgData.alt = title; | ||
|
||
let h3Data = document.createElement(`h3`); | ||
h3Data.classList.add("card-item"); | ||
|
||
if (title.length > 16) { | ||
h3Data.innerText = title.substring(0, 17) + "..."; | ||
} else { | ||
h3Data.innerText = title; | ||
} | ||
let buttonData = document.createElement(`button`); | ||
buttonData.classList.add("btn"); | ||
buttonData.innerText = "Read More"; | ||
div.appendChild(imgData); | ||
div.appendChild(h3Data); | ||
div.appendChild(buttonData); | ||
} else { | ||
let imgData = document.createElement(`img`); | ||
imgData.src = "http://via.placeholder.com/1080x1580"; | ||
imgData.alt = title; | ||
|
||
let h3Data = document.createElement(`h3`); | ||
h3Data.classList.add("card-item"); | ||
if (title.length > 16) { | ||
h3Data.innerText = title.substring(0, 17) + "..."; | ||
} else { | ||
h3Data.innerText = title; | ||
} | ||
let buttonData = document.createElement(`button`); | ||
buttonData.classList.add("btn"); | ||
buttonData.innerText = "Read More"; | ||
|
||
div.appendChild(imgData); | ||
div.appendChild(h3Data); | ||
div.appendChild(buttonData); | ||
} | ||
|
||
movieData.appendChild(div); | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,168 @@ | ||
:root { | ||
--light-grey: #626262; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
--white: #ffffff; | ||
} | ||
* { | ||
margin: 0; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
header { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.heading { | ||
font-family: "Roboto Mono"; | ||
font-size: 48px; | ||
font-weight: 250; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The font weight mentioned in the design in 400 |
||
margin: 12px 0 15px 0; | ||
} | ||
|
||
input[type="text"] { | ||
font-family: "Rubik"; | ||
padding-left: 20px; | ||
font-weight: 400; | ||
font-size: 16px; | ||
} | ||
|
||
.search-bar { | ||
height: 43px; | ||
width: 300px; | ||
border: 1px solid var(--light-grey); | ||
background: url("search.png"); | ||
background-repeat: no-repeat; | ||
background-position: right; | ||
background-position: calc(100% - 10px) center; | ||
} | ||
|
||
#app { | ||
font-family: Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
margin: 66px auto 149px auto; | ||
max-width: 1200px; | ||
} | ||
|
||
.movie-card { | ||
position: relative; | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: space-around; | ||
gap: 48px 75px; | ||
} | ||
|
||
.card img { | ||
height: 374px; | ||
width: 350px; | ||
border-radius: 20px; | ||
opacity: 1; | ||
} | ||
|
||
.card:hover img { | ||
opacity: 0.5; | ||
transition: opacity 0.5s; | ||
} | ||
|
||
.card { | ||
position: relative; | ||
} | ||
|
||
.card:hover button { | ||
display: block; | ||
} | ||
|
||
.card:hover h3 { | ||
display: block; | ||
} | ||
.card-item { | ||
position: absolute; | ||
left: 31.43%; | ||
top: 42.51%; | ||
color: var(--white); | ||
font-family: "Rubik"; | ||
font-style: normal; | ||
font-weight: 600; | ||
font-size: 24px; | ||
text-align: center; | ||
width: 122px; | ||
height: 56px; | ||
display: none; | ||
} | ||
|
||
.btn { | ||
position: absolute; | ||
left: 29.43%; | ||
top: 76.74%; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
background: #352c9a; | ||
border: none; | ||
display: none; | ||
color: var(--white); | ||
height: 37px; | ||
width: 125px; | ||
font-family: "Rubik"; | ||
font-size: 16px; | ||
font-weight: 600; | ||
} | ||
|
||
.btn:hover { | ||
background-color: #724fd8; | ||
} | ||
|
||
.btn:active { | ||
background-color: #724fdf; | ||
text-decoration: underline; | ||
} | ||
|
||
.btn:disabled { | ||
background-color: var(--light-grey); | ||
} | ||
|
||
.no-result { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.no-result img { | ||
max-width: 500px; | ||
width: 100%; | ||
} | ||
|
||
.section-item { | ||
margin-top: 96px; | ||
margin-bottom: 48px; | ||
font-family: "Rubik"; | ||
font-size: 32px; | ||
} | ||
|
||
@media (max-width: 767px) { | ||
.section-img { | ||
width: 400px; | ||
height: 360px; | ||
|
||
margin: 24px auto 81px auto; | ||
} | ||
.section-item { | ||
font-size: 30px; | ||
text-align: center; | ||
} | ||
} | ||
|
||
@media (max-width: 480px) { | ||
.heading { | ||
font-size: 36px; | ||
} | ||
.card img { | ||
width: 300px; | ||
height: 320px; | ||
margin: 24px 30px 24px 30px; | ||
} | ||
|
||
.btn { | ||
width: 125px; | ||
height: 37px; | ||
} | ||
.section-item { | ||
font-size: 20px; | ||
text-align: center; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Great attention to detail