-
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 4 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,13 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/main.js"></script> | ||
</body> | ||
</html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="" t="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@500&family=Rubik:wght@600&display=swap" rel="stylesheet"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>Book Ticket</title> | ||
</head> | ||
|
||
<body> | ||
<header class="header"> | ||
<h1 class="heading">Book Tickets</h1> | ||
<form class="form" method="post"> | ||
<input type="text" class="search-bar" placeholder="search" onfocus="this.placeholder=''" | ||
onblur="this.placeholder='search'"> | ||
</form> | ||
</header> | ||
<div id="app"> | ||
|
||
<div class="movie-card"> | ||
|
||
</div> | ||
</div> | ||
<div class="no-movie-found"> | ||
<div class="no-result"> | ||
<h2 class="section-item"> Sorry, there is no result for keyword you searched.</h2> | ||
<img class="section-img" src="MovieNotFound.png" alt="result not found"> | ||
</div> | ||
|
||
</div> | ||
<!-- <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> --> | ||
<script type="module" src="main.js"></script> | ||
|
||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,79 @@ | ||
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}`; | ||
|
||
document.querySelector('#app').innerHTML = ` | ||
<h1>Hello Vite!</h1> | ||
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a> | ||
` | ||
const app=document.querySelector("#app"); | ||
const movieData=document.querySelector(".movie-card"); | ||
const movieSearch=document.querySelector(".search-bar") | ||
const errorDiv=document.querySelector(".no-movie-found"); | ||
|
||
|
||
async function getMovieFromApi(api) { | ||
const response= await axios.get(api); | ||
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.
|
||
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(api); | ||
|
||
movieSearch.addEventListener("keyup", (event)=>{ | ||
event.preventDefault(); | ||
const query=event.target.value; | ||
|
||
if(query.length>0){ | ||
getMovieFromApi(searchUrl+"&query="+query); | ||
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. You can just pass query in this function since variables like api and searchUrl are globally scoped.
|
||
}else{ | ||
getMovieFromApi(api); | ||
} | ||
|
||
}); | ||
|
||
const showMovieData=(data)=>{ | ||
movieData.innerHTML =''; | ||
let count=0; | ||
data.forEach(movie => { | ||
const {poster_path,title}= movie; | ||
const div = document.createElement('div'); | ||
div.classList.add("card"); | ||
let htmlData=``; | ||
if(poster_path!=null){ | ||
htmlData+=`<img src="${imgUrl +poster_path}" alt="${title}">`; | ||
if(title.length>16){ | ||
htmlData+=`<h3 class="card-item"> ${title.substring(0,17)}...</h3>`; | ||
}else{ | ||
htmlData+=`<h3 class="card-item"> ${title}</h3>` | ||
} | ||
htmlData+=`<button class ="btn"> Read More </button>` | ||
|
||
div.innerHTML=htmlData | ||
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. Although innerHTML is one of the ways you can directly add elements, it should be avoided due to various reasons.. |
||
|
||
|
||
|
||
}else{ | ||
htmlData+=`<img src="http://via.placeholder.com/1080x1580" alt="${title}">`; | ||
if(title.length>16){ | ||
htmlData+=`<h3 class="card-item"> ${title.substring(0,17)}...</h3>` | ||
}else{ | ||
htmlData+=`<h3 class="card-item"> ${title}</h3>` | ||
} | ||
htmlData+=`<button class ="btn"> Read More </button>` | ||
|
||
div.innerHTML=htmlData | ||
|
||
} | ||
|
||
movieData.appendChild(div); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,176 @@ | ||
#app { | ||
font-family: Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
* { | ||
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; | ||
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 #626262; | ||
background: url('search.png'); | ||
background-repeat: no-repeat; | ||
background-position: right; | ||
background-position: calc(100% - 10px) center; | ||
} | ||
|
||
|
||
#app{ | ||
margin: 66px auto 149px auto; | ||
max-width: 1200px; | ||
} | ||
|
||
.movie-card{ | ||
position: relative; | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: space-around; | ||
gap:48px 75px; | ||
} | ||
|
||
|
||
.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; | ||
} | ||
|
||
|
||
.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: #FFFFFF; | ||
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; | ||
background: #352C9A; | ||
border: none; | ||
display: none; | ||
color: #FFFFFF; | ||
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: #626262; | ||
} | ||
|
||
@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