refs #363 Open account profile when click account name in toot
This commit is contained in:
parent
192735d525
commit
e4a6eae40e
|
@ -100,7 +100,7 @@
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { shell, clipboard } from 'electron'
|
import { shell, clipboard } from 'electron'
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import { findLink, isTag } from '../../../utils/link'
|
import { findAccount, findLink, isTag } from '../../../utils/link'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'toot',
|
name: 'toot',
|
||||||
|
@ -161,6 +161,23 @@ export default {
|
||||||
this.$router.push({ path: tag })
|
this.$router.push({ path: tag })
|
||||||
return tag
|
return tag
|
||||||
}
|
}
|
||||||
|
const accountURL = findAccount(e.target)
|
||||||
|
if (accountURL !== null) {
|
||||||
|
this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', true)
|
||||||
|
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/searchAccount', accountURL)
|
||||||
|
.then((account) => {
|
||||||
|
this.$store.dispatch('TimelineSpace/Contents/SideBar/openAccountComponent')
|
||||||
|
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/changeAccount', account)
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.$message({
|
||||||
|
message: 'Account not found',
|
||||||
|
type: 'error'
|
||||||
|
})
|
||||||
|
this.$store.commit('TimelineSpace/Contents/SideBar/changeOpenSideBar', false)
|
||||||
|
})
|
||||||
|
return accountURL
|
||||||
|
}
|
||||||
const link = findLink(e.target)
|
const link = findLink(e.target)
|
||||||
if (link !== null) {
|
if (link !== null) {
|
||||||
return shell.openExternal(link)
|
return shell.openExternal(link)
|
||||||
|
|
|
@ -8,6 +8,14 @@
|
||||||
<div id="sidebar_scrollable">
|
<div id="sidebar_scrollable">
|
||||||
<account-profile v-if="component === 1" v-on:change-loading="changeLoading"></account-profile>
|
<account-profile v-if="component === 1" v-on:change-loading="changeLoading"></account-profile>
|
||||||
<toot-detail v-if="component === 2"></toot-detail>
|
<toot-detail v-if="component === 2"></toot-detail>
|
||||||
|
<div
|
||||||
|
class="loading"
|
||||||
|
v-loading="true"
|
||||||
|
element-loading-text="Loading..."
|
||||||
|
element-loading-spinner="el-icon-loading"
|
||||||
|
:element-loading-background="backgroundColor"
|
||||||
|
v-else>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
|
@ -32,7 +40,8 @@ export default {
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar,
|
openSideBar: state => state.TimelineSpace.Contents.SideBar.openSideBar,
|
||||||
component: state => state.TimelineSpace.Contents.SideBar.component
|
component: state => state.TimelineSpace.Contents.SideBar.component,
|
||||||
|
backgroundColor: state => state.App.theme.background_color
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
|
@ -76,6 +85,10 @@ export default {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
height: calc(100% - 30px);
|
height: calc(100% - 30px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loading {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.slide-detail-enter-active, .slide-detail-leave-active {
|
.slide-detail-enter-active, .slide-detail-leave-active {
|
||||||
|
|
|
@ -31,7 +31,7 @@ export default {
|
||||||
load () {
|
load () {
|
||||||
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchFollowers', this.account)
|
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchFollowers', this.account)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.message({
|
this.$message({
|
||||||
message: 'Could not get followers',
|
message: 'Could not get followers',
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
|
|
|
@ -31,7 +31,7 @@ export default {
|
||||||
load () {
|
load () {
|
||||||
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchFollows', this.account)
|
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchFollows', this.account)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.message({
|
this.$message({
|
||||||
message: 'Could not get follows',
|
message: 'Could not get follows',
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
|
|
|
@ -23,3 +23,16 @@ export function isTag (target) {
|
||||||
}
|
}
|
||||||
return isTag(target.parentNode)
|
return isTag(target.parentNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function findAccount (target) {
|
||||||
|
if (target.getAttribute('class') && target.getAttribute('class').includes('u-url')) {
|
||||||
|
return target.href
|
||||||
|
}
|
||||||
|
if (target.parentNode === undefined || target.parentNode === null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (target.parentNode.getAttribute('class') === 'toot') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return findAccount(target.parentNode)
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,21 @@ const AccountProfile = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
searchAccount ({ commit, rootState }, accountURL) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const client = new Mastodon(
|
||||||
|
{
|
||||||
|
access_token: rootState.TimelineSpace.account.accessToken,
|
||||||
|
api_url: rootState.TimelineSpace.account.baseURL + '/api/v1'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
client.get('/search', { q: accountURL }, (err, data, res) => {
|
||||||
|
if (err) return reject(err)
|
||||||
|
if (data.accounts.length <= 0) return reject(new AccountNotFound('not found'))
|
||||||
|
resolve(data.accounts[0])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
changeAccount ({ commit, dispatch }, account) {
|
changeAccount ({ commit, dispatch }, account) {
|
||||||
dispatch('fetchRelationship', account)
|
dispatch('fetchRelationship', account)
|
||||||
commit('changeAccount', account)
|
commit('changeAccount', account)
|
||||||
|
@ -84,4 +99,10 @@ const AccountProfile = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AccountNotFound {
|
||||||
|
constructor (msg) {
|
||||||
|
this.msg = msg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default AccountProfile
|
export default AccountProfile
|
||||||
|
|
Loading…
Reference in New Issue