ChannelCard.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import React from 'react'
  2. import { useChannel } from '@/api/hooks'
  3. import { useChannelVideoCount } from '@/api/hooks/channel'
  4. import { absoluteRoutes } from '@/config/routes'
  5. import { AssetType, useAsset } from '@/providers'
  6. import { ChannelCardBase } from '@/shared/components'
  7. type ChannelCardProps = {
  8. id?: string
  9. className?: string
  10. onClick?: (e: React.MouseEvent<HTMLElement>) => void
  11. }
  12. export const ChannelCard: React.FC<ChannelCardProps> = ({ id, className, onClick }) => {
  13. const { channel, loading } = useChannel(id ?? '', { fetchPolicy: 'cache-first', skip: !id })
  14. const { url } = useAsset({ entity: channel, assetType: AssetType.AVATAR })
  15. const { videoCount } = useChannelVideoCount(id ?? '', undefined, {
  16. fetchPolicy: 'cache-first',
  17. skip: !id,
  18. })
  19. const isLoading = loading || id === undefined
  20. return (
  21. <ChannelCardBase
  22. className={className}
  23. title={channel?.title}
  24. channelHref={id ? absoluteRoutes.viewer.channel(id) : undefined}
  25. videoCount={videoCount}
  26. loading={isLoading}
  27. onClick={onClick}
  28. assetUrl={url}
  29. />
  30. )
  31. }