fix: episode and series not playing if episode is not present in nextUp and continueWatching
This commit is contained in:
6 files changed
+66
-40
No files matched your search
@@ -20,7 +20,7 @@ export default function LikeButton({
|
||||
isFavorite: boolean | undefined;
|
||||
queryKey: string[] | undefined;
|
||||
userId: string | undefined;
|
||||
itemName: string | undefined;
|
||||
itemName?: string | null;
|
||||
}) {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -20,7 +20,7 @@ export default function MarkPlayedButton({
|
||||
isPlayed?: boolean;
|
||||
queryKey?: string[];
|
||||
userId?: string;
|
||||
itemName?: string;
|
||||
itemName?: string | null;
|
||||
}) {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
|
||||
@@ -145,7 +145,15 @@ const PlayButton = ({
|
||||
seasonId: item.SeasonId,
|
||||
// startItemId: item.Id,
|
||||
});
|
||||
index = result.data.Items?.map((i) => i.Id).indexOf(item.Id) ?? 0;
|
||||
if (
|
||||
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) &&
|
||||
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) >
|
||||
-1
|
||||
) {
|
||||
index = result.data.Items?.map((i) => i.Id).indexOf(
|
||||
currentEpisodeId,
|
||||
);
|
||||
}
|
||||
mediaSource = await getMediaInfoApi(api).getPostedPlaybackInfo({
|
||||
audioStreamIndex: currentAudioTrack,
|
||||
subtitleStreamIndex:
|
||||
@@ -180,11 +188,14 @@ const PlayButton = ({
|
||||
enableUserData: true,
|
||||
userId: userId,
|
||||
});
|
||||
index =
|
||||
result.data.Items?.map((i) => i.Id).indexOf(
|
||||
currentEpisodeId ?? "",
|
||||
) ?? 0;
|
||||
|
||||
if (
|
||||
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) &&
|
||||
result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) > -1
|
||||
) {
|
||||
index = result.data.Items?.map((i) => i.Id).indexOf(
|
||||
currentEpisodeId,
|
||||
);
|
||||
}
|
||||
if (
|
||||
result.data.Items?.[index]?.Id &&
|
||||
result.data.Items?.[index].MediaSources?.[0]?.Id
|
||||
@@ -475,7 +486,7 @@ const PlayButton = ({
|
||||
if (!item.Id) {
|
||||
throw new Error("Item ID is not available");
|
||||
}
|
||||
let data: BaseItemDtoQueryResult | undefined;
|
||||
let data: BaseItemDtoQueryResult | null = null;
|
||||
const continueWatching = await getItemsApi(api).getResumeItems({
|
||||
userId: userId,
|
||||
limit: 1,
|
||||
@@ -493,10 +504,12 @@ const PlayButton = ({
|
||||
data = continueWatching.data;
|
||||
} else if ((nextUp.data.Items?.length ?? 0) > 0) {
|
||||
data = nextUp.data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
},
|
||||
enabled: itemType === BaseItemKind.Series,
|
||||
// enabled: itemType === BaseItemKind.Series,
|
||||
});
|
||||
return (
|
||||
<div
|
||||
@@ -531,7 +544,7 @@ const PlayButton = ({
|
||||
color="white"
|
||||
size={size}
|
||||
>
|
||||
Watch S{currentEpisode.data?.Items?.[0].ParentIndexNumber}E
|
||||
Watch S{currentEpisode.data?.Items?.[0].ParentIndexNumber ?? 1}E
|
||||
{currentEpisode.data?.Items?.[0]?.IndexNumber ?? 1}
|
||||
<MemoizedLinearProgress
|
||||
//@ts-ignore
|
||||
|
||||
@@ -4,7 +4,6 @@ import { motion } from "framer-motion";
|
||||
|
||||
import Button from "@mui/material/Button";
|
||||
import Chip from "@mui/material/Chip";
|
||||
import Paper from "@mui/material/Paper";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
@@ -17,6 +16,7 @@ import { getTypeIcon } from "../utils/iconsCollection";
|
||||
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCarouselStore } from "@/utils/store/carousel";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
import LikeButton from "../buttons/likeButton";
|
||||
import MarkPlayedButton from "../buttons/markPlayedButton";
|
||||
import PlayButton from "../buttons/playButton";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
@@ -74,20 +73,20 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
className="hero-carousel-background-image"
|
||||
src={
|
||||
item.ParentBackdropItemId
|
||||
? `${api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
|
||||
: `${api.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
|
||||
? `${api?.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
|
||||
: `${api?.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
|
||||
}
|
||||
style={{
|
||||
opacity: 0,
|
||||
}}
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
loading="eager"
|
||||
/>
|
||||
) : (
|
||||
<div className="hero-carousel-background-icon-container">
|
||||
{getTypeIcon(item.Type)}
|
||||
{getTypeIcon(item.Type ?? "Movie")}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -129,16 +128,16 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
item.Name
|
||||
) : (
|
||||
<img
|
||||
alt={item.Name}
|
||||
alt={item.Name ?? "Item"}
|
||||
className="hero-carousel-text-logo"
|
||||
src={`${api.basePath}/Items/${item.Id}/Images/Logo?quality=90&tag=${item.ImageTags.Logo}`}
|
||||
src={`${api?.basePath}/Items/${item.Id}/Images/Logo?quality=90&tag=${item.ImageTags.Logo}`}
|
||||
style={{
|
||||
opacity: 0,
|
||||
transition: "opacity 0.2s",
|
||||
objectFit: "contain",
|
||||
}}
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
@@ -240,15 +239,21 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{item.RunTimeTicks && (
|
||||
{item.RunTimeTicks ? (
|
||||
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
||||
{getRuntime(item.RunTimeTicks)}
|
||||
</Typography>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
{item.RunTimeTicks && (
|
||||
{item.RunTimeTicks ? (
|
||||
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
||||
{endsAt(item.RunTimeTicks - item.UserData.PlaybackPositionTicks)}
|
||||
{endsAt(
|
||||
item.RunTimeTicks - (item.UserData?.PlaybackPositionTicks ?? 0),
|
||||
)}
|
||||
</Typography>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
<Typography variant="subtitle2" style={{ opacity: 0.8 }}>
|
||||
{item.Genres?.slice(0, 4).join(" / ")}
|
||||
@@ -305,16 +310,14 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
>
|
||||
<PlayButton
|
||||
item={item}
|
||||
itemId={item.Id}
|
||||
userId={user?.Id}
|
||||
itemType={item.Type}
|
||||
itemType={item.Type ?? "Movie"}
|
||||
currentAudioTrack={0}
|
||||
currentSubTrack={0}
|
||||
currentVideoTrack={0}
|
||||
buttonProps={{
|
||||
size: "large",
|
||||
}}
|
||||
itemUserData={item.UserData}
|
||||
audio={
|
||||
item.Type === BaseItemKind.MusicAlbum ||
|
||||
item.Type === BaseItemKind.Audio ||
|
||||
@@ -327,6 +330,7 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
|
||||
<Button
|
||||
size="large"
|
||||
//@ts-ignore
|
||||
color="white"
|
||||
variant="outlined"
|
||||
endIcon={
|
||||
|
||||
@@ -263,7 +263,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
<AudioPlayer />
|
||||
<Outlet />
|
||||
<ReactQueryDevtools />
|
||||
<TanStackRouterDevtools />
|
||||
{/* <TanStackRouterDevtools /> */}
|
||||
</SnackbarProvider>
|
||||
</ThemeProvider>
|
||||
</Suspense>
|
||||
|
||||
@@ -45,18 +45,20 @@ function Home() {
|
||||
const libraries = useQuery({
|
||||
queryKey: ["libraries"],
|
||||
queryFn: async () => {
|
||||
if (!api) return;
|
||||
const libs = await getUserViewsApi(api).getUserViews({
|
||||
userId: user?.Id,
|
||||
});
|
||||
return libs.data;
|
||||
},
|
||||
enabled: !!user?.Id && !!api.accessToken,
|
||||
enabled: !!user?.Id && !!api?.accessToken,
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
const latestMedia = useQuery({
|
||||
queryKey: ["home", "latestMedia"],
|
||||
queryFn: async () => {
|
||||
if (!api) return;
|
||||
const media = await getUserLibraryApi(api).getLatestMedia({
|
||||
userId: user?.Id,
|
||||
fields: [
|
||||
@@ -83,6 +85,7 @@ function Home() {
|
||||
const resumeItemsVideo = useQuery({
|
||||
queryKey: ["home", "resume", "video"],
|
||||
queryFn: async () => {
|
||||
if (!api) return;
|
||||
const resumeItems = await getItemsApi(api).getResumeItems({
|
||||
userId: user?.Id,
|
||||
limit: 10,
|
||||
@@ -99,6 +102,7 @@ function Home() {
|
||||
const resumeItemsAudio = useQuery({
|
||||
queryKey: ["home", "resume", "audio"],
|
||||
queryFn: async () => {
|
||||
if (!api) return;
|
||||
const resumeItems = await getItemsApi(api).getResumeItems({
|
||||
userId: user?.Id,
|
||||
limit: 10,
|
||||
@@ -114,6 +118,7 @@ function Home() {
|
||||
const upNextItems = useQuery({
|
||||
queryKey: ["home", "upNext"],
|
||||
queryFn: async () => {
|
||||
if (!api) return;
|
||||
const upNext = await getTvShowsApi(api).getNextUp({
|
||||
userId: user?.Id,
|
||||
fields: [
|
||||
@@ -144,7 +149,7 @@ function Home() {
|
||||
|
||||
useEffect(() => {
|
||||
if (libraries.isSuccess) {
|
||||
const latestMediaLibsTemp = libraries.data.Items?.reduce(
|
||||
const latestMediaLibsTemp = libraries.data?.Items?.reduce(
|
||||
(filteredItems: BaseItemDto[], currentItem) => {
|
||||
if (currentItem.Type && !excludeTypes.has(currentItem.Type)) {
|
||||
filteredItems.push(currentItem);
|
||||
@@ -174,11 +179,15 @@ function Home() {
|
||||
<Carousel
|
||||
content={latestMedia.data}
|
||||
onChange={(now: number) => {
|
||||
if (latestMedia.isSuccess && latestMedia.data.length > 0) {
|
||||
if (latestMedia.data[now]?.ParentBackdropImageTags) {
|
||||
if (
|
||||
api &&
|
||||
latestMedia.isSuccess &&
|
||||
(latestMedia.data?.length ?? 0) > 0
|
||||
) {
|
||||
if (latestMedia.data?.[now]?.ParentBackdropImageTags) {
|
||||
setBackdrop(
|
||||
getImageUrlsApi(api).getItemImageUrlById(
|
||||
latestMedia.data[now].Id,
|
||||
latestMedia.data[now].Id ?? "",
|
||||
"Backdrop",
|
||||
{
|
||||
tag: latestMedia.data[now]
|
||||
@@ -191,14 +200,14 @@ function Home() {
|
||||
} else {
|
||||
setBackdrop(
|
||||
getImageUrlsApi(api).getItemImageUrlById(
|
||||
latestMedia.data[now].Id,
|
||||
latestMedia.data?.[now].Id ?? "",
|
||||
"Backdrop",
|
||||
{
|
||||
tag: latestMedia.data[now].BackdropImageTags[0],
|
||||
tag: latestMedia.data?.[now].BackdropImageTags?.[0],
|
||||
},
|
||||
),
|
||||
latestMedia.data[now]?.BackdropImageTags[0] ??
|
||||
latestMedia.data[now].Id,
|
||||
latestMedia.data?.[now]?.BackdropImageTags?.[0] ??
|
||||
latestMedia.data?.[now].Id,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -220,7 +229,7 @@ function Home() {
|
||||
) : (
|
||||
<CardScroller displayCards={4} title="Libraries">
|
||||
{libraries.status === "success" &&
|
||||
libraries.data.Items?.map((item) => {
|
||||
libraries.data?.Items?.map((item) => {
|
||||
return (
|
||||
<Card
|
||||
key={item.Id}
|
||||
@@ -253,7 +262,7 @@ function Home() {
|
||||
>
|
||||
{upNextItems.isPending ? (
|
||||
<CardsSkeleton />
|
||||
) : upNextItems.isSuccess && !upNextItems.data.TotalRecordCount ? (
|
||||
) : upNextItems.isSuccess && !upNextItems.data?.TotalRecordCount ? (
|
||||
<></>
|
||||
) : (
|
||||
<CardScroller displayCards={4} title="Up Next">
|
||||
@@ -310,7 +319,7 @@ function Home() {
|
||||
{resumeItemsVideo.isPending ? (
|
||||
<CardsSkeleton />
|
||||
) : resumeItemsVideo.isSuccess &&
|
||||
!resumeItemsVideo.data.TotalRecordCount ? (
|
||||
!resumeItemsVideo.data?.TotalRecordCount ? (
|
||||
<></>
|
||||
) : (
|
||||
<CardScroller displayCards={4} title="Continue Watching">
|
||||
@@ -363,7 +372,7 @@ function Home() {
|
||||
{resumeItemsAudio.isPending ? (
|
||||
<CardsSkeleton />
|
||||
) : resumeItemsAudio.isSuccess &&
|
||||
!resumeItemsAudio.data.TotalRecordCount ? (
|
||||
!resumeItemsAudio.data?.TotalRecordCount ? (
|
||||
<></>
|
||||
) : (
|
||||
<CardScroller displayCards={4} title="Continue Listening">
|
||||
|
||||
Reference in new issue
Block a user