who coded who to follow panel!?

This commit is contained in:
Henry Jameson 2026-08-26 14:32:05 +03:00
commit 8d6a93aa66

View file

@ -1,58 +1,20 @@
import { shuffle } from 'lodash'
import { useInstanceStore } from 'src/stores/instance.js'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useUsersStore } from 'src/stores/users.js'
import { fetchUser, suggestions } from 'src/api/public.js'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
function showWhoToFollow(panel, reply) {
const shuffled = shuffle(reply)
panel.usersToFollow.forEach((toFollow, index) => {
const user = shuffled[index]
const img = user.avatar || useInstanceStore().instanceIdentity.defaultAvatar
const name = user.acct
toFollow.img = img
toFollow.name = name
fetchUser({
id: name,
credentials: useOAuthStore().token,
}).then((result) => {
const { data: externalUser } = result
useUsersStore().addNewUsers(result)
toFollow.id = externalUser.id
})
})
}
function getWhoToFollow(panel) {
const credentials = useOAuthStore().token
if (credentials) {
panel.usersToFollow.forEach((toFollow) => {
toFollow.name = 'Loading...'
})
suggestions({ credentials }).then(({ data: reply }) => {
showWhoToFollow(panel, reply)
})
}
}
const WhoToFollowPanel = {
data: () => ({
usersToFollow: [],
}),
computed: {
user: function () {
user() {
return useUsersStore().currentUser.screen_name
},
suggestionsEnabled() {
return useInstanceCapabilitiesStore().suggestionsEnabled
},
},
methods: {
userProfileLink(id, name) {
@ -62,23 +24,53 @@ const WhoToFollowPanel = {
useInstanceStore().restrictedNicknames,
)
},
},
watch: {
user: function () {
if (this.suggestionsEnabled) {
getWhoToFollow()
}
getWhoToFollow() {
this.usersToFollow.forEach((toFollow) => {
toFollow.name = 'Loading...'
})
suggestions({ credentials: useOAuthStore().token }).then(
({ data: reply }) => {
this.showWhoToFollow(reply)
},
)
},
showWhoToFollow(reply) {
const shuffled = shuffle(reply)
this.usersToFollow.forEach((toFollow, index) => {
const user = shuffled[index]
const img =
user.avatar || useInstanceStore().instanceIdentity.defaultAvatar
const name = user.acct
toFollow.img = img
toFollow.name = name
fetchUser({
id: name,
credentials: useOAuthStore().token,
}).then((result) => {
const { data: externalUser } = result
useUsersStore().addNewUsers(result)
toFollow.id = externalUser.id
})
})
},
},
mounted: function () {
watch: {
user() {
this.getWhoToFollow()
},
},
mounted() {
this.usersToFollow = new Array(3).fill().map(() => ({
img: useInstanceStore().instanceIdentity.defaultAvatar,
name: '',
id: 0,
}))
if (this.suggestionsEnabled) {
getWhoToFollow()
}
this.getWhoToFollow()
},
}