aboutsummaryrefslogtreecommitdiff
path: root/src/components/who_to_follow/who_to_follow.js
blob: 1aa3a4cdcc897e23f08f228089402292ffba6f3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import apiService from '../../services/api/api.service.js'
import FollowCard from '../follow_card/follow_card.vue'

const WhoToFollow = {
  components: {
    FollowCard
  },
  data () {
    return {
      users: []
    }
  },
  mounted () {
    this.getWhoToFollow()
  },
  methods: {
    showWhoToFollow (reply) {
      reply.forEach((i, index) => {
        const user = {
          id: 0,
          name: i.display_name,
          screen_name: i.acct,
          profile_image_url: i.avatar || '/images/avi.png',
          profile_image_url_original: i.avatar || '/images/avi.png',
          statusnet_profile_url: i.url
        }
        this.users.push(user)

        this.$store.state.api.backendInteractor.fetchUser({ id: user.screen_name })
          .then((externalUser) => {
            if (!externalUser.error) {
              this.$store.commit('addNewUsers', [externalUser])
              user.id = externalUser.id
            }
          })
      })
    },
    getWhoToFollow () {
      const credentials = this.$store.state.users.currentUser.credentials
      if (credentials) {
        apiService.suggestions({ credentials: credentials })
          .then((reply) => {
            this.showWhoToFollow(reply)
          })
      }
    }
  }
}

export default WhoToFollow