@@ -201,12 +201,13 @@ function exibir_games_jogos(data, filtroBusca) {
201201 return data ;
202202}
203203
204- function exibir_resultado_pesquisa ( data , pesquisa ) {
204+ function exibir_resultado_pesquisa ( data , pesquisa , origem ) {
205205 let str = ''
206206 let button_ver_mais = document . getElementById ( "jogos-ver-mais" ) ;
207207 let cards_escondidos = document . getElementById ( "mostrar_mais_cards" ) ;
208208 let mensagem_nenhum_jogo_encontrado = document . querySelector ( ".jogos-nenhum-encontrado" ) ;
209209 let sessao_cards = document . getElementById ( 'pesquisa_cards' ) ;
210+ let repeticao ;
210211
211212 exibir_titulo_filtro_genero ( ) ;
212213 exibir_titulo_filtro_ordem ( ) ;
@@ -217,13 +218,20 @@ function exibir_resultado_pesquisa (data, pesquisa) {
217218 mensagem_nenhum_jogo_encontrado . style . display = "flex" ;
218219 sessao_cards . style . display = "none" ;
219220 } else {
220- for ( let i = 0 ; i < data . results . length ; i ++ ) {
221+ if ( origem === 1 ) {
222+ repeticao = 4 ;
223+ } else {
224+ repeticao = data . results . length
225+ }
226+
227+ for ( let i = 0 ; i < repeticao ; i ++ ) {
221228 let jogo = data . results [ i ]
222229 str += exibir_card_game_jogo ( jogo , 1 , pesquisa )
223230 }
224231
225232 sessao_cards . innerHTML = str ;
226233 }
234+
227235
228236 return data ;
229237}
@@ -384,10 +392,9 @@ function requisicao_games_jogos(filtroBusca){
384392 . then ( res => res . json ( ) )
385393 . then ( data => exibir_games_jogos ( data , filtroBusca ) ) ;
386394 } else {
387- console . log ( filtroBusca )
388395 fetch ( `https://api.rawg.io/api/games?search=${ filtroBusca } &key=0ae278d26fd24463b3d3c454be18cb17` )
389396 . then ( res => res . json ( ) )
390- . then ( data => exibir_resultado_pesquisa ( data , filtroBusca ) )
397+ . then ( data => exibir_resultado_pesquisa ( data , filtroBusca , 1 ) )
391398
392399 }
393400
@@ -399,12 +406,12 @@ function requisicao_plataformas(){
399406 . then ( data => exibir_plataformas ( data ) ) ;
400407}
401408
402- function requisicao_games_jogo_pesquisa ( ) {
409+ function requisicao_games_jogo_pesquisa ( origem ) {
403410 let barra_de_busca = document . getElementById ( "campo_buscar" ) . value ;
404411
405412 fetch ( `https://api.rawg.io/api/games?search=${ barra_de_busca } &key=0ae278d26fd24463b3d3c454be18cb17` )
406413 . then ( res => res . json ( ) )
407- . then ( data => exibir_resultado_pesquisa ( data , barra_de_busca ) )
414+ . then ( data => exibir_resultado_pesquisa ( data , barra_de_busca , origem ) )
408415}
409416
410417function requisicao_filtro_ordem ( type , ordem , nome_ordem ) {
@@ -463,6 +470,13 @@ function requisicao_games_jogo_detalhes (id, url_num, complemento) {
463470 . then ( data => exibir_detalhes_games_jogo ( data , id ) )
464471}
465472
473+ //Ativa o botao enter
474+ document . addEventListener ( "keypress" , function ( e ) {
475+ if ( e . key === "Enter" ) {
476+ requisicao_games_jogo_pesquisa ( 0 )
477+ }
478+ } )
479+
466480onload = ( ) => {
467481 requisicao_games_destaques ( ) ;
468482 requisicao_games_jogos ( '' ) ;
0 commit comments