From 8d6a93aa665afbd38dad7552b404ec7cf242cc23 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 26 Aug 2026 14:32:05 +0300 Subject: [PATCH] who coded who to follow panel!? --- .../who_to_follow_panel.js | 90 +++++++++---------- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/src/components/who_to_follow_panel/who_to_follow_panel.js b/src/components/who_to_follow_panel/who_to_follow_panel.js index bd0eaf5e1..107ec42f7 100644 --- a/src/components/who_to_follow_panel/who_to_follow_panel.js +++ b/src/components/who_to_follow_panel/who_to_follow_panel.js @@ -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() }, }