Fix up/down vote number changes
parent
dcf6a49715
commit
fe09567760
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue