gancio-upstream/components/FollowMe.vue

87 lines
2.5 KiB
Vue
Raw Normal View History

2020-02-10 00:45:51 +01:00
<template lang='pug'>
2022-07-01 15:55:09 +02:00
v-card
v-card-title(v-text="$t('common.follow_me_title')")
v-card-text
v-alert(type='warning' border='left' :icon='mdiInformation') {{$t('admin.stats', stats)}}
2022-07-01 15:55:09 +02:00
p(v-html="$t('event.follow_me_description', { title: settings.title, account: `@${settings.instance_name}@${settings.hostname}`})")
v-text-field(
:rules="[$validators.required('common.url')]"
:loading='loading'
:label="$t('common.url')"
v-model='instance_hostname')
v-btn(v-if='!isDialog' slot='prepend' text :disabled='(!couldGo || !proceed)' :href='link' target='_blank'
:loading='loading' color="primary") {{$t("common.follow")}}
2020-10-07 13:04:28 +02:00
2022-07-01 15:55:09 +02:00
p(slot='append') <img class='instance_thumb' :src="instance.thumbnail"/> {{instance.title}}
2021-05-19 16:17:48 +02:00
2022-07-01 15:55:09 +02:00
v-card-actions(v-if='isDialog')
v-spacer
v-btn(v-if='isDialog' outlined color='warning' @click="$emit('close')") {{$t("common.cancel")}}
v-btn(:disabled='(!couldGo || !proceed)' outlined :href='link' target='_blank'
2022-07-01 15:55:09 +02:00
:loading='loading' color="primary") {{$t("common.follow")}}
2020-02-10 00:45:51 +01:00
</template>
<script>
import { mapState } from 'vuex'
import debounce from 'lodash/debounce'
import { mdiInformation } from '@mdi/js'
2020-02-10 00:45:51 +01:00
export default {
name: 'FollowMe',
2020-11-13 00:13:44 +01:00
props:
{ isDialog: { type: Boolean, default: false } },
2020-02-10 00:45:51 +01:00
data () {
return {
mdiInformation,
2020-02-10 00:45:51 +01:00
instance_hostname: '',
proceed: false,
instance: {},
stats: {},
2020-09-05 01:21:47 +02:00
loading: false,
2021-05-19 16:17:48 +02:00
get_instance_info: debounce(this.getInstanceInfo, 300)
2020-02-10 00:45:51 +01:00
}
},
async fetch () {
this.stats = await this.$axios.$get('/instances/stats')
},
2020-02-10 00:45:51 +01:00
computed: {
...mapState(['settings']),
couldGo () {
// check if is mastodon
2021-05-19 16:17:48 +02:00
this.get_instance_info(this.instance_hostname)
2020-02-10 00:45:51 +01:00
return true
},
link () {
// check if exists
2021-10-18 11:25:39 +02:00
return `https://${this.instance_hostname}/authorize_interaction?uri=${this.settings.instance_name}@${this.settings.hostname}`
2020-02-10 00:45:51 +01:00
}
},
methods: {
getInstanceInfo () {
2020-02-20 20:55:06 +01:00
if (!this.instance_hostname) {
return
}
2021-05-19 16:17:48 +02:00
this.loading = true
2020-02-10 00:45:51 +01:00
const instance_url = `https://${this.instance_hostname}/api/v1/instance`
this.$axios.$get(instance_url)
.then(ret => {
this.instance = ret
this.proceed = true
2021-05-19 16:17:48 +02:00
this.loading = false
2020-02-10 00:45:51 +01:00
})
.catch(e => {
2021-05-19 16:17:48 +02:00
this.instance = {}
2020-02-10 00:45:51 +01:00
this.proceed = false
2021-05-19 16:17:48 +02:00
this.loading = false
2020-02-10 00:45:51 +01:00
})
}
}
}
</script>
2021-10-18 11:25:39 +02:00
<style>
2020-02-10 00:45:51 +01:00
.instance_thumb {
height: 20px;
}
</style>