1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-20 14:37:43 +01:00

Refactor TopFlix page and add MediaCard component

This commit is contained in:
Exodus-MW 2024-03-16 13:24:04 +05:30
parent 85b367b4c9
commit 6069dd97dd

View file

@ -1,14 +1,16 @@
import classNames from "classnames"; import classNames from "classnames";
import { ReactNode, useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { Link } from "react-router-dom"; // Import Link from react-router-dom
import { getMediaDetails, getMediaPoster } from "@/backend/metadata/tmdb";
import { TMDBContentTypes } from "@/backend/metadata/types/tmdb";
import { ThiccContainer } from "@/components/layout/ThinContainer"; import { ThiccContainer } from "@/components/layout/ThinContainer";
import { MediaCard } from "@/components/media/MediaCard";
import { MediaGrid } from "@/components/media/MediaGrid";
import { Divider } from "@/components/utils/Divider"; import { Divider } from "@/components/utils/Divider";
import { Heading1, Paragraph } from "@/components/utils/Text"; import { Heading1, Paragraph } from "@/components/utils/Text";
import { MediaItem } from "@/utils/mediaTypes";
import { SubPageLayout } from "./layouts/SubPageLayout"; import { SubPageLayout } from "./layouts/SubPageLayout";
// import { MediaGrid } from "@/components/media/MediaGrid"
// import { TopFlixCard } from "@/components/media/FlixCard";
function Button(props: { function Button(props: {
className: string; className: string;
@ -31,53 +33,25 @@ function Button(props: {
); );
} }
function isShowOrMovie(tmdbFullId: string): "series" | "movie" | "unknown" { function isShowOrMovie(tmdbFullId: string): "show" | "movie" {
if (tmdbFullId.includes("show-")) { if (tmdbFullId.includes("show-")) {
return "series"; return "show";
} }
if (tmdbFullId.includes("movie-")) { if (tmdbFullId.includes("movie-")) {
return "movie"; return "movie";
} }
return "unknown"; throw new Error("Invalid tmdbFullId");
} }
function directLinkToContent(tmdbFullId: string) { async function getPoster(
if (isShowOrMovie(tmdbFullId) === "series") { tmdbId: string,
return `/media/tmdb-tv-${tmdbFullId.split("-")[1]}#/media/tmdb-tv-${ type: TMDBContentTypes.MOVIE | TMDBContentTypes.TV,
tmdbFullId.split("-")[1] ): Promise<string> {
}`; const details = await getMediaDetails(tmdbId, type);
}
if (isShowOrMovie(tmdbFullId) === "movie") {
return `/media/tmdb-movie-${tmdbFullId.split("-")[1]}#/media/tmdb-movie-${
tmdbFullId.split("-")[1]
}`;
}
return null;
}
function ConfigValue(props: { const posterPath = getMediaPoster(details.poster_path);
name: string;
id: string; return posterPath || "";
children?: ReactNode;
}) {
const link = directLinkToContent(props.id);
return (
<>
<div className="flex">
<p className="flex-1 font-bold text-white pr-5 pl-3">
{link ? (
<Link to={link} className="hover:underline">
{props.name}
</Link>
) : (
<p>{props.name}</p>
)}
</p>
<p className="pr-3">{props.children}</p>
</div>
<Divider marginClass="my-3" />
</>
);
} }
async function getRecentPlayedItems() { async function getRecentPlayedItems() {
@ -139,8 +113,8 @@ export function TopFlix() {
const [totalViews, setTotalViews] = useState<string | null>(null); const [totalViews, setTotalViews] = useState<string | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [currentPage, setCurrentPage] = useState(1); const [currentPage, setCurrentPage] = useState(1);
const itemsPerPage = 10; const itemsPerPage = 12;
const maxItemsToShow = 100; // Maximum items to show const maxItemsToShow = 120; // Maximum items to show
const maxPageCount = Math.ceil(maxItemsToShow / itemsPerPage); // Calculate max page count based on maxItemsToShow const maxPageCount = Math.ceil(maxItemsToShow / itemsPerPage); // Calculate max page count based on maxItemsToShow
useEffect(() => { useEffect(() => {
@ -185,6 +159,8 @@ export function TopFlix() {
); );
} }
// make a object named media and it should be of type MediaItem
return ( return (
<SubPageLayout> <SubPageLayout>
<ThiccContainer> <ThiccContainer>
@ -203,20 +179,23 @@ export function TopFlix() {
</div> </div>
<Divider marginClass="my-3" /> <Divider marginClass="my-3" />
<MediaGrid>
{getItemsForCurrentPage().map((item) => { {getItemsForCurrentPage().map((item) => {
return ( const tmdbId = item.tmdbFullId.split("-")[1];
<ConfigValue const type = isShowOrMovie(item.tmdbFullId);
key={item.tmdbFullId} // const poster = await getPoster(tmdbId, type === "movie" ? TMDBContentTypes.MOVIE : TMDBContentTypes.TV);
id={item.tmdbFullId} const poster = "";
name={item.title} const media: MediaItem = {
> id: tmdbId,
{`${item.providerId}, ${isShowOrMovie( title: item.title,
item.tmdbFullId, type,
)} - Views: `} poster,
<strong>{item.count}</strong> year: 2009,
</ConfigValue> };
);
return <MediaCard linkable media={media} />;
})} })}
</MediaGrid>
</div> </div>
<div <div
style={{ display: "flex", justifyContent: "space-between" }} style={{ display: "flex", justifyContent: "space-between" }}