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