| 1 | 'use client' |
| 2 | |
| 3 | import type { PlatType } from '@/app/config/platConfig' |
| 4 | import type { OssImageProps } from '@/components/common/OssImage' |
| 5 | import { OssImage } from '@/components/common/OssImage' |
| 6 | import { usePlatformInfo } from '@/hooks/usePlatformMetadata' |
| 7 | import { getStaticPlatformIcon } from '@/store/platformMetadata/staticIcons' |
| 8 | |
| 9 | type PlatformIconProps = Omit<OssImageProps, 'src' | 'alt'> & { |
| 10 | platform?: PlatType | null |
| 11 | src?: string |
| 12 | alt?: string |
| 13 | } |
| 14 | |
| 15 | export function PlatformIcon({ platform, src, alt, width = 20, height = 20, ...props }: PlatformIconProps) { |
| 16 | const platformInfo = usePlatformInfo(platform) |
| 17 | const imageSrc = src ?? platformInfo?.icon ?? getStaticPlatformIcon(platform) |
| 18 | |
| 19 | if (!imageSrc) |
| 20 | return null |
| 21 | |
| 22 | return ( |
| 23 | <OssImage |
| 24 | {...props} |
| 25 | src={imageSrc} |
| 26 | alt={alt ?? platformInfo?.name ?? platform ?? 'platform'} |
| 27 | width={width} |
| 28 | height={height} |
| 29 | thumbnailWidth={typeof width === 'number' ? width : undefined} |
| 30 | thumbnailHeight={typeof height === 'number' ? height : undefined} |
| 31 | /> |
| 32 | ) |
| 33 | } |
| 34 | |
| 35 | export default PlatformIcon |
| 36 |