diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/state/models/feed-view.ts | 28 | ||||
-rw-r--r-- | src/state/models/post-thread-view.ts | 28 |
2 files changed, 36 insertions, 20 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 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 |