Skip to content

Commit

Permalink
changes of search
Browse files Browse the repository at this point in the history
  • Loading branch information
tayronemachadozup committed Jun 25, 2020
1 parent fc199ef commit bd7609c
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 83 deletions.
40 changes: 22 additions & 18 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const MovieDbPath = 'https://api.themoviedb.org';

// URLS IMAGENS
const IMG_URL = 'https://image.tmdb.org/t/p/w1920_and_h600_multi_faces';
const IMG_URL1 = 'https://image.tmdb.org/t/p/w220_and_h330_face/';
const IMG_URL_List = 'https://image.tmdb.org/t/p/w220_and_h330_face/';

//API
//API URL
function generateMovieDBUrl(path) {
const url = `${MovieDbPath}/3${path}api_key=${ApiKEY}&page=2&language=pt-BR`;
return url;
}
const url = `${MovieDbPath}/3${path}api_key=${ApiKEY}&page=2&language=pt-BR`;
return url;
}

function requestApi(type,url) {
return fetch(url)
Expand All @@ -25,11 +25,11 @@ function requestApi(type,url) {
}

function renderContent(point,data) {
console.log('render content', data);
//console.log('render content', data);
const list = `
<ul class="content__list__carousel">
${data.results.map(movie => `
<li class="content__list__carousel__folder"><img class ="img__folder" src="${IMG_URL1 + movie.poster_path}"></li>
<li class="content__list__carousel__folder"><img class ="img__folder" src="${IMG_URL_List + movie.poster_path}"></li>
`).join('')}
</ul>
`;
Expand All @@ -41,20 +41,24 @@ function renderEndpoint(element){
}

async function handleRequest(path,type,element){
let data = getToStorage(type);
if (!data) {
const url = generateMovieDBUrl(path);
await requestApi(type,url);
data = getToStorage(type);
}
renderContent(element, data);
try{
let data = getToStorage(type);
if (!data) {
const url = generateMovieDBUrl(path);
await requestApi(type,url);
data = getToStorage(type);
console.log('não exite');
}
renderContent(element, data);
}
catch(err){
console.log(err.msg);
}
}


function saveToStorage(arrName,data){
localStorage.setItem(arrName, JSON.stringify(data));
}

function getToStorage(arr){
return JSON.parse(localStorage.getItem(arr));
function getToStorage(arrName){
return JSON.parse(localStorage.getItem(arrName));
}
3 changes: 3 additions & 0 deletions childish/childish.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ <h2 class="content__title">Animações</h2>

</section>
</section>
<script src="../urlsCarousel.js"></script>
<script src="../api.js"></script>
<script src="childish.js"></script>
</body>
</html>
140 changes: 104 additions & 36 deletions childish/childish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,137 @@ const bestMoviesElement = document.querySelector('#childish-best-movies');
const actionMoviesElement = document.querySelector('#childish-action-movies');
const educationalSeriesElement = document.querySelector('#childish-educational-series');
const moviesSeriesElement = document.querySelector('#childish-movies-series');
const animationElement = document.querySelector('#childish-animation');
const animationElement = document.querySelector('#childish-animations');


function getAmazonOriginals(){
const url = generateMovieDBUrl('');
requestApi('',url);
const data = getToStorage('');
console.log('O array esta vindo de movies amazon originais', data);
renderContent(amazonOriginalsElement, data);
handleRequest('/discover/tv?with_genres=10762&','kids-series',amazonOriginalsElement);
}

function getBestMovies(){
const url = generateMovieDBUrl('');
requestApi('best-movies',url);
const data = getToStorage('best-movies');
console.log('O array esta vindo de best-movies', data);
renderContent(bestMoviesElement, data);
handleRequest('/discover/movie?with_genres=16&','kids-best-movies',bestMoviesElement);
}

function getActionMovies(){
const url = generateMovieDBUrl('');
requestApi('',url);
const data = getToStorage('');
console.log('O array esta vindo de ', data);
renderContent(bestMoviesElement, data);
handleRequest('','',);
}

function getEducationalSeries(){
const url = generateMovieDBUrl('');
requestApi('',url);
const data = getToStorage('');
console.log('O array esta vindo ', data);
renderContent(bestMoviesElement, data);
handleRequest('/discover/tv?with_genres=10751&','kids-educational-series',educationalSeriesElement);
}

function getMoviesSeries(){
const url = generateMovieDBUrl('') ;
requestApi('',url);
const data = getToStorage('');
console.log('O array esta vindo de ', data);
renderContent(thrillerMoviesElement, data);
handleRequest('','',);
}

function getAnimations(){
const url = generateMovieDBUrl('');
requestApi('',url);
const data = getToStorage('');
console.log('O array esta vindo de ', data);
renderContent(animationElement, data);
handleRequest('/discover/tv?with_genres=16&','kids-animation',animationElement);
}


//Getters
getAmazonOriginals();
getBestMovies();
getActionMovies();
// getActionMovies();
getEducationalSeries();
getMoviesSeries();
// getMoviesSeries();
getAnimations();


//https://www.themoviedb.org/search/remote/tv_network?take=50&skip=0&page=1&


//https://api.themoviedb.org/3/discover/tv?with_genres=16&api_key=9c5c64f28ef6b06c9548ba6f6077905a&page=2
//https://api.themoviedb.org/3/discover/tv?with_genres=10762&with_genres=10759&api_key=9c5c64f28ef6b06c9548ba6f6077905a&page=2

// discover/tv?with_genres=10762&

// aventura href="/discover/tv?with_genres=10759"


// discover/tv?with_genres=10762
//https://api.themoviedb.org/3/discover/tv?with_genres=10762&api_key=9c5c64f28ef6b06c9548ba6f6077905a&page=2

//https://api.themoviedb.org/3/discover/tv?with_genres=10751&api_key=9c5c64f28ef6b06c9548ba6f6077905a&page=2

//https://api.themoviedb.org/3/discover/movies?with_genres=16&12&28&api_key=9c5c64f28ef6b06c9548ba6f6077905a&page=2
/*
{
"genres": [
{
"id": 28,
"name": "Ação" --
},
{
"id": 12,
"name": "Aventura" --
},
{
"id": 16,
"name": "Animação" --
},
{
"id": 35,
"name": "Comédia"
},
{
"id": 80,
"name": "Crime"
},
{
"id": 99,
"name": "Documentário"
},
{
"id": 18,
"name": "Drama"
},
{
"id": 10751,
"name": "Família"
},
{
"id": 14,
"name": "Fantasia"
},
{
"id": 36,
"name": "História"
},
{
"id": 27,
"name": "Terror"
},
{
"id": 10402,
"name": "Música"
},
{
"id": 9648,
"name": "Mistério"
},
{
"id": 10749,
"name": "Romance"
},
{
"id": 878,
"name": "Ficção científica"
},
{
"id": 10770,
"name": "Cinema TV"
},
{
"id": 53,
"name": "Thriller"
},
{
"id": 10752,
"name": "Guerra"
},
{
"id": 37,
"name": "Faroeste"
}
]
}
*/
23 changes: 11 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const addedSeriesElement =document.querySelector('#series-added');

var slideIndex = 1;

//function reload(){
// document.location.reload(true);
//}

function createCarousel(arrMovies) {
const carousel = `
<ul class="carousel__slideshow">
Expand Down Expand Up @@ -51,14 +47,18 @@ function currentSlide(n) {
}

function search() {
let arrSearch = getToStorage('search-result');
inputElement.addEventListener("keypress", event => {
let value = event.target.value.toLowerCase();

if(event.which == 13){
const url = generateMovieDBUrl('/search/multi?')+`&query=${value}`;
requestApi('search-result',url);
//window.location.href = './search/search.html';
console.log(getToStorage('search-result'));
if(event.which == 13){
const url = generateMovieDBUrl('/search/multi?')+`&query=${value}`;
if(arrSearch){
localStorage.removeItem('search-result');
console.log('Foi apagado');
}
console.log('O array não exites e passou na Verificação');
requestApi('search-result',url);
//window.location.href = './search/search.html';
}
});
}
Expand Down Expand Up @@ -99,7 +99,6 @@ getSeriesAdded ();

createCarousel(foldersCarousel);
search();
renderContent();
showSlides(slideIndex);
reload();


2 changes: 1 addition & 1 deletion search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h1><img src="../assets/prime-brand.png" alt="Amazon-prime-brand"></h1>

</section>
</section>
<script src="../index.js"></script>
<script src="../api.js"></script>
<script src="search.js"></script>
</body>
</html>
Expand Down
27 changes: 11 additions & 16 deletions search/search.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
const resultsElement = document.querySelector('#search-results');

const arrResults = getToStorage('search-result');

//console.log(arrResults);
console.log('foi chamado', arrResults);

function renderResults(data){
const result = `
<ul class="search__results__list">
${data.results.map(movie => `
<li class="search__results__list__items"><img class ="img__forder" src="${IMG_URL1 + movie.poster_path}"></li></li>
function renderResults(){
const data = getToStorage('search-result');
console.log(' Resultados do array que a search vai pegar :',data);
const results = `
<ul class="search__results__list">
${data.results.map(movie => `
<li class="search__results__list__items"><img class ="img__folder" src="${IMG_URL_List + movie.poster_path}"></li>
` ).join('')}
`
resultsElement.innerHTML = result;
}


function getToStorage(arr){
return JSON.parse(localStorage.getItem(arr));
resultsElement.innerHTML = results;
}



renderResults(arrResults);
renderResults();

0 comments on commit bd7609c

Please sign in to comment.