From 07c30c0896de316119b188c9e62f4666bf0cb2a9 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sun, 14 Mar 2021 20:03:39 +0200 Subject: added functionality to highlight buttons on init --- src/app/components/post/post.component.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index bf43a83..572ad9c 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -34,15 +34,23 @@ export class PostComponent implements OnInit { this._postService.getPostRequest(Guid.parse(this.paramId)).subscribe( (result: object) => { Object.assign(this.post, result); + + console.log(this.post.postId); + this.post.fileURLs = Object.values(result)[7]; this.votesNumber = this.post.currentRating; this.voteBtns = document.getElementsByClassName('vote') as HTMLCollectionOf; - this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); + this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); + this.loadUser(); } ); + + window.addEventListener("load", () => { + this.highlightButtonsOnInit(); + }); } private loadUser(): void { @@ -107,7 +115,7 @@ export class PostComponent implements OnInit { } private deleteRating(ratingId: string, isLike: boolean): void { - this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe( + this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(this.paramId)).subscribe( () => { this.votesNumber += 1 - Number(isLike) * 2; } @@ -118,4 +126,16 @@ export class PostComponent implements OnInit { this.voteBtns.item(0)!.style.backgroundColor = (isUpvoted) ? 'lightblue' : 'white'; this.voteBtns.item(1)!.style.backgroundColor = (isDownvoted) ? 'lightblue' : 'white'; } + + private highlightButtonsOnInit(): void { + this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe( + (x: object) => { + const isLike: boolean = Object.values(x)[3]; + + console.log(this.voteBtns); + + this.changeColorOfVoteButton(isLike, !isLike); + } + ); + } } -- cgit v1.2.3