Skip to content

Commit 7fc1a18

Browse files
authored
Merge pull request #377 from sparcs-kaist/refactor/vote
Resolve vote delay
2 parents d60e4f9 + 8f5186d commit 7fc1a18

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

src/components/LikeButton.vue

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,43 @@ export default {
5757
if (!this.votable) {
5858
return
5959
}
60-
if (this.isSchool) {
61-
if (this.isMine) {
62-
this.$store.dispatch('dialog/toast', this.$t('nonvotable-myself'))
63-
return
64-
}
60+
if (this.isMine) {
61+
this.$store.dispatch('dialog/toast', this.$t('nonvotable-myself'))
62+
return
6563
}
6664
if (this.liked && [1, 2].includes(this.item.communication_article_status)) {
6765
this.$store.dispatch('dialog/toast', this.$t('impossible-cancel-like'))
6866
return
6967
}
70-
const myVote = this.item.my_vote === ballot
71-
? 'vote_cancel'
72-
: (ballot ? 'vote_positive' : 'vote_negative')
73-
74-
// if (this.item.my_vote === null) {
75-
// this.item.my_vote = ballot
76-
// if (ballot) {
77-
// this.item.positive_vote_count++
78-
// } else {
79-
// this.item.negative_vote_count++
80-
// }
81-
// } else {
82-
// if (this.item.my_vote) {
83-
// this.item.positive_vote_count--
84-
// } else {
85-
// this.item.negative_vote_count--
86-
// }
87-
// this.item.my_vote = null
88-
// }
8968
69+
const oldVote = this.item.my_vote
70+
const newVote = ballot
71+
72+
if (newVote === true && oldVote !== true) {
73+
// vote up && previously not voted up
74+
this.item.positive_vote_count++
75+
} else if (oldVote === true) {
76+
// previously voted up => change vote
77+
this.item.positive_vote_count--
78+
}
79+
if (newVote === false && oldVote !== false) {
80+
// vote down && previously not voted down
81+
this.item.negative_vote_count++
82+
} else if (oldVote === false) {
83+
// previously voted down => change vote
84+
this.item.negative_vote_count--
85+
}
86+
if (oldVote === newVote) {
87+
// cancel vote
88+
this.item.my_vote = null
89+
} else {
90+
// update vote
91+
this.item.my_vote = newVote
92+
}
93+
94+
const myVote = oldVote === newVote
95+
? 'vote_cancel'
96+
: (newVote ? 'vote_positive' : 'vote_negative')
9097
this.$emit('vote', { id: this.item.id, vote: myVote })
9198
},
9299
elideText (text) {

src/components/PostComment.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ export default {
244244
}
245245
this.isVoting = true
246246
await voteComment(ballot.id, ballot.vote)
247-
this.$emit('vote')
248247
this.isVoting = false
249248
},
250249
toggleReplyCommentInput () {

src/components/ThePostComments.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
class="comments__comment"
1717
@update="$emit('update', $event)"
1818
@upload="$emit('upload', $event)"
19-
@vote="$emit('refresh')"
2019
@delete="$emit('refresh')"
2120
@fetch-comment="$emit('fetch-comment', $event)"
2221
/>

src/views/Post.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ export default {
199199
} catch (err) {
200200
this.$store.dispatch('dialog/toast', this.$t('nonvotable-myself'))
201201
}
202-
await this.refresh()
203202
},
204203
205204
async archive () {

0 commit comments

Comments
 (0)