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

revert to OG flix page bc i cant code for shit

This commit is contained in:
Cooper Ransom 2024-03-17 16:54:18 -04:00
parent 2afc08d159
commit 313f6af874

View file

@ -1,15 +1,14 @@
import classNames from "classnames"; import classNames from "classnames";
import { useEffect, useState } from "react"; import { ReactNode, 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 { Divider } from "@/components/utils/Divider";
import { MediaGrid } from "@/components/media/MediaGrid";
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;
@ -32,25 +31,53 @@ function Button(props: {
); );
} }
function isShowOrMovie(tmdbFullId: string): "show" | "movie" { function isShowOrMovie(tmdbFullId: string): "series" | "movie" | "unknown" {
if (tmdbFullId.includes("show-")) { if (tmdbFullId.includes("show-")) {
return "show"; return "series";
} }
if (tmdbFullId.includes("movie-")) { if (tmdbFullId.includes("movie-")) {
return "movie"; return "movie";
} }
throw new Error("Invalid tmdbFullId"); return "unknown";
} }
async function getPoster( function directLinkToContent(tmdbFullId: string) {
tmdbId: string, if (isShowOrMovie(tmdbFullId) === "series") {
type: TMDBContentTypes.MOVIE | TMDBContentTypes.TV, return `${window.location.pathname}#/media/tmdb-movie-${
): Promise<string> { tmdbFullId.split("-")[1]
const details = await getMediaDetails(tmdbId, type); }`;
}
if (isShowOrMovie(tmdbFullId) === "movie") {
return `${window.location.pathname}#/media/tmdb-tv-${
tmdbFullId.split("-")[1]
}`;
}
return null;
}
const posterPath = getMediaPoster(details.poster_path); function ConfigValue(props: {
name: string;
return posterPath || ""; id: string;
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() {
@ -112,8 +139,9 @@ 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 = 12; const itemsPerPage = 10;
const maxItemsToShow = 12; // Maximum items to show const maxItemsToShow = 100; // Maximum items to show
const maxPageCount = Math.ceil(maxItemsToShow / itemsPerPage); // Calculate max page count based on maxItemsToShow
useEffect(() => { useEffect(() => {
getRecentPlayedItems() getRecentPlayedItems()
@ -157,8 +185,6 @@ export function TopFlix() {
); );
} }
// make a object named media and it should be of type MediaItem
return ( return (
<SubPageLayout> <SubPageLayout>
<ThiccContainer> <ThiccContainer>
@ -169,30 +195,50 @@ export function TopFlix() {
the current backend deployment. the current backend deployment.
</Paragraph> </Paragraph>
<div className="mt-8 w-auto"> <div className="mt-8 w-auto">
<div className="bg-buttons-secondary rounded-xl scale-95 py-3 px-5 mb-14 inline-block"> <div className="bg-buttons-secondary rounded-xl scale-95 py-3 px-5 mb-2 inline-block">
<p className="font-bold bg-opacity-90 text-buttons-secondaryText"> <p className="font-bold bg-opacity-90 text-buttons-secondaryText">
Overall Views: {totalViews} Overall Views: {totalViews}
</p> </p>
</div> </div>
</div> </div>
<MediaGrid> <Divider marginClass="my-3" />
{getItemsForCurrentPage().map((item) => { {getItemsForCurrentPage().map((item) => {
const tmdbId = item.tmdbFullId.split("-")[1]; return (
const type = isShowOrMovie(item.tmdbFullId); <ConfigValue
const poster = getPoster(tmdbId, type === "movie" ? TMDBContentTypes.MOVIE : TMDBContentTypes.TV); key={item.tmdbFullId}
console.log(poster); id={item.tmdbFullId}
const media: MediaItem = { name={item.title}
id: tmdbId, >
title: item.title, {`${item.providerId}, ${isShowOrMovie(
type, item.tmdbFullId,
poster, )} - Views: `}
// year: 420, <strong>{item.count}</strong>
}; </ConfigValue>
);
return <MediaCard linkable media={media} />;
})} })}
</MediaGrid> </div>
<div
style={{ display: "flex", justifyContent: "space-between" }}
className="mt-5 w-full px-8"
>
<Button
className="py-px box-content bg-buttons-secondary hover:bg-buttons-secondaryHover bg-opacity-90 text-buttons-secondaryText justify-center items-center"
onClick={() => setCurrentPage(currentPage - 1)}
disabled={currentPage === 1}
>
Previous page
</Button>
<div style={{ display: "flex", alignItems: "center" }}>
{currentPage} / {maxPageCount}
</div>
<Button
className="py-px box-content bg-buttons-secondary hover:bg-buttons-secondaryHover bg-opacity-90 text-buttons-secondaryText justify-center items-center"
onClick={() => setCurrentPage(currentPage + 1)}
disabled={currentPage === maxPageCount}
>
Next page
</Button>
</div> </div>
</ThiccContainer> </ThiccContainer>
</SubPageLayout> </SubPageLayout>