Skip to content

Commit

Permalink
84.mostrar-resultados-en-pantalla
Browse files Browse the repository at this point in the history
  • Loading branch information
verdizone committed Mar 2, 2021
1 parent 6ac9398 commit 423b66d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';


//Modules
Expand All @@ -14,7 +15,12 @@ import { AppComponent } from './app.component';
AppComponent
],
imports: [
//Angular
BrowserModule,
HttpClientModule,
//Third parties...

//Mis Modulos
SharedModule,
GifsModule,

Expand Down
5 changes: 4 additions & 1 deletion src/app/gifs/busqueda/busqueda.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class BusquedaComponent implements OnInit {
buscarTexto( ){
const valor = this.txtBuscar.nativeElement.value;

// console.log( valor );
if (valor.trim().length === 0){
return;
}

this.gifsService.buscarGifs( valor );

this.txtBuscar.nativeElement.value = '';
Expand Down
23 changes: 22 additions & 1 deletion src/app/gifs/resultados/resultados.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
<div class="col">
<hr>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Labore distinctio, iste accusamus consequatur ut eligendi quos et tempore explicabo delectus, inventore voluptas corporis maiores incidunt illum. Voluptatem quo ab eveniet?</p>


<div class="row">
<div *ngFor="let gif of resultados"
class="col-md-4 col-sm-6">
<div class="card">
<img
[src]="gif.images.downsized_medium.url"
[alt]="gif.title"
class="card-image-top
">
<div class="card-body">
<div class="card-text">
<!-- {{ gif.title }} -->
{{ gif.images.downsized_medium.url }}
</div>
</div>
</div>
</div>
</div>



</div>
13 changes: 8 additions & 5 deletions src/app/gifs/resultados/resultados.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';
import { GifsService } from '../sevices/gifs.service';

@Component({
selector: 'app-resultados',
templateUrl: './resultados.component.html',
styles: [
]
})
export class ResultadosComponent implements OnInit {
export class ResultadosComponent {

constructor() { }

ngOnInit(): void {
get resultados(){
return this._gifsService.resultados;
}

constructor( private _gifsService:GifsService, ) { }


}
30 changes: 28 additions & 2 deletions src/app/gifs/sevices/gifs.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class GifsService {


private apiKey:string = 'l5riPVpNTboaKKKjqUAe81u9PmKLfRhG';
private _historial:string[] = [];


//TODO cambiar el tipado de any por el correspondiente
public resultados:any[] = [];

get historial (){
return [...this._historial];
}

constructor ( private http:HttpClient, ) {}

buscarGifs( query:string ){
this._historial.unshift( query );

console.log(this._historial);
query = query.trim().toLowerCase();

if (!this._historial.includes( query ) ){

this._historial.unshift( query );
this._historial = this._historial.splice(0,10);

}

// console.log(this._historial);

this.http.get(`https://api.giphy.com/v1/gifs/search?api_key=l5riPVpNTboaKKKjqUAe81u9PmKLfRhG&q=${ query }&limit=10`)
.subscribe( ( resp:any ) => {
console.log( resp.data );
this.resultados = resp.data;
})



}


Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/sidebar/sidebar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h3 class="text-light display-6">
<a href="#"
class="list-group-item list-group-item-action"
*ngFor="let item of historial"
>{{item}}
>{{item | titlecase}}
</a>

</div>
Expand Down
2 changes: 2 additions & 0 deletions src/app/shared/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export class SidebarComponent {

constructor( private _gifsService: GifsService, ){}



}

0 comments on commit 423b66d

Please sign in to comment.