diff options
Diffstat (limited to 'src/state/models/feed-view.ts')
-rw-r--r-- | src/state/models/feed-view.ts | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/state/models/feed-view.ts b/src/state/models/feed-view.ts index c45127ab3..e89a54194 100644 --- a/src/state/models/feed-view.ts +++ b/src/state/models/feed-view.ts @@ -73,19 +73,23 @@ export class FeedItemModel implements GetTimeline.FeedItem { } 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 @@ -93,19 +97,23 @@ export class FeedItemModel implements GetTimeline.FeedItem { } 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 |