refs #123 Show followers in account profile
This commit is contained in:
parent
4f2ab66c66
commit
a0ef5779fe
|
@ -1,12 +1,43 @@
|
|||
<template>
|
||||
<div id="followers">
|
||||
Comming soon...
|
||||
<template v-for="follow in followers">
|
||||
<user :user="follow"></user>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from 'vuex'
|
||||
import User from '../../Cards/User'
|
||||
|
||||
export default {
|
||||
name: 'followers'
|
||||
name: 'followers',
|
||||
props: [ 'account' ],
|
||||
components: { User },
|
||||
computed: {
|
||||
...mapState({
|
||||
followers: state => state.TimelineSpace.Contents.SideBar.AccountProfile.Followers.followers
|
||||
})
|
||||
},
|
||||
created () {
|
||||
this.load()
|
||||
},
|
||||
watch: {
|
||||
account: function (newAccount, oldAccount) {
|
||||
this.load()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
load () {
|
||||
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchFollowers', this.account)
|
||||
.catch(() => {
|
||||
this.message({
|
||||
message: 'Could not get followers',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import Mastodon from 'mastodon-api'
|
||||
|
||||
const Followers = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
followers: []
|
||||
},
|
||||
mutations: {
|
||||
updateFollowers (state, users) {
|
||||
state.followers = users
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
fetchFollowers ({ state, commit, rootState }, account) {
|
||||
return new Promise((resolve, reject) => {
|
||||
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true, { root: true })
|
||||
const client = new Mastodon(
|
||||
{
|
||||
access_token: rootState.TimelineSpace.account.accessToken,
|
||||
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
|
||||
})
|
||||
client.get(`/accounts/${account.id}/followers`, { limit: 80 }, (err, data, res) => {
|
||||
if (err) return reject(err)
|
||||
commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false, { root: true })
|
||||
commit('updateFollowers', data)
|
||||
resolve(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Followers
|
Loading…
Reference in New Issue