Skip to content

Commit

Permalink
feat: Social page developed and fetch details
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash7824 committed Aug 24, 2024
1 parent d9ee4f0 commit e3cd9ae
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 2 deletions.
2 changes: 2 additions & 0 deletions client/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CreateRoomComponent } from './pages/create-room/create-room.component';
import { GameRoomComponent } from './pages/game-room/game-room.component';
import { LoginComponent } from './pages/login/login.component';
import { SignUpComponent } from './pages/sign-up/sign-up.component';
import { SocialComponent } from './pages/social/social.component';

const routes: Routes = [
{path: '', component: LoginComponent},
Expand All @@ -14,6 +15,7 @@ const routes: Routes = [
{path: 'game', component: GameRoomComponent },
{path: 'home', component: HomeComponent },
{path: 'signUp', component: SignUpComponent },
{path: 'social', component: SocialComponent },
];

@NgModule({
Expand Down
4 changes: 3 additions & 1 deletion client/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {MatFormFieldModule} from '@angular/material/form-field';
import {ReactiveFormsModule} from '@angular/forms';
import {MatIconModule} from '@angular/material/icon';
import {MatButtonModule} from '@angular/material/button';
import { SocialComponent } from './pages/social/social.component';
@NgModule({
declarations: [
AppComponent,
Expand All @@ -30,7 +31,8 @@ import {MatButtonModule} from '@angular/material/button';
ChessGameComponent,
SideBarComponent,
SignUpComponent,
LoginComponent
LoginComponent,
SocialComponent
],
imports: [
BrowserModule,
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/components/side-bar/side-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</a>
</li>
<li>
<a routerLink="/home" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<a routerLink="/social" class="flex items-center p-2 text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group">
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 18">
<path d="M14 2a3.963 3.963 0 0 0-1.4.267 6.439 6.439 0 0 1-1.331 6.638A4 4 0 1 0 14 2Zm1 9h-1.264A6.957 6.957 0 0 1 15 15v2a2.97 2.97 0 0 1-.184 1H19a1 1 0 0 0 1-1v-1a5.006 5.006 0 0 0-5-5ZM6.5 9a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9ZM8 10H5a5.006 5.006 0 0 0-5 5v2a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-2a5.006 5.006 0 0 0-5-5Z"/>
</svg>
Expand Down
18 changes: 18 additions & 0 deletions client/src/app/pages/social/social.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<app-side-bar></app-side-bar>

<section>
<div class="w-100 my-4 flex justify-center items-center">
<input
type="text"
placeholder="Search friends..."
class="my-2 w-[500px] pl-4 pr-4 py-2 px-4 text-center text-sm text-slate-900 bg-white border border-slate-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 shadow-sm"
(input)="searchFriends($event)"
/>
</div>

<div>
<div *ngFor="let friend of friendsList">
<span>{{friend.name}}</span>
</div>
</div>
</section>
Empty file.
50 changes: 50 additions & 0 deletions client/src/app/pages/social/social.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { User } from 'src/app/models/User';
import { ApiService } from 'src/app/services/api.service';
import { CommonService } from 'src/app/services/common.service';

@Component({
selector: 'app-social',
templateUrl: './social.component.html',
styleUrls: ['./social.component.scss']
})
export class SocialComponent implements OnInit{

friendsList: User[] = [];
allUsers: any;
constructor(public apiServ: ApiService, private cs: CommonService){}

ngOnInit(){
if(!this.cs.socialLoaded){
this.getAllUsers().then((val: any) => {
this.friendsList = this.allUsers;
this.cs.socialLoaded = true;
})
}
}

searchFriends(ev: any){
let name = ev.target.value;
if(!name){
this.friendsList = this.allUsers;
}

this.friendsList = [];
for(let user of this.allUsers){
let case_sensitive_user_name = user.name.toLowerCase();
if(case_sensitive_user_name.includes(name.toLowerCase())){
if(!this.friendsList.some(friend => friend.name == user.name)){
this.friendsList.push(user);
}
}
}
}


getAllUsers() : Promise<any>{
return this.apiServ.get("admin/getAllUsers").then((res: any) => {
this.allUsers = res;
}, (error: any) => console.error(error)
)}
}
10 changes: 10 additions & 0 deletions client/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,14 @@ export class ApiService {
httpHeaders = httpHeaders.append('Access-Control-Allow-Headers', 'Content-Type');
return this.http.get<User>(`${environment.base_url}/${this.getUser_Url}`, { headers: httpHeaders })
}

public get(endpoint: any): Promise<any>{
let authorizationToken = JSON.parse(sessionStorage.getItem('authToken') || '');
let httpHeaders: HttpHeaders = new HttpHeaders();
httpHeaders = httpHeaders.append('auth-token', authorizationToken.authToken);
httpHeaders = httpHeaders.append('Content-Type', 'application/json');
httpHeaders = httpHeaders.append('Accept', 'application/json');
httpHeaders = httpHeaders.append('Access-Control-Allow-Headers', 'Content-Type');
return this.http.get<any>(`${environment.base_url}/${endpoint}`, { headers: httpHeaders }).toPromise();
}
}
1 change: 1 addition & 0 deletions client/src/app/services/common.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import { Injectable } from '@angular/core';
export class CommonService {

homeLoaded: boolean = false;
socialLoaded: boolean = false;
constructor() { }
}

0 comments on commit e3cd9ae

Please sign in to comment.