aboutsummaryrefslogtreecommitdiff
path: root/src/components/who_to_follow_panel
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/who_to_follow_panel')
-rw-r--r--src/components/who_to_follow_panel/who_to_follow_panel.js111
-rw-r--r--src/components/who_to_follow_panel/who_to_follow_panel.vue37
2 files changed, 148 insertions, 0 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
new file mode 100644
index 00000000..49b8f5b6
--- /dev/null
+++ b/src/components/who_to_follow_panel/who_to_follow_panel.js
@@ -0,0 +1,111 @@
+import apiService from '../../services/api/api.service.js'
+
+function showWhoToFollow (panel, reply) {
+ var users = reply
+ var cn
+ var index
+ var step = 7
+ cn = Math.floor(Math.random() * step)
+ for (index = 0; index < 3; index++) {
+ var user
+ user = users[cn]
+ 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)
+ .then((externalUser) => {
+ if (!externalUser.error) {
+ panel.$store.commit('addNewUsers', [externalUser])
+ panel.id1 = 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) {
+ var credentials = panel.$store.state.users.currentUser.credentials
+ if (credentials) {
+ panel.name1 = 'Loading...'
+ panel.name2 = 'Loading...'
+ panel.name3 = 'Loading...'
+ apiService.suggestions({credentials: credentials})
+ .then((reply) => {
+ showWhoToFollow(panel, reply)
+ })
+ }
+}
+
+const WhoToFollowPanel = {
+ data: () => ({
+ img1: '/images/avi.png',
+ name1: '',
+ id1: 0,
+ img2: '/images/avi.png',
+ name2: '',
+ id2: 0,
+ img3: '/images/avi.png',
+ name3: '',
+ id3: 0
+ }),
+ computed: {
+ user: function () {
+ return this.$store.state.users.currentUser.screen_name
+ },
+ moreUrl: function () {
+ var host = window.location.hostname
+ var user = this.user
+ var suggestionsWeb = this.$store.state.instance.suggestionsWeb
+ var url
+ url = suggestionsWeb.replace(/{{host}}/g, encodeURIComponent(host))
+ url = url.replace(/{{user}}/g, encodeURIComponent(user))
+ return url
+ },
+ suggestionsEnabled () {
+ return this.$store.state.instance.suggestionsEnabled
+ }
+ },
+ watch: {
+ user: function (user, oldUser) {
+ if (this.suggestionsEnabled) {
+ getWhoToFollow(this)
+ }
+ }
+ },
+ mounted:
+ function () {
+ if (this.suggestionsEnabled) {
+ getWhoToFollow(this)
+ }
+ }
+}
+
+export default WhoToFollowPanel
diff --git a/src/components/who_to_follow_panel/who_to_follow_panel.vue b/src/components/who_to_follow_panel/who_to_follow_panel.vue
new file mode 100644
index 00000000..d031318d
--- /dev/null
+++ b/src/components/who_to_follow_panel/who_to_follow_panel.vue
@@ -0,0 +1,37 @@
+<template>
+ <div class="who-to-follow-panel">
+ <div class="panel panel-default base01-background">
+ <div class="panel-heading timeline-heading base02-background base04">
+ <div class="title">
+ {{$t('who_to_follow.who_to_follow')}}
+ </div>
+ </div>
+ <div class="panel-body who-to-follow">
+ <p>
+ <img v-bind:src="img1"/> <router-link :to="{ name: 'user-profile', params: { id: id1 } }">{{ name1 }}</router-link><br>
+ <img v-bind:src="img2"/> <router-link :to="{ name: 'user-profile', params: { id: id2 } }">{{ name2 }}</router-link><br>
+ <img v-bind:src="img3"/> <router-link :to="{ name: 'user-profile', params: { id: id3 } }">{{ name3 }}</router-link><br>
+ <img v-bind:src="$store.state.instance.logo"> <a v-bind:href="moreUrl" target="_blank">{{$t('who_to_follow.more')}}</a>
+ </p>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script src="./who_to_follow_panel.js" ></script>
+
+<style lang="scss">
+ .who-to-follow * {
+ vertical-align: middle;
+ }
+ .who-to-follow img {
+ width: 32px;
+ height: 32px;
+ }
+ .who-to-follow p {
+ line-height: 40px;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+</style>