From 8419a8e403abf5b25e3b53655cfafabf4eb30a3e Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sat, 13 Mar 2021 12:54:58 +0200 Subject: Updated the highlight functionality --- src/app/components/post/post.component.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/app/components/post/post.component.ts') 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'; + } } -- cgit v1.2.3