refs #6 Call account in timeline space store
This commit is contained in:
parent
9c695b2b72
commit
e15d8706ae
|
@ -14,7 +14,16 @@ export default {
|
|||
name: 'timeline-space',
|
||||
components: { SideMenu },
|
||||
created () {
|
||||
console.log(this.$route.params.id)
|
||||
this.$store.dispatch('TimelineSpace/fetchAccount', this.$route.params.id)
|
||||
.then((account) => {
|
||||
this.$store.dispatch('TimelineSpace/username', account)
|
||||
})
|
||||
.catch(() => {
|
||||
this.$message({
|
||||
message: 'Could not find account',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -44,22 +44,10 @@ export default {
|
|||
name: 'side-menu',
|
||||
computed: {
|
||||
...mapState({
|
||||
account: state => state.TimelineSpace.SideMenu.account,
|
||||
username: state => state.TimelineSpace.SideMenu.username
|
||||
account: state => state.TimelineSpace.account,
|
||||
username: state => state.TimelineSpace.username
|
||||
})
|
||||
},
|
||||
created () {
|
||||
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 () {
|
||||
return this.$route.params.id
|
||||
|
|
|
@ -19,7 +19,6 @@ const GlobalHeader = {
|
|||
})
|
||||
ipcRenderer.once('response-list-accounts', (event, accounts) => {
|
||||
commit('updateAccounts', accounts)
|
||||
console.log(accounts)
|
||||
resolve(accounts)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,9 +1,57 @@
|
|||
import { ipcRenderer } from 'electron'
|
||||
import Mastodon from 'mastodon-api'
|
||||
import SideMenu from './TimelineSpace/SideMenu'
|
||||
|
||||
const TimelineSpace = {
|
||||
namespaced: true,
|
||||
modules: {
|
||||
SideMenu
|
||||
},
|
||||
state: {
|
||||
account: {
|
||||
domain: '',
|
||||
id: ''
|
||||
},
|
||||
username: ''
|
||||
},
|
||||
mutations: {
|
||||
updateAccount (state, account) {
|
||||
state.account = account
|
||||
},
|
||||
updateUsername (state, username) {
|
||||
state.username = username
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
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) => {
|
||||
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)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,54 +1,8 @@
|
|||
import { ipcRenderer } from 'electron'
|
||||
import Mastodon from 'mastodon-api'
|
||||
|
||||
const SideMenu = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
account: {
|
||||
domain: '',
|
||||
id: ''
|
||||
},
|
||||
username: ''
|
||||
},
|
||||
mutations: {
|
||||
updateAccount (state, account) {
|
||||
state.account = account
|
||||
},
|
||||
updateUsername (state, username) {
|
||||
state.username = username
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
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) => {
|
||||
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)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
state: {},
|
||||
mutations: {},
|
||||
actions: {}
|
||||
}
|
||||
|
||||
export default SideMenu
|
||||
|
|
Loading…
Reference in New Issue