Skip to content

Commit

Permalink
feat: respondFriendReq implemented and toastr incorporated
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash7824 committed Aug 25, 2024
1 parent 71f6c7a commit dd58572
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 6 deletions.
6 changes: 4 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
],
"styles": [
"@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
"src/styles.scss",
"node_modules/ngx-toastr/toastr.css"
],
"scripts": []
},
Expand Down Expand Up @@ -95,7 +96,8 @@
],
"styles": [
"@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
"src/styles.scss",
"node_modules/ngx-toastr/toastr.css"
],
"scripts": []
}
Expand Down
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"private": true,
"dependencies": {
"@angular/animations": "^16.0.0",
"@angular/animations": "^16.2.12",
"@angular/cdk": "^16.2.14",
"@angular/common": "^16.0.0",
"@angular/compiler": "^16.0.0",
Expand All @@ -22,6 +22,7 @@
"@angular/router": "^16.0.0",
"@types/socket.io-client": "^3.0.0",
"is-chess": "^1.0.2",
"ngx-toastr": "^19.0.0",
"rxjs": "~7.8.0",
"socket.io-client": "^4.7.5",
"tslib": "^2.3.0",
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {MatButtonModule} from '@angular/material/button';
import { SocialComponent } from './pages/social/social.component';
import { MatDialogModule } from '@angular/material/dialog';
import { InboxComponent } from './components/inbox/inbox.component';
import { ToastrModule } from 'ngx-toastr';
@NgModule({
declarations: [
AppComponent,
Expand All @@ -49,7 +50,8 @@ import { InboxComponent } from './components/inbox/inbox.component';
ReactiveFormsModule,
MatIconModule,
MatButtonModule,
MatDialogModule
MatDialogModule,
ToastrModule.forRoot(),
],
providers: [ApiService],
bootstrap: [AppComponent]
Expand Down
9 changes: 9 additions & 0 deletions src/app/components/inbox/inbox.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<h2 mat-dialog-title>Modal Title</h2>
<mat-dialog-content>
<div *ngFor="let friendReq of cs.getFriendRequestList" class="flex flex-column">
<h2>{{friendReq.sender | titlecase}}</h2>
<span>Sent on: {{friendReq.date | date}}</span>
<span>Status: {{friendReq.status}}</span>
<div class="flex flex-row my-2">
<button class="btn btn-success mx-2" (click)="respondFriendReq('accept', friendReq.sender_id)">Accept</button>
<button class="btn btn-danger" (click)="respondFriendReq('decline', friendReq.sender_id)">Decline</button>
</div>
</div>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button (click)="onNoClick()">Close</button>
Expand Down
40 changes: 39 additions & 1 deletion src/app/components/inbox/inbox.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ApiService } from 'src/app/services/api.service';
import { CommonService } from 'src/app/services/common.service';
import { ToastrService } from 'ngx-toastr';

@Component({
selector: 'app-inbox',
Expand All @@ -10,11 +13,46 @@ export class InboxComponent {

constructor(
public dialogRef: MatDialogRef<InboxComponent>,
@Inject(MAT_DIALOG_DATA) public data: any
@Inject(MAT_DIALOG_DATA) public data: any,
public apiServ: ApiService,
public cs: CommonService,
private toastr: ToastrService
) { }

ngOnInit(){
if(this.cs.IsUndefinedOrNull(this.cs.getFriendRequestList)){
this.apiServ.gets('social/getPendingFriendRequests').subscribe({
next: (response) => {
console.log(response);
this.cs.getFriendRequestList = response;
},
error: (error) => console.error(error)
})
}
}

onNoClick(): void {
this.dialogRef.close();
}

respondFriendReq(action: string, sender_id: string){
const body = {
responseToId: sender_id,
action: action
}
this.apiServ.posts('social/respondFriendRequest', body).subscribe({
next: (response) => {
let status = response.status
switch(status){
case 'accept': this.toastr.success('Friend Request Accepted'); break;
case 'decline': this.toastr.error('Friend Request Declined'); break;
default: this.toastr.warning('Invalid response')
}
},
error: (error) => console.error(error)
})

this.onNoClick();
}

}
9 changes: 9 additions & 0 deletions src/app/models/FriendRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface FriendRequest{
friend_req_id: string,
sender_id: string
receiver_id: string
sender: string
receiver: string
status: string
date: Date
}
6 changes: 6 additions & 0 deletions src/app/services/common.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { User } from '../models/User';
import { FriendRequest } from '../models/FriendRequest';

@Injectable({
providedIn: 'root'
Expand All @@ -10,5 +11,10 @@ export class CommonService {
socialLoaded: boolean = false;
friendsList: User[] = [];
getUser!: User;
getFriendRequestList: FriendRequest[] = [];
constructor() { }

IsUndefinedOrNull(data: any){
return (data == null || data == undefined || data == '' || data.length == 0);
}
}

0 comments on commit dd58572

Please sign in to comment.