ChannelView.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React from 'react'
  2. import { RouteComponentProps, useParams } from '@reach/router'
  3. import { useQuery } from '@apollo/client'
  4. import { GET_CHANNEL } from '@/api/queries/channels'
  5. import { GetChannel, GetChannelVariables } from '@/api/queries/__generated__/GetChannel'
  6. import { VideoGrid } from '@/components'
  7. import { Header, StyledAvatar, Title, TitleSection, VideoSection } from './ChannelView.style'
  8. const ChannelView: React.FC<RouteComponentProps> = () => {
  9. const { id } = useParams()
  10. const { loading, data } = useQuery<GetChannel, GetChannelVariables>(GET_CHANNEL, {
  11. variables: { id },
  12. })
  13. if (loading || !data?.channel) {
  14. return <p>Loading Channel...</p>
  15. }
  16. const videos = data?.channel?.videos || []
  17. return (
  18. <div>
  19. <Header coverPhotoURL={data.channel.coverPhotoURL}>
  20. <TitleSection>
  21. <StyledAvatar img={data.channel.avatarPhotoURL} name={data.channel.handle} />
  22. <Title>{data.channel.handle}</Title>
  23. </TitleSection>
  24. </Header>
  25. {videos.length > 0 && (
  26. <VideoSection>
  27. <VideoGrid videos={videos} showChannel={false} />
  28. </VideoSection>
  29. )}
  30. </div>
  31. )
  32. }
  33. export default ChannelView