Skip to content

Commit

Permalink
Merge pull request #6 from GoogolApp/search
Browse files Browse the repository at this point in the history
Search and view user profile
  • Loading branch information
igormatheusdiniz authored May 28, 2018
2 parents 0cfcaff + 8a9bc2d commit 08f9ad0
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/_services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ export class UsersService {
})
}

getAll() : Observable<User[]> {
return this.http.get<User[]>(this.url, this.httpOptions)
.map(users => {
return users;
});
}

}
3 changes: 3 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { AuthService } from '../_services/auth';
import { MatchesService } from '../_services/matches';
import { EventsService } from '../_services/events';
import { UsersService } from '../_services/users';
import { SearchedProfilePage } from '../pages/searched-profile/searched-profile';

@NgModule({
declarations: [
Expand All @@ -38,6 +39,7 @@ import { UsersService } from '../_services/users';
AllEventsTab,
MyEventsTab,
SearchPage,
SearchedProfilePage,
SignInPage,
SignUpPage,
HomePage
Expand All @@ -59,6 +61,7 @@ import { UsersService } from '../_services/users';
AllEventsTab,
MyEventsTab,
SearchPage,
SearchedProfilePage,
SignInPage,
SignUpPage,
HomePage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="placeholder" [style.background]="color">
<span class="placeholder-text">{{word.charAt(0)}}</span>
<span class="placeholder-text">{{word.charAt(0).toUpperCase()}}</span>
</div>
18 changes: 17 additions & 1 deletion src/pages/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,21 @@
</ion-navbar>
</ion-header>

<ion-content padding>
<ion-content padding padding id="SEARCH_PAGE">
<ion-searchbar placeholder="Digite o username" [(ngModel)]="usernameSearch" [showCancelButton]="shouldShowCancel" (keyup)="searchUser(usernameSearch)">
</ion-searchbar>

<ion-list no-lines>
<div *ngIf="usernameSearch !== '' ">
<button ion-item detail-none *ngFor="let user of filteredUsers" (click)="showPageUser(user._id)">
<ion-avatar item-start>
<profile-pic-generator word="{{user.username}}" color="#4A90E2"></profile-pic-generator>
</ion-avatar>
@{{user.username}}
</button>
</div>
<ion-item no-lines *ngIf="usernameSearch !== '' && usernameSearch !== undefined && anyResult === false ">
Usuário não encontrado
</ion-item>
</ion-list>
</ion-content>
11 changes: 10 additions & 1 deletion src/pages/search/search.scss
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@

#SEARCH_PAGE{
.placeholder {
height: 33px;
width: 33px;
}

.placeholder-text {
font-size: 15px;
}
}
60 changes: 56 additions & 4 deletions src/pages/search/search.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,66 @@
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Component, OnInit } from '@angular/core';
import { NavController, LoadingController } from 'ionic-angular';
import { User } from '../../_models/user';
import { UsersService } from '../../_services/users';
import { EventsService } from '../../_services/events';
import { ProfilePage } from '../profile/profile';
import { SearchedProfilePage } from '../searched-profile/searched-profile';

@Component({
selector: 'page-search',
templateUrl: 'search.html'
})
export class SearchPage {
export class SearchPage implements OnInit{

constructor(public navCtrl: NavController) {
async ngOnInit() {
await this.fetchUsers();
}
constructor(public navCtrl: NavController, private userService: UsersService, private loadingController: LoadingController) {
}

private users:User[] = [];
public filteredUsers:User[] = [];
public anyResult:boolean;

loading = this.loadingController.create({
content: 'Buscando usuário...',
spinner: 'bubbles'
});

showPageUser(id: string) {
localStorage.setItem('searchedUser', JSON.stringify(id));
this.navCtrl.push(SearchedProfilePage);
}

searchUser(input:string){
this.filteredUsers = [];
this.anyResult = false;

this.users.forEach(user => {
if(user.username.toLowerCase().includes(input.toLowerCase())) {
this.filteredUsers.push(user);
this.anyResult = true;
}
});
}

fetchUsers() {
this.loading.present();

this.userService.getAll().subscribe(
users => {
this.resetFields();
this.users = users;
this.loading.dismiss();
},
error => {
this.loading.dismiss();
console.log(error)
}
);
}

private resetFields(){
this.users = [];
}
}
67 changes: 67 additions & 0 deletions src/pages/searched-profile/searched-profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!--
Generated template for the SearchedProfilePage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>

<ion-navbar>
<ion-title>Buscar</ion-title>
</ion-navbar>

</ion-header>


<ion-content padding class="pg-profile">
<!-- img -->
<section text-center>
<profile-pic-generator word="Castor" color="#4A90E2"></profile-pic-generator>
</section>

<!-- name / username -->
<p class="text-xxlarge-normal" text-center>
@{{userSearch.username}}
<br>
<span class="text-default-light" text-center>{{userSearch.email}}</span>
</p>

<!-- follow grid -->
<ion-grid>
<ion-row>
<ion-col class="text-default-light" text-center>
<span class="text-default-medium">{{userSearch.following.length}}</span>
<br> Seguindo
</ion-col>

<ion-col class="text-default-light" text-center>
<span class="text-default-medium">{{userSearch.followers.length}}</span>
<br> Seguidores
</ion-col>

<ion-col class="text-default-light" text-center>
<span class="text-default-medium">{{5}}</span>
<br> Reputação
</ion-col>
</ion-row>
</ion-grid>

<!-- teams row -->
<section class="favorite-teams">
<p class="text-default-light">Times Favoritos</p>
<div>
<img width="40" height="40" src="https://ssl.gstatic.com/onebox/media/sports/logos/-_cmntP5q_pHL7g5LfkRiw_96x96.png">
<img width="40" height="40" src="https://ssl.gstatic.com/onebox/media/sports/logos/Th4fAVAZeCJWRcKoLW7koA_96x96.png">
<img width="40" height="40" src="https://ssl.gstatic.com/onebox/media/sports/logos/7spurne-xDt2p6C0imYYNA_96x96.png">
</div>
</section>

<section class="last-match">

<span class="text-default-light">Ultima partida</span>
<span class="text-secondary" float-right> Ver todas </span>

<googol-card [event]="eventos[0]" action="NONE"></googol-card>
</section>

</ion-content>
13 changes: 13 additions & 0 deletions src/pages/searched-profile/searched-profile.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { SearchedProfilePage } from './searched-profile';

@NgModule({
declarations: [
SearchedProfilePage,
],
imports: [
IonicPageModule.forChild(SearchedProfilePage),
],
})
export class SearchedProfilePageModule {}
9 changes: 9 additions & 0 deletions src/pages/searched-profile/searched-profile.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
page-searched-profile {
.pg-profile{
.last-match{
padding-top: 5%;
padding-bottom: 5%;
}
}

}
45 changes: 45 additions & 0 deletions src/pages/searched-profile/searched-profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { User } from '../../_models/user';
import { UsersService } from '../../_services/users';
import { EventsService } from '../../_services/events';

/**
* Generated class for the SearchedProfilePage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/

@IonicPage()
@Component({
selector: 'page-searched-profile',
templateUrl: 'searched-profile.html',
})
export class SearchedProfilePage {
userSearch = new User();
eventos = {};

constructor(public navCtrl: NavController, private userService : UsersService, private eventsService : EventsService) {
let id = JSON.parse(localStorage.getItem('searchedUser'));
this.fetchUser(id);
this.fetchEvents();
}

fetchEvents(){
this.eventos = this.eventsService.getAll();
}

fetchUser(id : string){
this.userService.getOne(id).subscribe(
data=> {
console.log(data)
this.userSearch = data;
},
err =>{
console.log(err);
}
)
}

}

0 comments on commit 08f9ad0

Please sign in to comment.