File tree 3 files changed +14
-34
lines changed
3 files changed +14
-34
lines changed Original file line number Diff line number Diff line change 7
7
</ ion-toolbar >
8
8
</ ion-header >
9
9
< ion-content padding >
10
- < ion-list >
11
- < ion-item >
12
- < ion-input
13
- [(ngModel)] ="username "
14
- type ="text "
15
- placeholder ="github username "
16
- >
17
- </ ion-input >
18
- < ion-buttons >
19
- < ion-button (click) ="getRepos() " color ="primary " icon-end >
20
- < ion-icon name ="search "> </ ion-icon >
21
- </ ion-button >
22
- </ ion-buttons >
23
- </ ion-item >
24
- </ ion-list >
10
+ < ion-searchbar
11
+ color ="primary "
12
+ type ="search "
13
+ placeholder ="search name "
14
+ [debounce] ="1000 "
15
+ (ionInput) ="handleInput($event) "
16
+ >
17
+ </ ion-searchbar >
25
18
< ion-card *ngFor ="let repo of repos$ | async; let index = index; ">
26
19
< ion-card-header > {{ repo.name }} </ ion-card-header >
27
20
< ion-card-content > {{ repo.description }} </ ion-card-content >
Original file line number Diff line number Diff line change 1
1
import { GithubService } from "./../../services/github.service" ;
2
- import { Component , OnInit } from "@angular/core" ;
2
+ import { Component } from "@angular/core" ;
3
3
import { Observable } from "rxjs" ;
4
4
import { Repo } from "./models/repo" ;
5
5
@@ -9,17 +9,16 @@ import { Repo } from "./models/repo";
9
9
styleUrls : [ "./user-search.page.scss" ] ,
10
10
providers : [ GithubService ] ,
11
11
} )
12
- export class UserSearchPage implements OnInit {
12
+ export class UserSearchPage {
13
13
results : Observable < any > ;
14
14
public repos$ : Observable < Repo [ ] > ;
15
15
public username : string ;
16
16
17
17
constructor ( private githubService : GithubService ) { }
18
18
19
- ngOnInit ( ) { }
20
-
21
- getRepos ( ) : void {
19
+ // Input username to search for Github repos
20
+ handleInput ( event : CustomEvent ) : void {
21
+ this . username = event . detail . value . toLowerCase ( ) ;
22
22
this . repos$ = this . githubService . getRepos ( this . username ) ;
23
- console . log ( this . repos$ . subscribe ( ( x ) => console . log ( x ) ) ) ;
24
23
}
25
24
}
Original file line number Diff line number Diff line change @@ -10,19 +10,7 @@ import { Repo } from "../pages/user-search/models/repo";
10
10
export class GithubService {
11
11
constructor ( private http : HttpClient ) { }
12
12
13
- /* searchData(username: string): Observable<any> {
14
- return this.http.get(`https://api.github.com/users/${username}/repos`)
15
- .pipe(
16
- map(results => {
17
- console.log('RAW: ', results);
18
- return results['Search'];
19
- })
20
- );
21
- } */
22
13
getRepos ( username : string ) : Observable < any > {
23
- const returns = this . http . get ( `https://api.github.com/users/${ username } /repos` ) ;
24
- console . log ( returns . subscribe ( ( x ) => console . log ( x ) ) ) ;
25
- console . log ( 'returns type' , typeof ( returns ) ) ;
26
- return returns ;
14
+ return this . http . get ( `https://api.github.com/users/${ username } /repos` ) ;
27
15
}
28
16
}
You can’t perform that action at this time.
0 commit comments