Fix up/down vote number changes

This commit is contained in:
Paul Frazee
2022-11-16 11:02:36 -06:00
parent 96d12df021
commit 310ec3a574
2 changed files with 36 additions and 20 deletions
+18 -10
View File
@@ -73,19 +73,23 @@ export class FeedItemModel implements GetTimeline.FeedItem {
} }
async toggleUpvote() { 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({ const res = await this.rootStore.api.app.bsky.feed.setVote({
subject: { subject: {
uri: this.uri, uri: this.uri,
cid: this.cid, cid: this.cid,
}, },
direction: wasntUpvoted ? 'up' : 'none', direction: wasUpvoted ? 'none' : 'up',
}) })
runInAction(() => { runInAction(() => {
if (wasntUpvoted) { if (wasDownvoted) {
this.upvoteCount++ this.downvoteCount--
} else { }
if (wasUpvoted) {
this.upvoteCount-- this.upvoteCount--
} else {
this.upvoteCount++
} }
this.myState.upvote = res.data.upvote this.myState.upvote = res.data.upvote
this.myState.downvote = res.data.downvote this.myState.downvote = res.data.downvote
@@ -93,19 +97,23 @@ export class FeedItemModel implements GetTimeline.FeedItem {
} }
async toggleDownvote() { 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({ const res = await this.rootStore.api.app.bsky.feed.setVote({
subject: { subject: {
uri: this.uri, uri: this.uri,
cid: this.cid, cid: this.cid,
}, },
direction: wasntDownvoted ? 'down' : 'none', direction: wasDownvoted ? 'none' : 'down',
}) })
runInAction(() => { runInAction(() => {
if (wasntDownvoted) { if (wasUpvoted) {
this.downvoteCount++ this.upvoteCount--
} else { }
if (wasDownvoted) {
this.downvoteCount-- this.downvoteCount--
} else {
this.downvoteCount++
} }
this.myState.upvote = res.data.upvote this.myState.upvote = res.data.upvote
this.myState.downvote = res.data.downvote this.myState.downvote = res.data.downvote
+18 -10
View File
@@ -113,19 +113,23 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
} }
async toggleUpvote() { 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({ const res = await this.rootStore.api.app.bsky.feed.setVote({
subject: { subject: {
uri: this.uri, uri: this.uri,
cid: this.cid, cid: this.cid,
}, },
direction: wasntUpvoted ? 'up' : 'none', direction: wasUpvoted ? 'none' : 'up',
}) })
runInAction(() => { runInAction(() => {
if (wasntUpvoted) { if (wasDownvoted) {
this.upvoteCount++ this.downvoteCount--
} else { }
if (wasUpvoted) {
this.upvoteCount-- this.upvoteCount--
} else {
this.upvoteCount++
} }
this.myState.upvote = res.data.upvote this.myState.upvote = res.data.upvote
this.myState.downvote = res.data.downvote this.myState.downvote = res.data.downvote
@@ -133,19 +137,23 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
} }
async toggleDownvote() { 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({ const res = await this.rootStore.api.app.bsky.feed.setVote({
subject: { subject: {
uri: this.uri, uri: this.uri,
cid: this.cid, cid: this.cid,
}, },
direction: wasntDownvoted ? 'down' : 'none', direction: wasDownvoted ? 'none' : 'down',
}) })
runInAction(() => { runInAction(() => {
if (wasntDownvoted) { if (wasUpvoted) {
this.downvoteCount++ this.upvoteCount--
} else { }
if (wasDownvoted) {
this.downvoteCount-- this.downvoteCount--
} else {
this.downvoteCount++
} }
this.myState.upvote = res.data.upvote this.myState.upvote = res.data.upvote
this.myState.downvote = res.data.downvote this.myState.downvote = res.data.downvote