remove unneeded numbered variables who_to_follow
This commit is contained in:
parent
e59b67e119
commit
6fa993c122
2 changed files with 38 additions and 69 deletions
|
@ -2,62 +2,31 @@ import apiService from '../../services/api/api.service.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) {
|
function showWhoToFollow (panel, reply) {
|
||||||
var users = reply
|
panel.usersToFollow.forEach((toFollow, index) => {
|
||||||
var cn
|
let randIndex = Math.floor(Math.random() * reply.length)
|
||||||
var index
|
let user = reply[randIndex]
|
||||||
var step = 7
|
let img = user.avatar || '/images/avi.png'
|
||||||
cn = Math.floor(Math.random() * step)
|
let name = user.acct
|
||||||
for (index = 0; index < 3; index++) {
|
|
||||||
var user
|
toFollow.img = img
|
||||||
user = users[cn]
|
toFollow.name = name
|
||||||
var img
|
|
||||||
if (user.avatar) {
|
|
||||||
img = user.avatar
|
|
||||||
} else {
|
|
||||||
img = '/images/avi.png'
|
|
||||||
}
|
|
||||||
var name = user.acct
|
|
||||||
if (index === 0) {
|
|
||||||
panel.img1 = img
|
|
||||||
panel.name1 = name
|
|
||||||
panel.$store.state.api.backendInteractor.externalProfile(name)
|
panel.$store.state.api.backendInteractor.externalProfile(name)
|
||||||
.then((externalUser) => {
|
.then((externalUser) => {
|
||||||
if (!externalUser.error) {
|
if (!externalUser.error) {
|
||||||
panel.$store.commit('addNewUsers', [externalUser])
|
panel.$store.commit('addNewUsers', [externalUser])
|
||||||
panel.id1 = externalUser.id
|
toFollow.id = externalUser.id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (index === 1) {
|
|
||||||
panel.img2 = img
|
|
||||||
panel.name2 = name
|
|
||||||
panel.$store.state.api.backendInteractor.externalProfile(name)
|
|
||||||
.then((externalUser) => {
|
|
||||||
if (!externalUser.error) {
|
|
||||||
panel.$store.commit('addNewUsers', [externalUser])
|
|
||||||
panel.id2 = externalUser.id
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else if (index === 2) {
|
|
||||||
panel.img3 = img
|
|
||||||
panel.name3 = name
|
|
||||||
panel.$store.state.api.backendInteractor.externalProfile(name)
|
|
||||||
.then((externalUser) => {
|
|
||||||
if (!externalUser.error) {
|
|
||||||
panel.$store.commit('addNewUsers', [externalUser])
|
|
||||||
panel.id3 = externalUser.id
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
cn = (cn + step) % users.length
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWhoToFollow (panel) {
|
function getWhoToFollow (panel) {
|
||||||
var credentials = panel.$store.state.users.currentUser.credentials
|
var credentials = panel.$store.state.users.currentUser.credentials
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
panel.name1 = 'Loading...'
|
panel.usersToFollow.forEach((_, index) => {
|
||||||
panel.name2 = 'Loading...'
|
panel.usersToFollow[index].name = 'Loading...'
|
||||||
panel.name3 = 'Loading...'
|
})
|
||||||
apiService.suggestions({credentials: credentials})
|
apiService.suggestions({credentials: credentials})
|
||||||
.then((reply) => {
|
.then((reply) => {
|
||||||
showWhoToFollow(panel, reply)
|
showWhoToFollow(panel, reply)
|
||||||
|
@ -67,27 +36,24 @@ function getWhoToFollow (panel) {
|
||||||
|
|
||||||
const WhoToFollowPanel = {
|
const WhoToFollowPanel = {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
img1: '/images/avi.png',
|
usersToFollow: new Array(3).fill().map(x => (
|
||||||
name1: '',
|
{
|
||||||
id1: 0,
|
img: '/images/avi.png',
|
||||||
img2: '/images/avi.png',
|
name: '',
|
||||||
name2: '',
|
id: 0
|
||||||
id2: 0,
|
}
|
||||||
img3: '/images/avi.png',
|
))
|
||||||
name3: '',
|
|
||||||
id3: 0
|
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
user: function () {
|
user: function () {
|
||||||
return this.$store.state.users.currentUser.screen_name
|
return this.$store.state.users.currentUser.screen_name
|
||||||
},
|
},
|
||||||
moreUrl: function () {
|
moreUrl: function () {
|
||||||
var host = window.location.hostname
|
let host = window.location.hostname
|
||||||
var user = this.user
|
let user = this.user
|
||||||
var suggestionsWeb = this.$store.state.instance.suggestionsWeb
|
let suggestionsWeb = this.$store.state.instance.suggestionsWeb
|
||||||
var url
|
let url = suggestionsWeb.replace(/{{host}}/g, encodeURIComponent(host))
|
||||||
url = suggestionsWeb.replace(/{{host}}/g, encodeURIComponent(host))
|
.replace(/{{user}}/g, encodeURIComponent(user))
|
||||||
url = url.replace(/{{user}}/g, encodeURIComponent(user))
|
|
||||||
return url
|
return url
|
||||||
},
|
},
|
||||||
suggestionsEnabled () {
|
suggestionsEnabled () {
|
||||||
|
|
|
@ -8,9 +8,12 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body who-to-follow">
|
<div class="panel-body who-to-follow">
|
||||||
<p>
|
<p>
|
||||||
<img v-bind:src="img1"/> <router-link :to="userProfileLink(id1, name1)">{{ name1 }}</router-link><br>
|
<span v-for="user in usersToFollow">
|
||||||
<img v-bind:src="img2"/> <router-link :to="userProfileLink(id2, name2)">{{ name2 }}</router-link><br>
|
<img v-bind:src="user.img" />
|
||||||
<img v-bind:src="img3"/> <router-link :to="userProfileLink(id3, name3)">{{ name3 }}</router-link><br>
|
<router-link v-bind:to="userProfileLink(user.id, user.name)">
|
||||||
|
{{user.name}}
|
||||||
|
</router-link><br />
|
||||||
|
</span>
|
||||||
<img v-bind:src="$store.state.instance.logo"> <a v-bind:href="moreUrl" target="_blank">{{$t('who_to_follow.more')}}</a>
|
<img v-bind:src="$store.state.instance.logo"> <a v-bind:href="moreUrl" target="_blank">{{$t('who_to_follow.more')}}</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue