mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
refactor: extracting social media to vue component
This commit is contained in:
parent
0585960313
commit
3be426c0d5
42
webapp/components/SocialMedia/SocialMedia.vue
Normal file
42
webapp/components/SocialMedia/SocialMedia.vue
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<template>
|
||||||
|
<ds-space v-if="user.socialMedia && user.socialMedia.length" margin="large">
|
||||||
|
<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">
|
||||||
|
<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>
|
||||||
@ -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">
|
|
||||||
<img :src="link.favicon" alt="Link:" height="22" width="22" />
|
|
||||||
{{ 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