mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Merge pull request #4047 from Ocelot-Social-Community/3505-display-social-media-favicons-on-profile
feat: 🔥 Displaying Social Media Favicons On Profile Page
This commit is contained in:
commit
cc9c70dbe7
97
webapp/components/SocialMedia/SocialMedia.spec.js
Normal file
97
webapp/components/SocialMedia/SocialMedia.spec.js
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
import { config, mount } from '@vue/test-utils'
|
||||||
|
import SocialMedia from './SocialMedia.vue'
|
||||||
|
|
||||||
|
config.stubs['ds-space'] = '<span><slot /></span>'
|
||||||
|
config.stubs['ds-text'] = '<span><slot /></span>'
|
||||||
|
|
||||||
|
describe('SocialMedia.vue', () => {
|
||||||
|
let propsData
|
||||||
|
let mocks
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
propsData = {}
|
||||||
|
|
||||||
|
mocks = {
|
||||||
|
$t: jest.fn(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mount', () => {
|
||||||
|
const Wrapper = () => {
|
||||||
|
return mount(SocialMedia, { propsData, mocks })
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('socialMedia card title', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
propsData.userName = 'Jenny Rostock'
|
||||||
|
propsData.user = {
|
||||||
|
socialMedia: [
|
||||||
|
{
|
||||||
|
id: 'ee1e8ed6-fbef-4bcf-b411-a12926f2ea1e',
|
||||||
|
url: 'https://www.instagram.com/nimitbhargava',
|
||||||
|
__typename: 'SocialMedia',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders socialMedia card title', () => {
|
||||||
|
Wrapper()
|
||||||
|
expect(mocks.$t).toHaveBeenCalledWith('profile.socialMedia')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('socialMedia links', () => {
|
||||||
|
let wrapper
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
propsData.userName = 'Jenny Rostock'
|
||||||
|
propsData.user = {
|
||||||
|
socialMedia: [
|
||||||
|
{
|
||||||
|
id: 'ee1e8ed6-fbef-4bcf-b411-a12926f2ea1e',
|
||||||
|
url: 'https://www.instagram.com/nimitbhargava',
|
||||||
|
__typename: 'SocialMedia',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'dc91aecb-3289-47d0-8770-4b24eb24fd9c',
|
||||||
|
url: 'https://www.facebook.com/NimitBhargava',
|
||||||
|
__typename: 'SocialMedia',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'db1dc400-9303-4b43-9451-87dcac13b913',
|
||||||
|
url: 'https://www.youtube.com/channel/UCu3GiKBFn5I07V9hBxF2CRA',
|
||||||
|
__typename: 'SocialMedia',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
// Now assign wrapper
|
||||||
|
wrapper = Wrapper()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows 3 social media links', () => {
|
||||||
|
expect(wrapper.findAll('a')).toHaveLength(3)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders a social media link', () => {
|
||||||
|
const link = wrapper.findAll('a').at(0)
|
||||||
|
expect(link.attributes('href')).toEqual('https://www.instagram.com/nimitbhargava')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows the first favicon', () => {
|
||||||
|
const favicon = wrapper.findAll('a').at(0).find('img')
|
||||||
|
expect(favicon.attributes('src')).toEqual('https://www.instagram.com/favicon.ico')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows the second favicon', () => {
|
||||||
|
const favicon = wrapper.findAll('a').at(1).find('img')
|
||||||
|
expect(favicon.attributes('src')).toEqual('https://www.facebook.com/favicon.ico')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows the last favicon', () => {
|
||||||
|
const favicon = wrapper.findAll('a').at(-1).find('img')
|
||||||
|
expect(favicon.attributes('src')).toEqual('https://www.youtube.com/favicon.ico')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
49
webapp/components/SocialMedia/SocialMedia.vue
Normal file
49
webapp/components/SocialMedia/SocialMedia.vue
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<template>
|
||||||
|
<ds-space v-if="user.socialMedia && user.socialMedia.length" margin="large">
|
||||||
|
<base-card class="social-media-bc">
|
||||||
|
<ds-space margin="x-small">
|
||||||
|
<ds-text tag="h5" color="soft">
|
||||||
|
{{ $t('profile.socialMedia') }} {{ userName | truncate(15) }}?
|
||||||
|
</ds-text>
|
||||||
|
<template>
|
||||||
|
<ds-space v-for="link in socialMediaLinks()" :key="link.id" margin="x-small">
|
||||||
|
<a :href="link.url" target="_blank">
|
||||||
|
<img :src="link.favicon" alt="Link:" height="22" width="22" />
|
||||||
|
{{ link.username }}
|
||||||
|
</a>
|
||||||
|
</ds-space>
|
||||||
|
</template>
|
||||||
|
</ds-space>
|
||||||
|
</base-card>
|
||||||
|
</ds-space>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'social-media',
|
||||||
|
props: {
|
||||||
|
userName: {},
|
||||||
|
user: {},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
socialMediaLinks() {
|
||||||
|
const { socialMedia = [] } = this.user
|
||||||
|
return socialMedia.map((socialMedia) => {
|
||||||
|
const { url } = socialMedia
|
||||||
|
const matches = url.match(/^(?:https?:\/\/)?(?:[^@\n])?(?:www\.)?([^:/\n?]+)/g)
|
||||||
|
const [domain] = matches || []
|
||||||
|
const favicon = domain ? `${domain}/favicon.ico` : null
|
||||||
|
const username = url.split('/').pop()
|
||||||
|
return { url, username, favicon }
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.social-media-bc {
|
||||||
|
position: relative;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -103,23 +103,7 @@
|
|||||||
type="following"
|
type="following"
|
||||||
@fetchAllConnections="fetchAllConnections"
|
@fetchAllConnections="fetchAllConnections"
|
||||||
/>
|
/>
|
||||||
<ds-space v-if="user.socialMedia && user.socialMedia.length" margin="large">
|
<social-media :user-name="userName" :user="user" />
|
||||||
<base-card style="position: relative; height: auto">
|
|
||||||
<ds-space margin="x-small">
|
|
||||||
<ds-text tag="h5" color="soft">
|
|
||||||
{{ $t('profile.socialMedia') }} {{ userName | truncate(15) }}?
|
|
||||||
</ds-text>
|
|
||||||
<template>
|
|
||||||
<ds-space v-for="link in socialMediaLinks" :key="link.username" margin="x-small">
|
|
||||||
<a :href="link.url" target="_blank">
|
|
||||||
<user-avatar :image="link.favicon" />
|
|
||||||
{{ link.username }}
|
|
||||||
</a>
|
|
||||||
</ds-space>
|
|
||||||
</template>
|
|
||||||
</ds-space>
|
|
||||||
</base-card>
|
|
||||||
</ds-space>
|
|
||||||
</ds-flex-item>
|
</ds-flex-item>
|
||||||
|
|
||||||
<ds-flex-item :width="{ base: '100%', sm: 3, md: 5, lg: 3 }">
|
<ds-flex-item :width="{ base: '100%', sm: 3, md: 5, lg: 3 }">
|
||||||
@ -243,6 +227,7 @@ import { muteUser, unmuteUser } from '~/graphql/settings/MutedUsers'
|
|||||||
import { blockUser, unblockUser } from '~/graphql/settings/BlockedUsers'
|
import { blockUser, unblockUser } from '~/graphql/settings/BlockedUsers'
|
||||||
import PostMutations from '~/graphql/PostMutations'
|
import PostMutations from '~/graphql/PostMutations'
|
||||||
import UpdateQuery from '~/components/utils/UpdateQuery'
|
import UpdateQuery from '~/components/utils/UpdateQuery'
|
||||||
|
import SocialMedia from '~/components/SocialMedia/SocialMedia'
|
||||||
|
|
||||||
const tabToFilterMapping = ({ tab, id }) => {
|
const tabToFilterMapping = ({ tab, id }) => {
|
||||||
return {
|
return {
|
||||||
@ -254,6 +239,7 @@ const tabToFilterMapping = ({ tab, id }) => {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
SocialMedia,
|
||||||
PostTeaser,
|
PostTeaser,
|
||||||
HcFollowButton,
|
HcFollowButton,
|
||||||
HcCountTo,
|
HcCountTo,
|
||||||
@ -292,17 +278,6 @@ export default {
|
|||||||
user() {
|
user() {
|
||||||
return this.User ? this.User[0] : {}
|
return this.User ? this.User[0] : {}
|
||||||
},
|
},
|
||||||
socialMediaLinks() {
|
|
||||||
const { socialMedia = [] } = this.user
|
|
||||||
return socialMedia.map((socialMedia) => {
|
|
||||||
const { url } = socialMedia
|
|
||||||
const matches = url.match(/^(?:https?:\/\/)?(?:[^@\n])?(?:www\.)?([^:/\n?]+)/g)
|
|
||||||
const [domain] = matches || []
|
|
||||||
const favicon = domain ? `${domain}/favicon.ico` : null
|
|
||||||
const username = url.split('/').pop()
|
|
||||||
return { url, username, favicon }
|
|
||||||
})
|
|
||||||
},
|
|
||||||
userName() {
|
userName() {
|
||||||
const { name } = this.user || {}
|
const { name } = this.user || {}
|
||||||
return name || this.$t('profile.userAnonym')
|
return name || this.$t('profile.userAnonym')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user