返回 AiToEarn
staticIcons.ts
1 import type { StaticImageData } from 'next/image'
2 import { PlatType } from '@/app/config/platConfig'
3 import bilibiliIcon from '@/assets/svgs/plat/bilibili.svg'
4 import douyinIcon from '@/assets/svgs/plat/douyin.svg'
5 import facebookIcon from '@/assets/svgs/plat/facebook.svg'
6 import gzhIcon from '@/assets/svgs/plat/gzh.svg'
7 import instagramIcon from '@/assets/svgs/plat/instagram.svg'
8 import ksIcon from '@/assets/svgs/plat/ks.svg'
9 import linkedinIcon from '@/assets/svgs/plat/linkedin.svg'
10 import pinterestIcon from '@/assets/svgs/plat/pinterest.svg'
11 import threadsIcon from '@/assets/svgs/plat/threads.svg'
12 import tiktokIcon from '@/assets/svgs/plat/tiktok.svg'
13 import twitterIcon from '@/assets/svgs/plat/twitter.svg'
14 import wxSphIcon from '@/assets/svgs/plat/wx-sph.svg'
15 import xhsIcon from '@/assets/svgs/plat/xhs.svg'
16 import youtubeIcon from '@/assets/svgs/plat/youtube.svg'
17
18 type StaticPlatformIconAsset = string | StaticImageData
19
20 const STATIC_PLATFORM_ICON_MAP: Record<PlatType, StaticPlatformIconAsset> = {
21 [PlatType.Tiktok]: tiktokIcon,
22 [PlatType.Douyin]: douyinIcon,
23 [PlatType.Xhs]: xhsIcon,
24 [PlatType.WxSph]: wxSphIcon,
25 [PlatType.KWAI]: ksIcon,
26 [PlatType.YouTube]: youtubeIcon,
27 [PlatType.BILIBILI]: bilibiliIcon,
28 [PlatType.Twitter]: twitterIcon,
29 [PlatType.WxGzh]: gzhIcon,
30 [PlatType.Facebook]: facebookIcon,
31 [PlatType.Instagram]: instagramIcon,
32 [PlatType.Threads]: threadsIcon,
33 [PlatType.Pinterest]: pinterestIcon,
34 [PlatType.LinkedIn]: linkedinIcon,
35 }
36
37 function getStaticAssetSrc(asset: StaticPlatformIconAsset) {
38 return typeof asset === 'string' ? asset : asset.src
39 }
40
41 export function getStaticPlatformIcon(platType?: PlatType | null) {
42 if (!platType)
43 return undefined
44
45 return getStaticAssetSrc(STATIC_PLATFORM_ICON_MAP[platType])
46 }
47
47 lines TYPESCRIPT