Skip to content

Commit

Permalink
feat: discord icon, fixes #315
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Mar 22, 2024
1 parent 111fc65 commit f91267e
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/components/modules/home/SocialIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,6 @@ interface SocialIconProps {
id: string
}

const type2Copy = {
github: 'GitHub',
twitter: 'Twitter',
telegram: 'Telegram',
mail: 'Email',
rss: 'RSS',
email: 'Email',
feed: 'RSS',
bilibili: '哔哩哔哩',
netease: '网易云音乐',

qq: 'QQ',
wechat: '微信',
weibo: '微博',

x: 'X',
} as any
const icons = new Set(Object.keys(type2Copy))

const iconSet: Record<
string,
[string, ReactNode, string, (id: string) => string]
Expand Down Expand Up @@ -61,6 +42,12 @@ const iconSet: Record<
'#D44638',
(id) => `mailto:${id}`,
],
get email() {
return this.mail
},
get feed() {
return this.rss
},
rss: [
'RSS',
<i className="icon-[mingcute--rss-line]" />,
Expand Down Expand Up @@ -97,14 +84,21 @@ const iconSet: Record<
'#E6162D',
(id) => `https://weibo.com/${id}`,
],
discord: [
'Discord',
<i className="icon-[mingcute--discord-fill]" />,
'#7289DA',
(id) => `https://discord.gg/${id}`,
],
}
const icons = Object.keys(iconSet)

export const isSupportIcon = (icon: string) => icons.has(icon)
export const isSupportIcon = (icon: string) => icons.includes(icon)
export const SocialIcon = memo((props: SocialIconProps) => {
const { id, type } = props

const [name, Icon, iconBg, hrefFn] = useMemo(() => {
const [name, Icon, iconBg, hrefFn] = iconSet[type] || []
const [name, Icon, iconBg, hrefFn] = (iconSet as any)[type as any] || []
return [name, Icon, iconBg, hrefFn]
}, [type])

Expand Down Expand Up @@ -132,7 +126,7 @@ export const SocialIcon = memo((props: SocialIconProps) => {
</MotionButtonBase>
}
>
{type2Copy[type] || ''}
{name}
</FloatPopover>
)
})
Expand Down

0 comments on commit f91267e

Please sign in to comment.