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

79 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-08-02 11:34:12 +02: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 16:17:35 +01:00
import { shuffle } from 'lodash'
2018-08-02 11:34:12 +02:00
function showWhoToFollow (panel, reply) {
2019-01-24 16:17:35 +01:00
const shuffled = shuffle(reply)
panel.usersToFollow.forEach((toFollow, index) => {
2022-07-31 11:35:48 +02:00
const user = shuffled[index]
const img = user.avatar || this.$store.state.instance.defaultAvatar
const name = user.acct
toFollow.img = img
toFollow.name = name
panel.$store.state.api.backendInteractor.fetchUser({ id: name })
.then((externalUser) => {
if (!externalUser.error) {
panel.$store.commit('addNewUsers', [externalUser])
toFollow.id = externalUser.id
}
})
})
2018-03-28 08:57:11 +02:00
}
function getWhoToFollow (panel) {
2022-07-31 11:35:48 +02:00
const credentials = panel.$store.state.users.currentUser.credentials
if (credentials) {
panel.usersToFollow.forEach(toFollow => {
toFollow.name = 'Loading...'
})
2022-07-31 11:35:48 +02:00
apiService.suggestions({ credentials })
2018-08-02 11:38:43 +02:00
.then((reply) => {
2018-08-02 11:34:12 +02:00
showWhoToFollow(panel, reply)
})
2018-03-28 08:57:11 +02:00
}
}
2018-02-11 15:12:05 +01:00
const WhoToFollowPanel = {
data: () => ({
usersToFollow: []
2018-02-11 15:12:05 +01:00
}),
computed: {
user: function () {
return this.$store.state.users.currentUser.screen_name
},
2018-08-22 08:15:15 +02:00
suggestionsEnabled () {
2018-09-09 21:31:34 +02:00
return this.$store.state.instance.suggestionsEnabled
2018-12-17 00:52:27 +01:00
}
},
methods: {
userProfileLink (id, name) {
return generateProfileLink(id, name, this.$store.state.instance.restrictedNicknames)
2018-02-11 15:12:05 +01:00
}
},
watch: {
user: function (user, oldUser) {
2018-08-22 08:15:15 +02:00
if (this.suggestionsEnabled) {
2018-03-28 08:57:11 +02:00
getWhoToFollow(this)
2018-02-11 15:12:05 +01:00
}
}
},
mounted:
function () {
this.usersToFollow = new Array(3).fill().map(x => (
{
img: this.$store.state.instance.defaultAvatar,
name: '',
id: 0
}
))
2018-08-22 08:15:15 +02:00
if (this.suggestionsEnabled) {
2018-03-28 08:57:11 +02:00
getWhoToFollow(this)
2018-02-11 15:12:05 +01:00
}
}
}
export default WhoToFollowPanel