forked from AkkomaGang/akkoma-fe
Add generateProfileLink
This commit is contained in:
parent
ae8f0f36d8
commit
24caa2cfcd
4 changed files with 31 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
|
||||
|
||||
const chatPanel = {
|
||||
data () {
|
||||
return {
|
||||
|
@ -9,6 +11,9 @@ const chatPanel = {
|
|||
computed: {
|
||||
messages () {
|
||||
return this.$store.state.chat.messages
|
||||
},
|
||||
userProfileLink (user) {
|
||||
return generateProfileLink(user, user.name)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<img :src="message.author.avatar" />
|
||||
</span>
|
||||
<div class="chat-content">
|
||||
<router-link class="chat-name" :to="{ name: 'user-profile', params: { name: message.author.username } }">
|
||||
<router-link class="chat-name" :to="userProfileLink(message.author)">
|
||||
{{message.author.username}}
|
||||
</router-link>
|
||||
<br>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
const generateProfileLink = (user, name = '') => {
|
||||
const baseLinkParams = { name: 'user-profile' }
|
||||
const { id } = user
|
||||
|
||||
return { ...baseLinkParams, params: (isExternal(user) ? { id } : { name }) }
|
||||
}
|
||||
|
||||
const isExternal = ({screen_name}) => (screen_name.indexOf('@') > 0)
|
||||
|
||||
export default generateProfileLink
|
|
@ -0,0 +1,15 @@
|
|||
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
|
||||
|
||||
describe('generateProfileLink', () => {
|
||||
it('returns obj for local user', () => {
|
||||
const user = { screen_name: 'john' }
|
||||
|
||||
expect(generateProfileLink(user, 'jack')).to.eql({ name: 'user-profile', params: { name: 'jack' } })
|
||||
})
|
||||
|
||||
it('returns obj for external user', () => {
|
||||
const user = { screen_name: 'john@domain', id: 1 }
|
||||
|
||||
expect(generateProfileLink(user)).to.eql({ name: 'user-profile', params: { id: 1 } })
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue