forked from AkkomaGang/akkoma-fe
refactor pin/unpin status logic
This commit is contained in:
parent
e8abe1273b
commit
ce1d19136d
2 changed files with 13 additions and 21 deletions
|
@ -24,19 +24,15 @@ const ExtraButtons = {
|
||||||
},
|
},
|
||||||
pinStatus () {
|
pinStatus () {
|
||||||
this.refreshPopper()
|
this.refreshPopper()
|
||||||
this.$store.state.api.backendInteractor.pinOwnStatus(this.status.id).then((status) => {
|
this.$store.dispatch('pinStatus', this.status.id).then((status) => {
|
||||||
if (status.error) {
|
if (status.error) {
|
||||||
this.$emit('onError', status.error)
|
this.$emit('onError', status.error)
|
||||||
} else {
|
|
||||||
this.$store.dispatch('updatePinned', status)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
unpinStatus () {
|
unpinStatus () {
|
||||||
this.refreshPopper()
|
this.refreshPopper()
|
||||||
this.$store.state.api.backendInteractor.unpinOwnStatus(this.status.id).then((status) => {
|
this.$store.dispatch('unpinStatus', this.status.id)
|
||||||
this.$store.dispatch('updatePinned', status)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
refreshPopper () {
|
refreshPopper () {
|
||||||
this.showPopper = false
|
this.showPopper = false
|
||||||
|
|
|
@ -545,21 +545,17 @@ const statuses = {
|
||||||
rootState.api.backendInteractor.fetchPinnedStatuses(userId)
|
rootState.api.backendInteractor.fetchPinnedStatuses(userId)
|
||||||
.then(statuses => dispatch('addNewStatuses', { statuses, timeline: 'user', userId }))
|
.then(statuses => dispatch('addNewStatuses', { statuses, timeline: 'user', userId }))
|
||||||
},
|
},
|
||||||
updatePinned ({ rootState, commit }, status) {
|
pinStatus ({ rootState, commit }, statusId) {
|
||||||
commit('setPinned', { status })
|
return rootState.api.backendInteractor.pinOwnStatus(statusId).then((status) => {
|
||||||
if (status.pinned) {
|
if (!status.error) {
|
||||||
const statusObj = rootState.statuses.allStatusesObject[status.id]
|
commit('setPinned', { status })
|
||||||
const user = rootState.users.currentUser
|
}
|
||||||
commit('addNewStatuses', {
|
return status
|
||||||
statuses: [statusObj],
|
})
|
||||||
showImmediately: true,
|
},
|
||||||
timeline: 'pinned',
|
unpinStatus ({ rootState, commit }, statusId) {
|
||||||
user,
|
rootState.api.backendInteractor.unpinOwnStatus(statusId)
|
||||||
userId: user.id
|
.then((status) => commit('setPinned', { status }))
|
||||||
})
|
|
||||||
} else {
|
|
||||||
commit('removeStatus', { timeline: 'pinned', statusId: status.id })
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
retweet ({ rootState, commit }, status) {
|
retweet ({ rootState, commit }, status) {
|
||||||
// Optimistic retweeting...
|
// Optimistic retweeting...
|
||||||
|
|
Loading…
Reference in a new issue