ADD: All Vods on Home Page

ToDo:
Thumbnail in DB
Save user stream to Vod
This commit is contained in:
EvanLin3141
2025-02-28 19:52:01 +00:00
parent 077530b6e6
commit edb959506a
5 changed files with 153 additions and 39 deletions

View File

@@ -2,13 +2,14 @@ import React from "react";
import { StreamType } from "../../types/StreamType";
import { CategoryType } from "../../types/CategoryType";
import { UserType } from "../../types/UserType";
import { VodType } from "../../types/VodType";
// Base props that all item types share
interface BaseListItemProps {
onItemClick?: () => void;
extraClasses?: string;
}
// Stream item component
interface StreamListItemProps extends BaseListItemProps, Omit<StreamType, 'type'> {}
@@ -124,6 +125,52 @@ const UserListItem: React.FC<UserListItemProps> = ({
);
};
// VODs item component
interface VodListItemProps extends BaseListItemProps, Omit<VodType, "type"> {}
const VodListItem: React.FC<VodListItemProps> = ({
title,
streamer,
datetime,
category,
length,
views,
thumbnail,
url,
onItemClick,
extraClasses = "",
}) => {
return (
<div className="p-4">
<div
className={`${extraClasses} overflow-hidden flex-shrink-0 flex flex-col bg-purple-900 rounded-lg cursor-pointer mx-auto hover:bg-purple-600 hover:scale-105 transition-all`}
onClick={() => window.open(url, "_blank")}
>
<div className="relative w-full aspect-video overflow-hidden rounded-t-lg">
{thumbnail ? (
<img
src={thumbnail}
alt={title}
className="absolute top-0 left-0 w-full h-full object-cover"
/>
) : (
<div className="absolute top-0 left-0 w-full h-full bg-gray-600" />
)}
</div>
<div className="p-3">
<h3 className="font-semibold text-lg text-center truncate max-w-full">
{title}
</h3>
<p className="font-bold">{streamer}</p>
<p className="text-sm text-gray-300">{category}</p>
<p className="text-sm text-gray-300">{new Date(datetime).toLocaleDateString()} | {length} mins</p>
<p className="text-sm text-gray-300">{views} views</p>
</div>
</div>
</div>
);
};
// Legacy wrapper component for backward compatibility
export interface ListItemProps {
type: "stream" | "category" | "user";
@@ -138,4 +185,4 @@ export interface ListItemProps {
isLive?: boolean;
}
export { StreamListItem, CategoryListItem, UserListItem };
export { StreamListItem, CategoryListItem, UserListItem, VodListItem };

View File

@@ -10,16 +10,17 @@ import React, {
} from "react";
import { useNavigate } from "react-router-dom";
import "../../assets/styles/listRow.css";
import { StreamListItem, CategoryListItem, UserListItem } from "./ListItem";
import { StreamListItem, CategoryListItem, UserListItem, VodListItem } from "./ListItem";
import { StreamType } from "../../types/StreamType";
import { CategoryType } from "../../types/CategoryType";
import { UserType } from "../../types/UserType";
import { VodType } from "../../types/VodType"
type ItemType = StreamType | CategoryType | UserType;
type ItemType = StreamType | CategoryType | UserType | VodType;
interface ListRowProps {
variant?: "default" | "search";
type: "stream" | "category" | "user";
type: "stream" | "category" | "user" | "vod";
title?: string;
description?: string;
items: ItemType[];
@@ -100,6 +101,9 @@ const ListRow = forwardRef<ListRowRef, ListRowProps>((props, ref) => {
const isUserType = (item: ItemType): item is UserType =>
item.type === "user";
const isVodType = (item: ItemType): item is VodType =>
item.type === "vod";
return (
<div
className={`${extraClasses} flex relative rounded-[1.5rem] text-white transition-all ${
@@ -196,6 +200,24 @@ const ListRow = forwardRef<ListRowRef, ListRowProps>((props, ref) => {
/>
);
}
else if (type === "vod" && isVodType(item)) {
return (
<VodListItem
key={`vod-${item.id}`}
id={item.id}
title={item.title}
streamer={item.streamer}
datetime={item.datetime}
category={item.category}
length={item.length}
views={item.views}
url={item.url}
thumbnail={item.thumbnail}
onItemClick={() => window.open(item.url, "_blank")}
extraClasses={itemExtraClasses}
/>
);
}
return null;
})}
</>