akkoma-fe/src/components/who_to_follow_panel/who_to_follow_panel.js

78 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-08-02 09:34:12 +00:00
import apiService from '../../services/api/api.service.js'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
2019-01-24 15:17:35 +00:00
import { shuffle } from 'lodash'
2018-08-02 09:34:12 +00:00
function showWhoToFollow (panel, reply) {
2019-01-24 15:17:35 +00:00
const shuffled = shuffle(reply)
panel.usersToFollow.forEach((toFollow, index) => {
2019-01-24 15:17:35 +00:00
let user = shuffled[index]
let img = user.avatar || '/images/avi.png'
let name = user.acct
toFollow.img = img
toFollow.name = name
panel.$store.state.api.backendInteractor.externalProfile(name)
.then((externalUser) => {
if (!externalUser.error) {
panel.$store.commit('addNewUsers', [externalUser])
toFollow.id = externalUser.id
}
})
})
2018-03-28 06:57:11 +00:00
}
function getWhoToFollow (panel) {
var credentials = panel.$store.state.users.currentUser.credentials
if (credentials) {
panel.usersToFollow.forEach(toFollow => {
toFollow.name = 'Loading...'
})
2019-04-10 18:48:42 +00:00
apiService.suggestions({credentials: credentials})
2018-08-02 09:38:43 +00:00
.then((reply) => {
2018-08-02 09:34:12 +00:00
showWhoToFollow(panel, reply)
})
2018-03-28 06:57:11 +00:00
}
}
2018-02-11 14:12:05 +00:00
const WhoToFollowPanel = {
data: () => ({
usersToFollow: new Array(3).fill().map(x => (
{
img: '/images/avi.png',
name: '',
id: 0
}
))
2018-02-11 14:12:05 +00:00
}),
computed: {
user: function () {
return this.$store.state.users.currentUser.screen_name
},
2018-08-22 06:15:15 +00:00
suggestionsEnabled () {
2018-09-09 19:31:34 +00:00
return this.$store.state.instance.suggestionsEnabled
2018-12-16 23:52:27 +00:00
}
},
methods: {
userProfileLink (id, name) {
return generateProfileLink(id, name, this.$store.state.instance.restrictedNicknames)
2018-02-11 14:12:05 +00:00
}
},
watch: {
user: function (user, oldUser) {
2018-08-22 06:15:15 +00:00
if (this.suggestionsEnabled) {
2018-03-28 06:57:11 +00:00
getWhoToFollow(this)
2018-02-11 14:12:05 +00:00
}
}
},
mounted:
function () {
2018-08-22 06:15:15 +00:00
if (this.suggestionsEnabled) {
2018-03-28 06:57:11 +00:00
getWhoToFollow(this)
2018-02-11 14:12:05 +00:00
}
}
}
export default WhoToFollowPanel