import PropTypes from "prop-types";
import React, { useState, useLayoutEffect, useRef } from "react";
import Box from "@mui/material/Box";
import CircularProgress from "@mui/material/CircularProgress";
import Divider from "@mui/material/Divider";
import Tab from "@mui/material/Tab";
import Tabs from "@mui/material/Tabs";
import Typography from "@mui/material/Typography";
import useParallax from "@/utils/hooks/useParallax";
import { AnimatePresence, motion, useScroll } from "framer-motion";
import {
BaseItemKind,
ItemFields,
LocationType,
} from "@jellyfin/sdk/lib/generated-client";
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { Card } from "@/components/card/card";
import { useQuery } from "@tanstack/react-query";
import { Blurhash } from "react-blurhash";
import LikeButton from "@/components/buttons/likeButton";
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
import { setBackdrop } from "@/utils/store/backdrop";
import meshBg from "@/assets/herobg.png";
import ShowMoreText from "@/components/showMoreText";
import "./person.scss";
import IconLink from "@/components/iconLink";
import { createFileRoute } from "@tanstack/react-router";
function TabPanel(props) {
const { children, value, index, ...other } = props;
return (
{value === index &&
{children}
}
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.number.isRequired,
value: PropTypes.number.isRequired,
};
function a11yProps(index) {
return {
id: `full-width-tab-${index}`,
"aria-controls": `full-width-tabpanel-${index}`,
};
}
export const Route = createFileRoute("/_api/person/$id")({
component: PersonTitlePage,
});
function PersonTitlePage() {
const { id } = Route.useParams();
const api = Route.useRouteContext().api;
const user = useQuery({
queryKey: ["user"],
queryFn: async () => {
const usr = await getUserApi(api).getCurrentUser();
return usr.data;
},
networkMode: "always",
enabled: Boolean(api),
});
const item = useQuery({
queryKey: ["item", id],
queryFn: async () => {
const result = await getUserLibraryApi(api).getItem({
userId: user.data.Id,
itemId: id,
fields: [ItemFields.Crew],
});
return result.data;
},
enabled: !!user.data,
networkMode: "always",
refetchOnWindowFocus: true,
});
const personMovies = useQuery({
queryKey: ["item", id, "personMovies"],
queryFn: async () => {
const result = await getItemsApi(api).getItems({
userId: user.data.Id,
personIds: [id],
includeItemTypes: [BaseItemKind.Movie],
recursive: true,
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
sortOrder: ["Descending"],
excludeLocationTypes: [LocationType.Virtual],
});
return result.data;
},
enabled: item.isSuccess && item.data.Type === BaseItemKind.Person,
networkMode: "always",
});
const personShows = useQuery({
queryKey: ["item", id, "personShows"],
queryFn: async () => {
const result = await getItemsApi(api).getItems({
userId: user.data.Id,
personIds: [id],
includeItemTypes: [BaseItemKind.Series],
recursive: true,
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
sortOrder: ["Descending"],
excludeLocationTypes: [LocationType.Virtual],
});
return result.data;
},
enabled: item.isSuccess && item.data.Type === BaseItemKind.Person,
networkMode: "always",
});
const personBooks = useQuery({
queryKey: ["item", id, "personBooks"],
queryFn: async () => {
const result = await getItemsApi(api).getItems({
userId: user.data.Id,
personIds: [id],
includeItemTypes: [BaseItemKind.Book],
recursive: true,
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
sortOrder: ["Descending"],
excludeLocationTypes: [LocationType.Virtual],
});
return result.data;
},
enabled: item.isSuccess && item.data.Type === BaseItemKind.Person,
networkMode: "always",
});
const personPhotos = useQuery({
queryKey: ["item", id, "personPhotos"],
queryFn: async () => {
const result = await getItemsApi(api).getItems({
userId: user.data.Id,
personIds: [id],
includeItemTypes: [BaseItemKind.Photo],
recursive: true,
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
excludeLocationTypes: [LocationType.Virtual],
});
return result.data;
},
enabled: item.isSuccess && item.data.Type === BaseItemKind.Person,
networkMode: "always",
});
const personEpisodes = useQuery({
queryKey: ["item", id, "personEpisodes"],
queryFn: async () => {
const result = await getItemsApi(api).getItems({
userId: user.data.Id,
personIds: [id],
includeItemTypes: [BaseItemKind.Episode],
recursive: true,
fields: ["SeasonUserData", "Overview"],
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
excludeLocationTypes: [LocationType.Virtual],
limit: 24,
});
return result.data;
},
enabled: item.isSuccess && item.data.Type === BaseItemKind.Person,
networkMode: "always",
});
const [activePersonTab, setActivePersonTab] = useState(0);
const personTabs = [
{
title: "Movies",
data: personMovies,
queryKey: ["item", id, "personMovies"],
},
{
title: "TV Shows",
data: personShows,
queryKey: ["item", id, "personShows"],
},
{
title: "Books",
data: personBooks,
queryKey: ["item", id, "personBooks"],
},
{
title: "Photos",
data: personPhotos,
queryKey: ["item", id, "personPhotos"],
},
{
title: "Episodes",
data: personEpisodes,
queryKey: ["item", id, "personEpisodes"],
},
];
useLayoutEffect(() => {
if (
personMovies.isSuccess &&
personShows.isSuccess &&
personBooks.isSuccess &&
personPhotos.isSuccess &&
personEpisodes.isSuccess
) {
if (personMovies.data.TotalRecordCount !== 0) {
setActivePersonTab(0);
} else if (personShows.data.TotalRecordCount !== 0) {
setActivePersonTab(1);
} else if (personBooks.data.TotalRecordCount !== 0) {
setActivePersonTab(2);
} else if (personPhotos.data.TotalRecordCount !== 0) {
setActivePersonTab(3);
} else if (personEpisodes.data.TotalRecordCount !== 0) {
setActivePersonTab(4);
}
}
setBackdrop("", "");
}, [
personMovies.isSuccess,
personShows.isSuccess,
personBooks.isSuccess,
personPhotos.isSuccess,
personEpisodes.isSuccess,
]);
const [animationDirection, setAnimationDirection] = useState("forward");
const pageRef = useRef(null);
const { scrollYProgress } = useScroll({
target: pageRef,
offset: ["start start", "60vh start"],
});
const parallax = useParallax(scrollYProgress, 50);
if (item.isPending) {
return (
);
}
if (item.isSuccess) {
return (
{
e.currentTarget.style.opacity = 1;
}}
style={{
y: parallax,
}}
/>
{Object.keys(item.data.ImageTags).includes("Primary") ? (
<>

{
e.currentTarget.style.opacity = 1;
}}
className="item-hero-image"
/>
>
) : (
<>>
)}
{item.data.Name}
{item.data.ExternalUrls.map((url) => (
))}
{item.data.PremiereDate && (
<>
Birth
{new Date(item.data.PremiereDate).toDateString()}
>
)}
{item.data.EndDate && (
<>
Death
{new Date(item.data.EndDate).toDateString()}
>
)}
{
if (newVal > activePersonTab) {
setAnimationDirection("forward");
} else if (newVal < activePersonTab) {
setAnimationDirection("backwards");
}
setActivePersonTab(newVal);
}}
>
{personTabs.map((tab) => {
return (
);
})}
{personTabs.map((tab, index) => {
return (
{tab.data.isSuccess &&
tab.data.data.Items.map((tabitem, index) => {
return (
);
})}
{tab.data.isSuccess &&
tab.data.data.TotalRecordCount > 24 && (
And more...
)}
);
})}
);
}
if (item.isError) {
return ;
}
}
export default PersonTitlePage;