Skip to content

Commit

Permalink
User social links
Browse files Browse the repository at this point in the history
Related to Issue #39
  • Loading branch information
BobChao87 committed Oct 27, 2021
1 parent 68bd6aa commit 0371b53
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 19 deletions.
18 changes: 0 additions & 18 deletions components/user/Social.vue

This file was deleted.

88 changes: 88 additions & 0 deletions components/user/social/Box.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<template>
<Component :is="connectionMeta.link ? 'a' : 'div'" :href="connectionMeta.link" class="social-link-container">
<p>{{ connectionMeta.header || connection.platform }}</p>
<FontAwesomeIcon :icon="connectionMeta.icon" class="icon fa-6x" />
<p>{{ connection.username }}</p>
</Component>
</template>

<script lang="ts">
import Vue from 'vue';
import { Connection, ConnectionMeta, ConnectionMetas } from '~/types/api/user';
export default Vue.extend({
props: {
connection: {
type: Object as () => Connection,
default: undefined,
},
},
computed: {
connectionMeta(): Partial<ConnectionMeta> {
const connectionMeta = this.connectionMetas[this.connection?.platform] ?? { };
if (connectionMeta.linkBase) {

This comment has been minimized.

Copy link
@duncte123

duncte123 Oct 27, 2021

Member

Can't this be changed to this?

connectionMeta.linkBase?.(this.connection.username)

This comment has been minimized.

Copy link
@BobChao87

BobChao87 Oct 27, 2021

Author Contributor

Ah, it can! I clearly haven't adjusting my thinking for that when it comes to function calls, even though I know it exists.

connectionMeta.link = connectionMeta.linkBase(this.connection.username);
}
return connectionMeta;
},
},
/* eslint-disable-next-line vue/order-in-components */ // Here, data is way less interesting than computed
data() {
return {
connectionMetas: {
DISCORD: {
icon: [ 'fab', 'discord' ],
},
EMAIL: {
linkBase: fragment => `mailto:${fragment}`,
icon: [ 'fas', 'envelope' ],
},
FACEBOOK: {
linkBase: fragment => `https://www.facebook.com/${fragment}`,
icon: [ 'fab', 'facebook-f' ],
},
INSTAGRAM: {
linkBase: fragment => `https://www.instagram.com/${fragment}`,
icon: [ 'fab', 'instagram' ],
},
PHONE: {
linkBase: fragment => `tel:${fragment}`,
icon: [ 'fas', 'phone' ],
},
NICO: {
linkBase: fragment => `https://com.nicovideo.jp/community/${fragment}`,
icon: [ 'fas', 'tv' ],
},
SNAPCHAT: {
linkBase: fragment => `https://www.snapchat.com/add/${fragment}`,
icon: [ 'fab', 'snapchat-ghost' ],
},
SPEEDRUNCOM: {
linkBase: fragment => `https://speedrun.com/user/${fragment}`,
icon: [ 'fas', 'trophy' ],
},
TWITCH: {
linkBase: fragment => `https://www.twitch.tv/${fragment}`,
icon: [ 'fab', 'twitch' ],
},
TWITTER: {
linkBase: fragment => `https://www.twitter.com/${fragment}`,
icon: [ 'fab', 'twitter' ],
},
} as ConnectionMetas,
};
},
});
</script>

<style lang="scss" scoped>
.social-link-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
padding: var(--spacing);
}
</style>
48 changes: 48 additions & 0 deletions components/user/social/Social.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<div v-if="user && !user._fetching && user.connections.length" class="social-container">
<UserSocialBox v-for="connection of user.connections" :key="connection.id" :connection="connection" />
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import { mapActions } from 'vuex';
import { User, UserState } from '~/types/api/user';
export default Vue.extend({
props: {
userId: {
type: String,
default: '',
},
},
async fetch(): Promise<void> {
await Promise.allSettled([
this.getUser(this.userId),
]);
},
computed: {
user(): User|undefined {
return (this.$store.state.api.user as UserState).users[this.userId];
},
},
methods: {
...mapActions({
getUser: 'api/user/get',
}),
},
});
</script>

<style lang="scss" scoped>
.social-container {
width: 100%;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
border-block: 1px solid;
}
</style>
7 changes: 7 additions & 0 deletions configs/font-awesome.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ const solid = [
'Desktop',
'Donate',
'DotCircle',
'Envelope',
'Home',
'Language',
'MoneyBill',
'PaperPlane',
'Phone',
'Plus',
'Trophy',
'Tv',
];

const brands = [
'Discord',
'FacebookF',
'Github',
'Instagram',
'Patreon',
'SnapchatGhost',
'Twitch',
'Twitter',
];
Expand Down
23 changes: 22 additions & 1 deletion types/api/user.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,31 @@ export interface UserState extends OengusState {
searches: { [query: string]: Array<User>; };
}

export type ConnectionPlatform = 'DISCORD'|'TWITCH'|'TWITTER'|''
// This ended up being kinda social. Move to its own file?

export type ConnectionPlatform =
'DISCORD' |
'EMAIL' |
'FACEBOOK' |
'INSTAGRAM' |
'PHONE' |
'NICO' |
'SNAPCHAT' |
'SPEEDRUNCOM' |
'TWITCH' |
'TWITTER';

export interface Connection {
id: number;
platform: ConnectionPlatform;
username: string;
}

export interface ConnectionMeta {
linkBase?: (fragment: string) => string;
icon: Array<String>;
header?: string;
link?: string;
}

export type ConnectionMetas = Record<ConnectionPlatform, ConnectionMeta>;

0 comments on commit 0371b53

Please sign in to comment.