Merge pull request #15 from h3poteto/iss-11

closes #11 Show username in sidemneu
This commit is contained in:
AkiraFukushima 2018-03-09 17:37:57 +09:00 committed by GitHub
commit a7a7ce56a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 8 deletions

View File

@ -36,6 +36,21 @@ export default class Account {
)
})
}
getAccount (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'))
resolve(doc)
}
)
})
}
}
class EmptyRecordError {

View File

@ -125,6 +125,17 @@ ipcMain.on('get-instance', (event, id) => {
})
})
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)
})
})
/**
* Auto Updater
*

View File

@ -22,6 +22,6 @@ export default {
<style lang="scss" scoped>
.content {
margin-left: 145px;
margin-left: 180px;
}
</style>

View File

@ -2,7 +2,8 @@
<div id="side_menu">
<div class="profile-wrapper">
<div class="profile">
{{ instance.baseURL }}
<span>@{{ username }}</span>
<span>{{ instance.baseURL }}</span>
</div>
</div>
<el-menu
@ -43,11 +44,13 @@ export default {
name: 'side-menu',
computed: {
...mapState({
instance: state => state.TimelineSpace.SideMenu.instance
instance: state => state.TimelineSpace.SideMenu.instance,
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)
},
methods: {
id () {
@ -64,8 +67,8 @@ export default {
position: fixed;
top: 0;
left: 65px;
width: 144px;
height: 40px;
width: 180px;
height: 60px;
.profile {
color: #ffffff;
@ -76,10 +79,10 @@ export default {
.timeline-menu {
position: fixed;
top: 40px;
top: 60px;
left: 65px;
height: 100%;
width: 144px;
width: 180px;
}
}
</style>

View File

@ -1,4 +1,5 @@
import { ipcRenderer } from 'electron'
import Mastodon from 'mastodon-api'
const SideMenu = {
namespaced: true,
@ -6,11 +7,15 @@ const SideMenu = {
instance: {
baseURL: '',
id: ''
}
},
username: ''
},
mutations: {
updateInstance (state, instance) {
state.instance = instance
},
updateUsername (state, body) {
state.username = body.username
}
},
actions: {
@ -23,6 +28,27 @@ const SideMenu = {
ipcRenderer.on('response-get-instance', (event, instance) => {
commit('updateInstance', instance)
})
},
username ({ commit }, id) {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-local-account', id)
ipcRenderer.on('error-get-local-account', (event, err) => {
reject(err)
})
ipcRenderer.on('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)
})
})
})
}
}
}