diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/app/components/post/post.component.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index b2742c0..bf43a83 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -73,20 +73,18 @@ export class PostComponent implements OnInit { if (Object.values(x)[3] === isLike) { this.deleteRating(Object.values(x)[0], isLike); - this.voteBtns.item(Number(!isLike))!.style.backgroundColor = 'white'; - this.voteBtns.item(Number(isLike))!.style.backgroundColor = 'white'; + this.changeColorOfVoteButton(false, false); } else { this.putRating(isLike); - this.voteBtns.item(Number(!isLike))!.style.backgroundColor = 'lightblue'; - this.voteBtns.item(Number(isLike))!.style.backgroundColor = 'white'; + this.changeColorOfVoteButton(isLike, !isLike); } }, () => { this.createRating(isLike); - this.voteBtns.item(Number(!isLike))!.style.backgroundColor = 'lightblue'; + this.changeColorOfVoteButton(isLike, !isLike); } ); } @@ -115,4 +113,9 @@ export class PostComponent implements OnInit { } ); } + + private changeColorOfVoteButton(isUpvoted: boolean, isDownvoted: boolean): void { + this.voteBtns.item(0)!.style.backgroundColor = (isUpvoted) ? 'lightblue' : 'white'; + this.voteBtns.item(1)!.style.backgroundColor = (isDownvoted) ? 'lightblue' : 'white'; + } } |
