diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-11-16 11:02:36 -0600 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-11-16 11:02:36 -0600 |
commit | fe09567760e8379fbd3ab528c874b59110a1d779 (patch) | |
tree | a032f554c14b21f42dc51edba663cb3cc6567649 /src/state/models/post-thread-view.ts | |
parent | dcf6a497157afcc9fa8820128a85362bcb71fdc7 (diff) | |
download | voidsky-fe09567760e8379fbd3ab528c874b59110a1d779.tar.zst |
Fix up/down vote number changes
Diffstat (limited to 'src/state/models/post-thread-view.ts')
-rw-r--r-- | src/state/models/post-thread-view.ts | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/state/models/post-thread-view.ts b/src/state/models/post-thread-view.ts index 3d9f56ae3..58fee1619 100644 --- a/src/state/models/post-thread-view.ts +++ b/src/state/models/post-thread-view.ts @@ -113,19 +113,23 @@ export class PostThreadViewPostModel implements GetPostThread.Post { } async toggleUpvote() { - const wasntUpvoted = !this.myState.upvote + const wasUpvoted = !!this.myState.upvote + const wasDownvoted = !!this.myState.downvote const res = await this.rootStore.api.app.bsky.feed.setVote({ subject: { uri: this.uri, cid: this.cid, }, - direction: wasntUpvoted ? 'up' : 'none', + direction: wasUpvoted ? 'none' : 'up', }) runInAction(() => { - if (wasntUpvoted) { - this.upvoteCount++ - } else { + if (wasDownvoted) { + this.downvoteCount-- + } + if (wasUpvoted) { this.upvoteCount-- + } else { + this.upvoteCount++ } this.myState.upvote = res.data.upvote this.myState.downvote = res.data.downvote @@ -133,19 +137,23 @@ export class PostThreadViewPostModel implements GetPostThread.Post { } async toggleDownvote() { - const wasntDownvoted = !this.myState.downvote + const wasUpvoted = !!this.myState.upvote + const wasDownvoted = !!this.myState.downvote const res = await this.rootStore.api.app.bsky.feed.setVote({ subject: { uri: this.uri, cid: this.cid, }, - direction: wasntDownvoted ? 'down' : 'none', + direction: wasDownvoted ? 'none' : 'down', }) runInAction(() => { - if (wasntDownvoted) { - this.downvoteCount++ - } else { + if (wasUpvoted) { + this.upvoteCount-- + } + if (wasDownvoted) { this.downvoteCount-- + } else { + this.downvoteCount++ } this.myState.upvote = res.data.upvote this.myState.downvote = res.data.downvote |