who coded who to follow panel!?
This commit is contained in:
parent
f60a5c404e
commit
8d6a93aa66
1 changed files with 41 additions and 49 deletions
|
|
@ -1,58 +1,20 @@
|
||||||
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 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 = {
|
const WhoToFollowPanel = {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
usersToFollow: [],
|
usersToFollow: [],
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
user: function () {
|
user() {
|
||||||
return useUsersStore().currentUser.screen_name
|
return useUsersStore().currentUser.screen_name
|
||||||
},
|
},
|
||||||
suggestionsEnabled() {
|
|
||||||
return useInstanceCapabilitiesStore().suggestionsEnabled
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
userProfileLink(id, name) {
|
userProfileLink(id, name) {
|
||||||
|
|
@ -62,23 +24,53 @@ const WhoToFollowPanel = {
|
||||||
useInstanceStore().restrictedNicknames,
|
useInstanceStore().restrictedNicknames,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
getWhoToFollow() {
|
||||||
watch: {
|
this.usersToFollow.forEach((toFollow) => {
|
||||||
user: function () {
|
toFollow.name = 'Loading...'
|
||||||
if (this.suggestionsEnabled) {
|
})
|
||||||
getWhoToFollow()
|
|
||||||
}
|
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(() => ({
|
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()
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue