gancio/components/FollowMe.vue

76 lines
1.9 KiB
Vue
Raw Normal View History

2020-02-10 00:45:51 +01:00
<template lang='pug'>
2021-03-05 14:11:33 +01:00
v-card
2020-09-05 01:21:47 +02:00
v-card-title(v-text="$t('common.follow_me_title')")
v-card-text
p(v-html="$t('event.follow_me_description', { title: settings.title, account: `@${settings.instance_name}@${domain}`})")
v-text-field(
2020-10-09 00:39:54 +02:00
:rules="[$validators.required('common.url')]"
2020-09-05 01:21:47 +02:00
:label="$t('common.url')"
v-model='instance_hostname')
p <img class='instance_thumb' :src="instance.thumbnail"/> {{instance.title}}
2020-10-07 13:04:28 +02:00
2020-09-05 01:21:47 +02:00
v-card-actions
v-spacer
2020-10-09 00:39:54 +02:00
v-btn(color='warning' @click="$emit('close')") {{$t("common.cancel")}}
2020-09-05 01:21:47 +02:00
v-btn(:disabled='(!couldGo || !proceed)'
2020-10-07 13:04:28 +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 url from 'url'
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 {
instance_hostname: '',
proceed: false,
instance: {},
2020-09-05 01:21:47 +02:00
loading: false,
2020-02-10 00:45:51 +01:00
get_instance_info: debounce(this.getInstanceInfo, 500)
}
},
computed: {
...mapState(['settings']),
domain () {
const URL = url.parse(this.settings.baseurl)
return URL.hostname
},
couldGo () {
// check if is mastodon
this.get_instance_info()
return true
},
link () {
// check if exists
return `https://${this.instance_hostname}/authorize_interaction?uri=${this.settings.instance_name}@${this.domain}`
}
},
methods: {
getInstanceInfo () {
2020-02-20 20:55:06 +01:00
if (!this.instance_hostname) {
return
}
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
})
.catch(e => {
this.proceed = false
})
}
}
}
</script>
<style lang="less">
.instance_thumb {
height: 20px;
}
</style>