feat: enhance PlayButton to fetch and display current episode data
This commit is contained in:
1 parent
2d4b0d66b4
commit
65e5370dbf
1 file changed
+73
-36
@@ -629,33 +629,6 @@ const PlayButton = ({
|
||||
e.stopPropagation();
|
||||
itemQuery.mutate(currentEpisodeId);
|
||||
};
|
||||
if (iconOnly) {
|
||||
return (
|
||||
//@ts-ignore
|
||||
<Fab
|
||||
color="primary"
|
||||
aria-label="Play"
|
||||
className={className}
|
||||
onClick={(e) =>
|
||||
item.Type === "Episode" ? handleClick(e, item.Id) : handleClick(e)
|
||||
}
|
||||
sx={sx}
|
||||
size={size}
|
||||
{...buttonProps}
|
||||
>
|
||||
<div
|
||||
className="material-symbols-rounded em-4 fill"
|
||||
style={{
|
||||
fontSize: "3em",
|
||||
}}
|
||||
>
|
||||
play_arrow
|
||||
</div>
|
||||
</Fab>
|
||||
);
|
||||
}
|
||||
|
||||
if (itemType === BaseItemKind.Series) {
|
||||
const currentEpisode = useQuery({
|
||||
queryKey: ["playButton", "currentEpisode", item?.Id],
|
||||
queryFn: async () => {
|
||||
@@ -693,6 +666,47 @@ const PlayButton = ({
|
||||
},
|
||||
// enabled: itemType === BaseItemKind.Series,
|
||||
});
|
||||
|
||||
if (iconOnly) {
|
||||
return (
|
||||
//@ts-ignore
|
||||
<Fab
|
||||
color="primary"
|
||||
aria-label="Play"
|
||||
className={className}
|
||||
onClick={(e) => {
|
||||
if (item.Type === "Episode") {
|
||||
handleClick(e, item.Id)
|
||||
} else if (itemType === BaseItemKind.Series) {
|
||||
handleClick(e, currentEpisode.data?.Items?.[0]?.Id)
|
||||
} else {
|
||||
handleClick(e)
|
||||
}
|
||||
}}
|
||||
sx={sx}
|
||||
size={size}
|
||||
disabled={
|
||||
currentEpisode.isPending ||
|
||||
(itemType === BaseItemKind.Series &&
|
||||
(!currentEpisode.data ||
|
||||
!currentEpisode.data.Items ||
|
||||
currentEpisode.data.Items.length === 0))
|
||||
}
|
||||
{...buttonProps}
|
||||
>
|
||||
<div
|
||||
className="material-symbols-rounded em-4 fill"
|
||||
style={{
|
||||
fontSize: "3em",
|
||||
}}
|
||||
>
|
||||
play_arrow
|
||||
</div>
|
||||
</Fab>
|
||||
);
|
||||
}
|
||||
|
||||
if (itemType === BaseItemKind.Series) {
|
||||
return (
|
||||
<div
|
||||
className="play-button"
|
||||
@@ -705,7 +719,12 @@ const PlayButton = ({
|
||||
loading={currentEpisode.isPending}
|
||||
className={className ?? "play-button"}
|
||||
variant="contained"
|
||||
onClick={(e) => handleClick(e, currentEpisode.data?.Items?.[0]?.Id)}
|
||||
onClick={(e) => {
|
||||
const episodeId = currentEpisode.data?.Items?.[0]?.Id;
|
||||
if (episodeId) {
|
||||
handleClick(e, episodeId);
|
||||
}
|
||||
}}
|
||||
startIcon={
|
||||
<div
|
||||
className="material-symbols-rounded fill"
|
||||
@@ -725,23 +744,41 @@ const PlayButton = ({
|
||||
//@ts-ignore - white color is a custom color in the theme which mui's types don't know about
|
||||
color="white"
|
||||
size={size}
|
||||
disabled={
|
||||
currentEpisode.isPending ||
|
||||
!currentEpisode.data ||
|
||||
!currentEpisode.data.Items ||
|
||||
currentEpisode.data.Items.length === 0 ||
|
||||
!currentEpisode.data.Items[0].Id
|
||||
}
|
||||
>
|
||||
Watch S{currentEpisode.data?.Items?.[0].ParentIndexNumber ?? 1}E
|
||||
{currentEpisode.data?.Items?.[0]?.IndexNumber ?? 1}
|
||||
{currentEpisode.isPending
|
||||
? "Loading..."
|
||||
: !currentEpisode.data ||
|
||||
!currentEpisode.data.Items ||
|
||||
currentEpisode.data.Items.length === 0
|
||||
? "No episodes to watch found"
|
||||
: (
|
||||
<>
|
||||
Watch S{currentEpisode.data.Items[0].ParentIndexNumber ?? 1}E
|
||||
{currentEpisode.data.Items[0]?.IndexNumber ?? 1}
|
||||
<MemoizedLinearProgress
|
||||
//@ts-ignore
|
||||
value={
|
||||
100 >
|
||||
(currentEpisode.data?.Items?.[0].UserData?.PlayedPercentage ??
|
||||
(currentEpisode.data.Items[0].UserData?.PlayedPercentage ??
|
||||
100) &&
|
||||
(currentEpisode.data?.Items?.[0].UserData?.PlayedPercentage ??
|
||||
(currentEpisode.data.Items[0].UserData?.PlayedPercentage ??
|
||||
0) > 0
|
||||
? currentEpisode.data?.Items?.[0].UserData?.PlayedPercentage
|
||||
? currentEpisode.data.Items[0].UserData?.PlayedPercentage
|
||||
: 0
|
||||
}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</Button>
|
||||
{(currentEpisode.data?.Items?.[0].UserData?.PlaybackPositionTicks ??
|
||||
{(currentEpisode.data?.Items?.[0]?.UserData?.PlaybackPositionTicks ??
|
||||
0) > 0 && (
|
||||
<Typography
|
||||
sx={{
|
||||
@@ -754,8 +791,8 @@ const PlayButton = ({
|
||||
variant="caption"
|
||||
>
|
||||
{getRuntimeCompact(
|
||||
(currentEpisode.data?.Items?.[0].RunTimeTicks ?? 0) -
|
||||
(currentEpisode.data?.Items?.[0].UserData
|
||||
(currentEpisode.data?.Items?.[0]?.RunTimeTicks ?? 0) -
|
||||
(currentEpisode.data?.Items?.[0]?.UserData
|
||||
?.PlaybackPositionTicks ?? 0),
|
||||
)}{" "}
|
||||
left
|
||||
|
||||
Reference in new issue
Block a user