diff options
| author | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-03-14 20:03:39 +0200 |
|---|---|---|
| committer | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-03-14 20:03:39 +0200 |
| commit | 07c30c0896de316119b188c9e62f4666bf0cb2a9 (patch) | |
| tree | 7201765a9ca7c24ad2a029c68c25c265185cecb9 /src/app/components/post/post.component.ts | |
| parent | 8419a8e403abf5b25e3b53655cfafabf4eb30a3e (diff) | |
| download | DevHive-Angular-07c30c0896de316119b188c9e62f4666bf0cb2a9.tar DevHive-Angular-07c30c0896de316119b188c9e62f4666bf0cb2a9.tar.gz DevHive-Angular-07c30c0896de316119b188c9e62f4666bf0cb2a9.zip | |
added functionality to highlight buttons on init
Diffstat (limited to 'src/app/components/post/post.component.ts')
| -rw-r--r-- | src/app/components/post/post.component.ts | 24 |
1 files changed, 22 insertions, 2 deletions
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<HTMLElement>; - 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); + } + ); + } } |
