-
Notifications
You must be signed in to change notification settings - Fork 38
Project cinema by Mariusz Sygnowski #18
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
Open
mariuszsygnowski
wants to merge
17
commits into
constructorlabs:master
Choose a base branch
from
mariuszsygnowski:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
24fcb87
beggining of app
mariuszsygnowski 242c643
beginning of app
mariuszsygnowski b84d765
search button displaying input.value in <p> element
mariuszsygnowski 13a31c8
Title, year and poster is displayed after typed in search box
mariuszsygnowski c1b90cc
search bar and 2 layouts for screen sizes
mariuszsygnowski b45e92e
correction in last commit: added all files
mariuszsygnowski 9487a6b
https insted of http: website via github will works now correctly
mariuszsygnowski e4048b2
adjustment in grid gap
mariuszsygnowski e81911f
rebild app.js: moved paramaters to object params, added function setUrl
mariuszsygnowski 38aee1d
images are on beggining of every found movie, description is also add…
mariuszsygnowski dec0fea
prev and next button are working now
mariuszsygnowski 0ed38cb
search box width will be set to 30rem when screen is over 500px
mariuszsygnowski 1935bf4
when clicked on selected movie, poster is gone and in that place I fi…
mariuszsygnowski 4bbebf7
more details after clicked on selected movie
mariuszsygnowski af12429
adjustemnt in font weight
mariuszsygnowski ec48044
small changes in searchResult.innerHTML
mariuszsygnowski 52834e3
testing version: pageNumber:2
mariuszsygnowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" | ||
| content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <link rel="stylesheet" href="style.css"> | ||
| <title>Project Cinema by Mariusz Sygnowski</title> | ||
| </head> | ||
| <body> | ||
|
|
||
| <div class="container"> | ||
| <div class="control"> | ||
| <form id="control__search"> | ||
| <input type="text" class="control__search__input"/> | ||
| <input type="submit" class="control__search__submit" value="Search" /> | ||
| </form> | ||
| </div> | ||
|
|
||
| <div class="buttons"> | ||
| <button class="buttons__button-prev">Prev</button> | ||
| <p class="currentPage"></p> | ||
| <div class="results"> | ||
|
|
||
| </div> | ||
| <p class="currentPage"></p> | ||
| <button class="buttons__button-next">Next</button> | ||
| </div> | ||
|
|
||
| </div> | ||
|
|
||
|
|
||
| <script src="js/app.js"></script> | ||
| </body> | ||
| </html> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| const form = document.querySelector('#control__search'), | ||
| searchInput = document.querySelector('.control__search__input'), | ||
| results = document.querySelector('.results'), | ||
| buttonsClass = document.querySelector('.buttons'), | ||
| currentPageClasses = document.querySelectorAll('.currentPage'), | ||
| nextBtn = document.querySelector('.buttons__button-next'), | ||
| prevBtn = document.querySelector('.buttons__button-prev'); | ||
|
|
||
| let params = { | ||
| inputValue: searchInput.value, | ||
| pageNumber: 2, | ||
| totalPages: 0, | ||
| imdbID: '', | ||
| apiKey: 'f899a3c1' | ||
| }; | ||
|
|
||
| form.addEventListener('submit', (e) => { | ||
| e.preventDefault(); | ||
| buttonsClass.style.display = 'none'; | ||
| results.innerHTML = ''; | ||
| params.pageNumber = 1; | ||
| params.totalPages = 0; | ||
| params.inputValue = searchInput.value; | ||
| runFetch(); | ||
| }); | ||
|
|
||
| nextBtn.addEventListener('click', (e) => { | ||
| e.preventDefault(); | ||
| results.innerHTML = ''; | ||
| buttonsClass.style.display = 'none'; | ||
| if (params.pageNumber === params.totalPages) { | ||
| params.pageNumber = 1; | ||
| } else { | ||
| params.pageNumber++; | ||
| } | ||
|
|
||
| runFetch(); | ||
| }); | ||
|
|
||
| prevBtn.addEventListener('click', (e) => { | ||
| e.preventDefault(); | ||
| results.innerHTML = ''; | ||
| buttonsClass.style.display = 'none'; | ||
| if (params.pageNumber === 1) { | ||
| params.pageNumber = params.totalPages; | ||
| } else { | ||
| params.pageNumber--; | ||
| } | ||
| runFetch(); | ||
|
|
||
| }); | ||
|
|
||
| function setUrlWithTypedSearch() { | ||
| return `https://www.omdbapi.com/?&plot=full&apikey=${params.apiKey}&s=${params.inputValue}&page=${params.pageNumber}`; | ||
| } | ||
|
|
||
| function setUrlForEachMovieWithImdbIDNumber() { //I need imdbID to get full details of every found movie | ||
| return `https://www.omdbapi.com/?i=${params.imdbID}&plot=full&apikey=${params.apiKey}&page=${params.pageNumber}`; | ||
| } | ||
|
|
||
| function runFetch() { | ||
| fetch(setUrlWithTypedSearch()) | ||
| .then((response) => { | ||
| return response.json(); | ||
| }) | ||
| .then((body) => { | ||
| params.totalPages = body.totalResults / 10; //divide by as as there is 10 results per page | ||
| params.totalPages = Math.ceil(params.totalPages); //round up as I want to have all possible number of pages | ||
| currentPageClasses.forEach((currentPageClass) => { | ||
| currentPageClass.textContent = `page ${params.pageNumber} / ${params.totalPages}`; | ||
| }); | ||
| body.Search.forEach(e => { | ||
|
Collaborator
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. Would be great to see display logic extracted to own function |
||
| params.imdbID = e.imdbID; | ||
| fetch(setUrlForEachMovieWithImdbIDNumber()) | ||
| .then((response) => { | ||
| return response.json(); | ||
| }) | ||
| .then((body) => { | ||
| // console.log(body); | ||
| buttonsClass.style.display = 'block'; | ||
| let movieParams = { | ||
| description: body.Plot, | ||
| poster: body.Poster, | ||
| title: body.Title, | ||
| year: body.Year, | ||
| actors: body.Actors | ||
| }; | ||
|
|
||
| let searchResult = document.createElement('div'); | ||
| searchResult.className = 'results__searchResult'; | ||
|
|
||
| if (movieParams.poster === 'N/A') { //if there is no poster then I use default image | ||
| movieParams.poster = 'images/noPoster.jpg'; | ||
| } | ||
| if (movieParams.description === 'N/A') { //if there is no description I set | ||
| movieParams.description = ''; | ||
| } | ||
|
|
||
| searchResult.innerHTML = ` | ||
| <h2 class="results__searchResult__title">${movieParams.title}</h2> | ||
| <img class="results__searchResult__poster" src="${movieParams.poster}"/> | ||
| <h3 class="results__searchResult__year hide">(${movieParams.year})</h3> | ||
| <h3 class="results__searchResult__actors hide">Actors: ${movieParams.actors}</h3> | ||
| <h3 class="results__searchResult__description hide">${movieParams.description}</h3> | ||
| `; | ||
| const posterImg = searchResult.querySelector('.results__searchResult__poster'); | ||
| const description = searchResult.querySelector('.results__searchResult__description'); | ||
| const year = searchResult.querySelector('.results__searchResult__year'); | ||
| const actors = searchResult.querySelector('.results__searchResult__actors'); | ||
| searchResult.addEventListener('click', () => { | ||
| // console.log(posterImg); | ||
| description.classList.toggle('hide'); | ||
| year.classList.toggle('hide'); | ||
| posterImg.classList.toggle('hide'); | ||
| actors.classList.toggle('hide'); | ||
| }); | ||
| results.append(searchResult); | ||
| }) | ||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| console.log('Server failed to return data: ' + error); | ||
| }); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Good use of BEM