diff --git a/src/components/item.tsx b/src/components/item.tsx new file mode 100644 index 0000000..db1f096 --- /dev/null +++ b/src/components/item.tsx @@ -0,0 +1,28 @@ +import { Channel, Playlist, Video } from "piped-api/dist/types"; +import { VideoComponent } from "./video"; +import { PlaylistComponent } from "./playlist"; +import { ChannelComponent } from "./channel"; + +export function ItemComponent({ item, channel }: ItemComponentProps) { + if (item.type === "stream") { + item = item as Video; + return ; + } else if (item.type === "playlist") { + item = item as Playlist; + return ( + + ); + } else if (item.type === "channel") { + item = item as Channel; + return ; + } else { +
+ Idk how to render this +
; + } +} + +type ItemComponentProps = { + channel: Channel; + item: Video | Playlist | Channel; +}; diff --git a/src/components/video.tsx b/src/components/video.tsx index 6d5b2fa..321a22c 100644 --- a/src/components/video.tsx +++ b/src/components/video.tsx @@ -38,7 +38,9 @@ export function VideoComponent({ video, uploaderAvatar }: VideoComponentProps) {

- {`${shortenNumber(video.views)} • ${video.uploadedDate}`} + {`${shortenNumber(video.views)}${ + video.uploadedDate ? ` • ${video.uploadedDate}` : "" + }`}

diff --git a/src/pages/channel.tsx b/src/pages/channel.tsx index 4748c34..d61caae 100644 --- a/src/pages/channel.tsx +++ b/src/pages/channel.tsx @@ -1,16 +1,11 @@ -import { Channel, Playlist, Tab, Video } from "piped-api/dist/types"; -import { - SkeletonVideoComponent, - VideoComponent, - VideoContainer, -} from "../components/video"; +import { Channel, Tab } from "piped-api/dist/types"; +import { SkeletonVideoComponent, VideoContainer } from "../components/video"; import { useParams, useSearchParams } from "react-router-dom"; import { Button, Card, CardFooter } from "@nextui-org/react"; import { capitalize } from "../components/utils"; import React from "react"; -import { PlaylistComponent } from "../components/playlist"; import { CheckCircleIcon } from "@heroicons/react/24/solid"; -import { ChannelComponent } from "../components/channel"; +import { ItemComponent } from "../components/item"; export default function ChannelPage() { const { id } = useParams(); @@ -135,48 +130,20 @@ class ChannelPageСomponent extends React.Component< })} - {tabId !== "videos" ? ( - - {tab?.content.map((item) => { - if (item.type === "stream") { - item = item as Video; - return ( - - ); - } else if (item.type === "playlist") { - item = item as Playlist; - return ( - - ); - } else if (item.type === "channel") { - item = item as Channel; - return ; - } else { -
- Idk how to render this -
; - } - })} -
- ) : ( - - {channel.relatedStreams.map((video) => ( - + {(tabId !== "videos" + ? tab?.content || [] + : channel.relatedStreams + ).map((item) => { + return ( + - ))} - - )} + ); + })} + ); }