aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/components/post/post.component.ts75
1 files changed, 35 insertions, 40 deletions
diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts
index 68bf161..1ec9232 100644
--- a/src/app/components/post/post.component.ts
+++ b/src/app/components/post/post.component.ts
@@ -68,66 +68,61 @@ export class PostComponent implements OnInit {
this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe(
(x: object) => {
if (Object.values(x)[3]) {
- this.deleteUpVoteRating(Object.values(x)[0]);
+ this.deleteRating(Object.values(x)[0], true);
}
else {
- this.putUpVoteRating();
+ this.putRating(true);
}
},
() => {
- this.crateUpVoteRating();
+ this.crateRating(true);
}
);
}
-
- crateUpVoteRating(): void {
- this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe(
- () => {
- this.votesNumber++;
+
+ downVotePost(): void {
+ if (!this.loggedIn) {
+ this._router.navigate(['/login']);
+ return;
}
- );
-}
- putUpVoteRating(): void {
- this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe(
- () => {
- this.votesNumber += 2;
+ this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe(
+ (x: object) => {
+ if (!Object.values(x)[3]) {
+ this.deleteRating(Object.values(x)[0], false);
+ }
+ else {
+ this.putRating(false);
+ }
},
() => {
- this.crateUpVoteRating();
+ this.crateRating(false);
}
);
}
- deleteUpVoteRating(ratingId: string): void {
- this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe(
+ crateRating(isLike: boolean): void {
+ this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), isLike).subscribe(
+ () => {
+ this.votesNumber += -1 + Number(isLike) * 2;
+ }
+ );
+}
+
+ putRating(isLike: boolean): void {
+ this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), isLike).subscribe(
() => {
- this.votesNumber--;
+ // when false -2 + 0 wjen true -2 + 4
+ this.votesNumber += -2 + Number(isLike) * 4;
}
);
}
- downVotePost(): void {
- if(!this.loggedIn) {
- this._router.navigate(['/login']);
- return;
-}
-
-this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe(
- () => {
- this.votesNumber -= 2;
- },
- () => {
- this.crateDownVoteRating();
- }
-);
+ deleteRating(ratingId: string, isLike: boolean): void {
+ this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe(
+ () => {
+ this.votesNumber += 1 - Number(isLike) * 2;
+ }
+ );
}
-
- crateDownVoteRating(): void {
- this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe(
- () => {
- this.votesNumber--;
- }
- );
-}
}