Skip to content
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

Correction Done #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
<!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>
<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" />
<link rel="stylesheet" href="style.css" />
<link
href="https://fonts.googleapis.com/css?family=Rubik"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css?family=Roboto Mono"
rel="stylesheet"
/>
<title>Vite App</title>
</head>
<body>
<div id="app">
<h2 class="title">Movie List</h2>
<header class="center">
<form id="form">
<input
type="text"
placeholder="Search"
id="search"
class="search"
/>
</form>
</header>
<p class="noresulttext" id="nodata"></p>
<img class="nopic" id="pic" src="" alt=" " />
<main id="movie-box">
<div class="box">
<img id="posterimg" src="" alt="" />
<div class="overlay"></div>
</div>
</main>
</div>
<script type="module" src="main.js"></script>
</body>
</html>
67 changes: 62 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,63 @@
import './style.css'
const API_URL =
"https://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=04c35731a5ee918f014970082a0088b1&page=1";
const IMG_PATH = "https://image.tmdb.org/t/p/w1280";
const SEARCH_API =
"https://api.themoviedb.org/3/search/movie?&api_key=04c35731a5ee918f014970082a0088b1&query=";

document.querySelector('#app').innerHTML = `
<h1>Hello Vite!</h1>
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
`
const moiveBox = document.querySelector("#movie-box");
const getMovies = async (url) => {
const response = await fetch(url);
const data = await response.json();
showMovies(data);
};

getMovies(API_URL);

const showMovies = (data) => {
moiveBox.innerHTML = "";
document.getElementById("nodata").textContent = "";
document.getElementById("pic").src = "";

if (data.results.length === 0) {
document.getElementById("nodata").textContent =
"Sorry, there is no result for keyword you searched.";
document.getElementById("pic").src = "/readme-files/noresult_found.png";
}

data.results.forEach((result, index) => {
if (index < 15) {
const { title, poster_path } = result;
console.log(title);
const box = document.createElement("div");
box.classList.add("box");

const image = document.createElement("img");
image.setAttribute("src", IMG_PATH + poster_path);

const div = document.createElement("div");
div.classList.add("overlay");

const h3 = document.createElement("h3");
h3.classList.add("mname");
h3.textContent = title;

const div2 = document.createElement("div");
div2.classList.add("text");
div2.textContent = "Book Now";

div.append(h3, div2);
box.append(image, div);
moiveBox.append(box);
}
});
};

form.addEventListener("submit", (e) => {
e.preventDefault();
const searchTerm = search.value;
if (searchTerm) {
getMovies(SEARCH_API + "&query=" + searchTerm);
} else {
getMovies(API_URL);
}
});
199 changes: 193 additions & 6 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,195 @@
#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;
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}

* {
box-sizing: border-box;
}

.title {
position: relative;
width: 346px;
height: 63px;
left: 747px;
top: 23px;

font-family: "Roboto Mono";
font-style: normal;
font-weight: 400;
font-size: 48px;
line-height: 63px;

color: #000000;
}

header {
padding: 1rem;
display: flex;
justify-content: flex-end;
}

.header {
position: relative;
width: 346px;
height: 63px;
left: 575px;
top: 50px;
font-family: "Roboto Mono";
font-style: normal;
font-weight: 400;
font-size: 48px;
line-height: 63px;
color: #000000;
}

.search {
background-image: url("/readme-files/Vector.png");
background-size: 20px;
background-position: calc(100% - 10px) center;
background-repeat: no-repeat;
background-color: white;
border: 1px solid #626262;
border-radius: 0px;
font-size: 1rem;
padding: 0.5rem;
color: black;
width: 300px;
height: 43px;
top: 126px;
}

.center {
justify-content: center;
}

.search:focus {
outline: 0;
}

.search::placeholder {
position: absolute;
width: 53px;
height: 19px;
left: 16px;
top: 12px;
font-family: "Rubik";
font-style: normal;
font-weight: 400;
font-size: 16px;
line-height: 19px;
color: #626262;
}

#movie-box {
display: flex;
flex-wrap: wrap;
justify-content: center;
}

.box {
margin-left: 5rem;
margin-right: 5rem;
margin-top: 2rem;
border-radius: 20px;
box-shadow: 0px 10px 20px 5px rgba(0, 0, 0, 0.25);
position: relative;
overflow: hidden;
}

.box img {
height: 359px;
position: relative;
left: 0%;
right: 0%;
top: 0%;
bottom: 0%;
width: 320px;
border-radius: 20px;
margin-bottom: -5px;
}

.nopic {
position: absolute;
width: 620px;
height: 447px;
left: 580px;
top: 351px;
overflow: hidden;
}

.noresulttext {
position: absolute;
width: 792px;
height: 38px;
left: 480px;
top: 265px;
font-family: "Rubik";
font-style: normal;
font-weight: 600;
font-size: 32px;
line-height: 38px;
letter-spacing: 0.004em;
color: #000000;
}

.text {
margin-top: 50px;
position: absolute;
left: 50%;
transform: translateX(-50%);
font-family: "Rubik", sans-serif;
font-style: normal;
font-weight: 500;
font-size: 16px;
line-height: 19px;
background-color: #352c9a;
color: white;
min-width: 145px;
height: 43px;
padding: 10px;
overflow: hidden;
}

.text:hover {
background-color: #724fd8;
}

.text:active {
text-decoration: underline;
}

.mname {
margin-top: 150px;
font-family: "Rubik";
font-style: normal;
font-weight: 600;
font-size: 24px;
line-height: 28px;
letter-spacing: 0.004em;
}

.overlay {
position: absolute;
left: 0;
right: 0;
bottom: 0;
color: white;
transform: translateY(100%);
transition: transform 0.4s ease-in;
}

.box:hover .overlay {
transform: translateY(0);
position: absolute;
left: 0%;
right: 0%;
top: 0%;
bottom: 0%;
background: rgba(98, 98, 98, 0.6);
border-radius: 20px;
}