refs #10 Display domain name in sidemenu
This commit is contained in:
parent
2f5b993014
commit
773a58d0bb
@ -15,25 +15,6 @@ export default class Account {
|
||||
})
|
||||
}
|
||||
|
||||
getInstance (id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.db.findOne(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
(err, doc) => {
|
||||
if (err) return reject(err)
|
||||
if (empty(doc)) return reject(new EmptyRecordError('empty'))
|
||||
const instance = {
|
||||
baseURL: doc.baseURL,
|
||||
id: doc._id
|
||||
}
|
||||
resolve(instance)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
getAccount (id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.db.findOne(
|
||||
|
@ -115,25 +115,14 @@ ipcMain.on('list-accounts', (event, _) => {
|
||||
})
|
||||
})
|
||||
|
||||
ipcMain.on('get-instance', (event, id) => {
|
||||
const account = new Account(db)
|
||||
account.getInstance(id)
|
||||
.catch((err) => {
|
||||
event.sender.send('error-get-instance', err)
|
||||
})
|
||||
.then((instance) => {
|
||||
event.sender.send('response-get-instance', instance)
|
||||
})
|
||||
})
|
||||
|
||||
ipcMain.on('get-local-account', (event, id) => {
|
||||
const account = new Account(db)
|
||||
account.getAccount(id)
|
||||
.catch((err) => {
|
||||
event.sender.send('error-get-local-account', err)
|
||||
})
|
||||
.then((token) => {
|
||||
event.sender.send('response-get-local-account', token)
|
||||
.then((account) => {
|
||||
event.sender.send('response-get-local-account', account)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
active-text-color="#ffffff">
|
||||
<el-menu-item :index="index.toString()" v-for="(account, index) in accounts" v-bind:key="account.id" :route="{path: `/${account.id}/home`}">
|
||||
<i class="el-icon-menu"></i>
|
||||
<span slot="title">{{ account.baseURL }}</span>
|
||||
<span slot="title">{{ account.domain }}</span>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
<div class="space">
|
||||
|
@ -3,7 +3,7 @@
|
||||
<div class="profile-wrapper">
|
||||
<div class="profile">
|
||||
<span>@{{ username }}</span>
|
||||
<span>{{ instance.baseURL }}</span>
|
||||
<span>{{ account.domain }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<el-menu
|
||||
@ -44,13 +44,21 @@ export default {
|
||||
name: 'side-menu',
|
||||
computed: {
|
||||
...mapState({
|
||||
instance: state => state.TimelineSpace.SideMenu.instance,
|
||||
account: state => state.TimelineSpace.SideMenu.account,
|
||||
username: state => state.TimelineSpace.SideMenu.username
|
||||
})
|
||||
},
|
||||
created () {
|
||||
this.$store.dispatch('TimelineSpace/SideMenu/fetchInstance', this.$route.params.id)
|
||||
this.$store.dispatch('TimelineSpace/SideMenu/username', this.$route.params.id)
|
||||
this.$store.dispatch('TimelineSpace/SideMenu/fetchAccount', this.$route.params.id)
|
||||
.then((account) => {
|
||||
this.$store.dispatch('TimelineSpace/SideMenu/username', account)
|
||||
})
|
||||
.catch(() => {
|
||||
this.$message({
|
||||
message: 'Could not find account',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
id () {
|
||||
|
@ -4,51 +4,49 @@ import Mastodon from 'mastodon-api'
|
||||
const SideMenu = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
instance: {
|
||||
baseURL: '',
|
||||
account: {
|
||||
domain: '',
|
||||
id: ''
|
||||
},
|
||||
username: ''
|
||||
},
|
||||
mutations: {
|
||||
updateInstance (state, instance) {
|
||||
state.instance = instance
|
||||
updateAccount (state, account) {
|
||||
state.account = account
|
||||
},
|
||||
updateUsername (state, body) {
|
||||
state.username = body.username
|
||||
updateUsername (state, username) {
|
||||
state.username = username
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
fetchInstance ({ commit }, id) {
|
||||
ipcRenderer.send('get-instance', id)
|
||||
ipcRenderer.once('error-get-instance', (event, err) => {
|
||||
// TODO: handle error
|
||||
console.log(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-instance', (event, instance) => {
|
||||
commit('updateInstance', instance)
|
||||
})
|
||||
},
|
||||
username ({ commit }, id) {
|
||||
fetchAccount ({ commit }, id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('get-local-account', id)
|
||||
ipcRenderer.once('error-get-local-account', (event, err) => {
|
||||
// TODO: handle error
|
||||
console.log(err)
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-local-account', (event, account) => {
|
||||
const client = new Mastodon(
|
||||
{
|
||||
access_token: account.accessToken,
|
||||
api_url: account.baseURL + '/api/v1'
|
||||
|
||||
})
|
||||
client.get('/accounts/verify_credentials', {})
|
||||
.then((res) => {
|
||||
commit('updateUsername', res.data)
|
||||
resolve(res)
|
||||
})
|
||||
commit('updateAccount', account)
|
||||
resolve(account)
|
||||
})
|
||||
})
|
||||
},
|
||||
username ({ commit }, account) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const client = new Mastodon(
|
||||
{
|
||||
access_token: account.accessToken,
|
||||
api_url: account.baseURL + '/api/v1'
|
||||
|
||||
})
|
||||
client.get('/accounts/verify_credentials', {})
|
||||
.then((res) => {
|
||||
commit('updateUsername', res.data.username)
|
||||
resolve(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user