Skip to content

Commit

Permalink
removed refresher everywhere and added snackbar for left over places
Browse files Browse the repository at this point in the history
  • Loading branch information
harshbaldwa committed Sep 3, 2019
1 parent d65b9e2 commit 43ca5ce
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 48 deletions.
21 changes: 3 additions & 18 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { Subscription, timer } from 'rxjs';
})
export class AppComponent implements OnInit, OnDestroy {
title = 'ladder-ranking';
private notifN: Subscription;
private notifC: Subscription;
private notifP: Subscription;
private authSub: Subscription;
public id: string;

Expand All @@ -21,24 +18,12 @@ export class AppComponent implements OnInit, OnDestroy {
ngOnInit() {
this.authService.autoAuthUser();
this.id = localStorage.getItem('_id');
this.notifN = timer(1000)
.subscribe(data => {
this.ladderService.getNumberChallenge(this.id);
});
this.notifC = timer(1000)
.subscribe(data => {
this.ladderService.getNumberConfirmations(this.id);
});
this.notifP = timer(1000)
.subscribe(data => {
this.ladderService.getNumberPrevious(this.id);
});
this.ladderService.getNumberChallenge(this.id);
this.ladderService.getNumberConfirmations(this.id);
this.ladderService.getNumberPrevious(this.id);
}

ngOnDestroy() {
this.authSub.unsubscribe();
this.notifC.unsubscribe();
this.notifN.unsubscribe();
this.notifP.unsubscribe();
}
}
12 changes: 11 additions & 1 deletion src/app/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AuthData } from './auth-data.model';
import { Subject } from 'rxjs';
import { Router } from '@angular/router';
import { environment } from '../../environments/environment';
import { MatSnackBar } from '@angular/material';

@Injectable({ providedIn: 'root' })
export class AuthService {
Expand All @@ -13,7 +14,8 @@ export class AuthService {
private isAuthenticated = false;
private authStatusListener = new Subject<boolean>();
private wrongCredential = new Subject<boolean>();
constructor(private http: HttpClient, private router: Router) {}

constructor(private http: HttpClient, private router: Router, private snackBar: MatSnackBar) {}

getToken() {
return this.token;
Expand Down Expand Up @@ -43,6 +45,7 @@ export class AuthService {
const authData: AuthData = {name, roll, hostel, gender, category, preferred, contact, password};
this.http.post(environment.apiUrl + 'signup', authData)
.subscribe();
this.snackBar('Successfully signed up!', 'OK')
this.router.navigate(['/login']);
}

Expand All @@ -61,6 +64,7 @@ export class AuthService {
this.authStatusListener.next(true);
this.wrongCredential.next(false);
this.saveAuthData(token);
this.snackBar('Successfully logged in!', 'OK')
this.router.navigate(['/']);
}
}, error => {
Expand All @@ -84,6 +88,7 @@ export class AuthService {
this.isAuthenticated = false;
this.authStatusListener.next(false);
this.clearAuthData();
this.snackBar('Successfully logged out!', 'OK')
this.router.navigate(['/']);
}

Expand All @@ -100,4 +105,9 @@ export class AuthService {
private getAuthData() {
return localStorage.getItem('token');
}

openSnackBar(message: string, action: string) {
this.snackBar.open(message, action, { duration: 2000 });
}

}
8 changes: 2 additions & 6 deletions src/app/challenge-list/challenge-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ export class ChallengeListComponent implements OnInit, OnDestroy {
challengesS: Challenges[] = [];
private challengesSubR: Subscription;
private challengesSubS: Subscription;
private refresher: Subscription;
public id = localStorage.getItem('_id');

constructor(public ladderService: LadderService) {}

ngOnInit() {
this.refresher = timer(0, 10000).subscribe(() => {
this.ladderService.getChallengesR(this.id);
this.ladderService.getChallengesS(this.id);
});
this.ladderService.getChallengesR(this.id);
this.ladderService.getChallengesS(this.id);
this.challengesSubR = this.ladderService.getChallengesRUpdateListener()
.subscribe((challenges: Challenges[]) => {
for (const challenge of challenges) {
Expand Down Expand Up @@ -72,7 +69,6 @@ export class ChallengeListComponent implements OnInit, OnDestroy {
}

onDeleteR(id: string) {
this.refresher.unsubscribe();
this.ladderService.deleteChallengeR(id);
this.ladderService.openSnackBar('Challenge Declined!', 'OK');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ export class ConfirmationComponent implements OnInit, OnDestroy {
constructor(public ladderService: LadderService) { }

ngOnInit() {
this.refresher = timer(0, 15000)
.subscribe(data => {
this.ladderService.getConfirmations(this.id);
});
this.ladderService.getConfirmations(this.id);
this.confirmSub = this.ladderService.getConfirmationsUpdateListener()
.subscribe((confirmations: Confirmations[]) => {
this.confirmations = confirmations;
Expand Down Expand Up @@ -67,6 +64,5 @@ export class ConfirmationComponent implements OnInit, OnDestroy {

ngOnDestroy() {
this.confirmSub.unsubscribe();
this.refresher.unsubscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ <h1 style="margin-left: 20%;">Update Result</h1>
<h2>How to enter score?</h2>
</div>
<p>Enter the match score in first one <br>
Enter set score like this<br> 11-0 11-10 11-9 </p>
Enter set score like this<br> 11-5 11-10 11-9 <br>
First enter your score then opponent's,
so 11 would be your score and 5 would be opponent's score</p>
</mat-card>
10 changes: 10 additions & 0 deletions src/app/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
</span>
<span class="spacer"></span>
<ul *ngIf="!isMobile">
<li>
<button *ngIf="userAuthenticated" [routerLink]="['/']" routerLinkActive="mat-accent" color="primary" mat-raised-button>
<mat-icon>home</mat-icon>
Home
</button>
</li>
<li>
<button *ngIf="userAuthenticated && notificationsC" matBadge matBadgeColor="accent" matBadge={{notificationsC}}
matBadgeOverlap="true" routerLink="/confirmation/confirm" routerLinkActive="mat-accent" color="primary" mat-raised-button>
Expand Down Expand Up @@ -90,6 +96,10 @@
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item routerLink="/">
<mat-icon>home</mat-icon>
<span>Home</span>
</button>
<button mat-menu-item routerLink="/confirmation/confirm">
<mat-icon>done</mat-icon>
<span>Confirm Result</span>
Expand Down
7 changes: 1 addition & 6 deletions src/app/ladder-table/ladder-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class LadderTableComponent implements OnInit, OnDestroy {
sportName = new FormControl('');
filter = new FormControl('');
private authSubs: Subscription;
private refresher: Subscription;
public Id = localStorage.getItem('_id');

table: LadderRanking[] = [];
Expand Down Expand Up @@ -79,10 +78,7 @@ export class LadderTableComponent implements OnInit, OnDestroy {
}
});
// this.sportName.setValue(localStorage.getItem('sport'));
this.refresher = timer(100, 15000)
.subscribe(data => {
this.ladderService.getLadder(this.sportName.value);
});
this.ladderService.getLadder(this.sportName.value);
this.tableSub = this.ladderService.getLadderUpdateListener()
.subscribe((table: LadderRanking[]) => {
this.table = table;
Expand Down Expand Up @@ -113,7 +109,6 @@ export class LadderTableComponent implements OnInit, OnDestroy {
ngOnDestroy() {
this.tableSub.unsubscribe();
this.authSubs.unsubscribe();
this.refresher.unsubscribe();
localStorage.setItem('sport', this.sportName.value);
}
}
7 changes: 1 addition & 6 deletions src/app/previous-match/previous-match.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ export class PreviousMatchComponent implements OnInit, OnDestroy {
public displayedColumns: string[] = ['date', 'player', 'result'];
public id = localStorage.getItem('_id');
public previousMatches: PreviousMatch[];
private refresher: Subscription;
public previousSub: Subscription;
constructor(public ladderService: LadderService) {}

ngOnInit() {
this.refresher = timer(0, 15000)
.subscribe(data => {
this.ladderService.getPreviousMatchResult(this.id);
});
this.ladderService.getPreviousMatchResult(this.id);
this.previousSub = this.ladderService.getPreviousUpdateListener()
.subscribe((matches: PreviousMatch[]) => {
this.previousMatches = matches;
Expand Down Expand Up @@ -60,6 +56,5 @@ export class PreviousMatchComponent implements OnInit, OnDestroy {

ngOnDestroy() {
this.previousSub.unsubscribe();
this.refresher.unsubscribe();
}
}
5 changes: 0 additions & 5 deletions src/app/profile/edit/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,5 @@ export class ProfileComponent implements OnInit {
sportttr,
form.value.contact
);
this.openSnackBar();
}

openSnackBar() {
this.snackBar.open('Changed Successfully', 'OK!', { duration: 2000 });
}
}

0 comments on commit 43ca5ce

Please sign in to comment.