aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-13 12:02:56 +0200
committerDanail Dimitrov <danaildimitrov321@gmail.com>2021-03-13 12:02:56 +0200
commit98d4f0e3a0fc8fd8d753617a2b681a18f8a60e2b (patch)
tree99c14a82c0a08c7f93d98c919130f60fdd5a27f8
parent2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b (diff)
downloadDevHive-Angular-98d4f0e3a0fc8fd8d753617a2b681a18f8a60e2b.tar
DevHive-Angular-98d4f0e3a0fc8fd8d753617a2b681a18f8a60e2b.tar.gz
DevHive-Angular-98d4f0e3a0fc8fd8d753617a2b681a18f8a60e2b.zip
adding downVote functionality
-rw-r--r--.vs/slnx.sqlitebin167936 -> 167936 bytes
-rw-r--r--src/app/components/post/post.component.ts75
2 files changed, 35 insertions, 40 deletions
diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite
index e79a43d..2061481 100644
--- a/.vs/slnx.sqlite
+++ b/.vs/slnx.sqlite
Binary files differ
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--;
- }
- );
-}
}