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

first few challenges done up until more info btn #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
41 changes: 41 additions & 0 deletions cinemaStylesheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
body {
margin-top: 0;
margin-left: 0;
margin-right: 0;
}
.topnav {
background-color: navy;
color: white;
align-content: center;
font-family: sans-serif;
text-align: center;
padding: 5px;
}
.movie-form {
display: flex;
justify-content: center;
padding-top: 3%;
padding-bottom: 3%;
background-color: lightblue;
}
button {
padding: 2px;
border: 1px solid darkblue;
border-radius: 0%;
}
.movie-feed {
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
background-color: antiquewhite;
}
.movie-feed li {
padding-top: 3%;
}
.section2 {
margin-top: 0;
}
.section2 ul{
margin-top: 0;
}
32 changes: 32 additions & 0 deletions codebin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// fetch call and returning elements to html

// fetch API call
fetch(createUrl())
.then(function (response) {
return response.json()
}).then(function (data) {
let movieData = data.Search;
console.log(Object.keys(data))
call movieMap() function
// everything below this works
return movieData.map(function(item){
const itemKeys = Object.keys(item);
const itemArr = Object.values(item);
// console.log(itemKeys);
console.log(itemArr);
const newNode = createNode('li');
newNode.innerHTML = itemArr[0] + ': ' + itemArr[1];
returnedMovies.append(newNode);
const newImg = createNode('img');
newImg.src = itemArr[4];
const newLink = createNode('a');
const movieLink = itemArr[2]
newLink.href = `https://www.imdb.com/title/${movieLink}/`;
returnedMovies.append(newNode, newImg);
returnedMovies.append(newImg, newLink);
console.log( itemArr[0] );
})

}).catch(function (error) {
console.log('unsuccessful' + error);
})
29 changes: 29 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HL Project Cinema</title>
<link rel="stylesheet" type="text/css" href="cinemaStylesheet.css">
</head>

<body>
<div class="topnav">
<h1>Harry's Movie Searcher</h1>
</div>
<form id="movieSearchForm" class="movie-form">
<input type="text" id="movieSearchInput" autofocus value="batman">
<button type="submit" id="movieSearchButton">Search Movies</button>
</form>
<div class="container section2" id="section2">
<ul id="returnedMovies" class="movie-feed">

</ul>
</div>

<script src="./src/index.js"></script>
</body>

</html>
63 changes: 63 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// variable declaration
const movieSearchForm = document.querySelector('#movieSearchForm');
const movieSearchInput = document.querySelector('#movieSearchInput');
const movieSearchButton = document.querySelector('#moveSearchButton');

const returnedMovies = document.querySelector('#returnedMovies');

const returnedItems = document.querySelectorAll('#returnedMovies > li');

// event listeners
movieSearchForm.addEventListener('submit', submitForm);
returnedItems.addEventListener('click', moreInfo);

// form submission
function createUrl(input) {
const search = movieSearchInput.value.trim();
return `http://www.omdbapi.com/?s=${search}&apikey=564a6b07`;
}


// functions
function createNode(element) {
return document.createElement(element);
}

function resetForm(movieSearchInput) {
movieSearchInput.value = '';
movieSearchInput.focus();
}

function display(myJsonData) {
let movieArray = myJsonData.Search.map(function (movie) {
return `
<li>
<h2>${movie.Title}</h2>
<p>${movie.Year}</p>
<a href="https://www.imdb.com/title/${movie.imdbID}" target="_blank">
<img src=${movie.Poster}>
</a>
</li>
`;
}).join('');
returnedMovies.innerHTML = movieArray;
}

function submitForm(event) {
event.preventDefault();

// fetch API call
fetch(createUrl())
.then(function (response) {
return response.json()
}).then(function (myJsonData) {
return display(myJsonData);
}).catch(function (error) {
console.log('unsuccessful' + error);
})
resetForm(movieSearchInput);
}

function moreInfo(event) {
console.log(event);
}