Skip to content

Commit 9589468

Browse files
refactor: user search results now use ng pipe
1 parent 16455bc commit 9589468

File tree

3 files changed

+43
-61
lines changed

3 files changed

+43
-61
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
11
<ion-header>
2-
<ion-toolbar color="primary">
3-
<ion-buttons slot="start">
4-
<ion-menu-button></ion-menu-button>
5-
<ion-title>
6-
Github Search
7-
</ion-title>
8-
</ion-buttons>
9-
</ion-toolbar>
2+
<ion-toolbar color="primary">
3+
<ion-buttons slot="start">
4+
<ion-menu-button></ion-menu-button>
5+
<ion-title> Github Search </ion-title>
6+
</ion-buttons>
7+
</ion-toolbar>
108
</ion-header>
11-
129
<ion-content padding>
13-
<ion-list>
14-
<ion-item>
15-
<ion-input
16-
[(ngModel)]="username"
17-
type="text"
18-
placeholder="github username"
19-
>
20-
</ion-input>
21-
<ion-buttons>
22-
<ion-button (click)="getRepos()" color="primary" icon-end>
23-
<ion-icon name="search"></ion-icon>
24-
</ion-button>
25-
</ion-buttons>
26-
</ion-item>
27-
</ion-list>
28-
<ion-card *ngFor="let repo of repoList">
29-
<ion-card-header>
30-
{{ repo.name }}
31-
</ion-card-header>
32-
<ion-card-content>
33-
{{ repo.description }}
34-
</ion-card-content>
35-
</ion-card>
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>
25+
<ion-card *ngFor="let repo of repoList$ | async; let index = index;">
26+
<ion-card-header> {{ repo.name }} </ion-card-header>
27+
<ion-card-content> {{ repo.description }} </ion-card-content>
28+
</ion-card>
3629
</ion-content>
+16-24
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
1-
import { GithubService } from './../../services/github.service';
2-
import { Component, OnInit } from '@angular/core';
3-
import { Observable } from 'rxjs';
1+
import { GithubService } from "./../../services/github.service";
2+
import { Component, OnInit } from "@angular/core";
3+
import { Observable } from "rxjs";
44

55
@Component({
6-
selector: 'app-user-search',
7-
templateUrl: './user-search.page.html',
8-
styleUrls: ['./user-search.page.scss'],
9-
providers: [GithubService]
6+
selector: "app-user-search",
7+
templateUrl: "./user-search.page.html",
8+
styleUrls: ["./user-search.page.scss"],
9+
providers: [GithubService],
1010
})
1111
export class UserSearchPage implements OnInit {
12+
results: Observable<any>;
13+
public repoList$;
14+
public username;
1215

13-
results: Observable<any>;
14-
public repoList;
15-
public username;
16+
constructor(private githubService: GithubService) {}
1617

17-
constructor(private githubService: GithubService) { }
18-
19-
ngOnInit() {
20-
}
21-
22-
getRepos() {
23-
this.githubService.getRepos(this.username).subscribe(
24-
data => {
25-
this.repoList = data;
26-
},
27-
err => console.log(err),
28-
() => console.log('list of repos is returned')
29-
);
30-
}
18+
ngOnInit() {}
3119

20+
getRepos(): void {
21+
this.repoList$ = this.githubService.getRepos(this.username);
22+
console.log(this.repoList$.subscribe((x) => console.log(x)));
23+
}
3224
}

src/app/services/github.service.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ export class GithubService {
1818
})
1919
);
2020
} */
21-
getRepos(username) {
22-
const repos = this.http.get(
23-
`https://api.github.com/users/${username}/repos`
24-
);
25-
return repos;
21+
getRepos(username: string) {
22+
return this.http.get(`https://api.github.com/users/${username}/repos`);
2623
}
2724
}

0 commit comments

Comments
 (0)