refactor: remove redundant calls for getCurrentUser
This commit is contained in:
35 files changed
+651
-690
No files matched your search
@@ -11,7 +11,6 @@ import useScrollTrigger from "@mui/material/useScrollTrigger";
|
||||
|
||||
import { Link, useLocation, useNavigate } from "@tanstack/react-router";
|
||||
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api";
|
||||
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
@@ -35,6 +34,7 @@ import {
|
||||
ListItemText,
|
||||
} from "@mui/material";
|
||||
import BackButton from "../buttons/backButton";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
interface ListItemLinkProps {
|
||||
icon?: ReactNode;
|
||||
@@ -77,24 +77,16 @@ export const AppBar = () => {
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
const usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
enabled: display && Boolean(api?.accessToken),
|
||||
throwOnError: true,
|
||||
});
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const libraries = useQuery({
|
||||
queryKey: ["libraries"],
|
||||
queryFn: async () => {
|
||||
const libs = await getUserViewsApi(api).getUserViews({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
});
|
||||
return libs.data;
|
||||
},
|
||||
enabled: !!user.data && !!api.accessToken,
|
||||
enabled: !!user?.Id && !!api.accessToken,
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
@@ -179,19 +171,18 @@ export const AppBar = () => {
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row" style={{ gap: "0.6em" }}>
|
||||
<IconButton onClick={() => navigate({ to: "/search" })}>
|
||||
<IconButton
|
||||
onClick={() => navigate({ to: "/search", params: { query: "" } })}
|
||||
>
|
||||
<div className="material-symbols-rounded">search</div>
|
||||
</IconButton>
|
||||
<IconButton onClick={() => navigate({ to: "/favorite" })}>
|
||||
<div className="material-symbols-rounded">favorite</div>
|
||||
</IconButton>
|
||||
<IconButton sx={{ p: 0 }} onClick={handleMenuOpen}>
|
||||
{user.isSuccess &&
|
||||
(user.data.PrimaryImageTag === undefined ? (
|
||||
<Avatar
|
||||
className="appBar-avatar"
|
||||
alt={user.data.Name ?? "image"}
|
||||
>
|
||||
{!!user?.Id &&
|
||||
(user?.PrimaryImageTag === undefined ? (
|
||||
<Avatar className="appBar-avatar" alt={user?.Name ?? "image"}>
|
||||
<span className="material-symbols-rounded appBar-avatar-icon">
|
||||
account_circle
|
||||
</span>
|
||||
@@ -199,8 +190,8 @@ export const AppBar = () => {
|
||||
) : (
|
||||
<Avatar
|
||||
className="appBar-avatar"
|
||||
src={`${api.basePath}/Users/${user.data.Id}/Images/Primary`}
|
||||
alt={user.data.Name ?? "image"}
|
||||
src={`${api.basePath}/Users/${user?.Id}/Images/Primary`}
|
||||
alt={user?.Name ?? "image"}
|
||||
>
|
||||
<span className="material-symbols-rounded appBar-avatar-icon">
|
||||
account_circle
|
||||
@@ -281,12 +272,12 @@ export const AppBar = () => {
|
||||
<List>
|
||||
<ListItemLink to="/home" icon="home" primary="Home" />
|
||||
{libraries.isSuccess &&
|
||||
libraries.data.Items?.map((library, index) => (
|
||||
libraries.data.Items?.map((library) => (
|
||||
<ListItemLink
|
||||
key={library.Id}
|
||||
to={`/library/${library.Id}`}
|
||||
icon={getTypeIcon(library.CollectionType)}
|
||||
primary={library.Name}
|
||||
primary={library.Name ?? "Library"}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
|
||||
@@ -46,7 +46,7 @@ type PlayButtonProps = {
|
||||
item: BaseItemDto;
|
||||
itemId: string;
|
||||
itemUserData: UserItemDataDto;
|
||||
userId: string;
|
||||
userId: string | undefined;
|
||||
itemType: BaseItemKind;
|
||||
currentAudioTrack: number;
|
||||
currentVideoTrack: number;
|
||||
|
||||
@@ -44,6 +44,7 @@ $image-size: 5em;
|
||||
flex-direction: column;
|
||||
gap: 0.2em;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
&-item.Mui-disabled {
|
||||
|
||||
@@ -14,7 +14,6 @@ import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import "./queueButton.scss";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useRouteContext } from "@tanstack/react-router";
|
||||
const QueueButton = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const [queueItems, currentItemIndex] = useQueue((state) => [
|
||||
@@ -29,7 +28,7 @@ const QueueButton = () => {
|
||||
return result.data;
|
||||
},
|
||||
});
|
||||
const [buttonEl, setButtonEl] = useState(null);
|
||||
const [buttonEl, setButtonEl] = useState<HTMLButtonElement | null>(null);
|
||||
|
||||
const handlePlay = useMutation({
|
||||
mutationKey: ["handlePlayIndex"],
|
||||
@@ -76,13 +75,105 @@ const QueueButton = () => {
|
||||
position: "relative",
|
||||
}}
|
||||
>
|
||||
{queueItems[currentItemIndex].Id && (
|
||||
<>
|
||||
<Typography px="1em" mb={2} variant="h5" fontWeight={300}>
|
||||
Currently Playing:
|
||||
</Typography>
|
||||
<MenuItem
|
||||
className="queue-item"
|
||||
disabled
|
||||
key={queueItems[currentItemIndex].Id}
|
||||
>
|
||||
<Typography variant="subtitle2">
|
||||
{queueItems[currentItemIndex]?.Type === "Audio"
|
||||
? currentItemIndex + 1
|
||||
: queueItems[currentItemIndex].IndexNumberEnd
|
||||
? `S${queueItems[currentItemIndex].ParentIndexNumber}:E${queueItems[currentItemIndex].IndexNumber} / ${queueItems[currentItemIndex].IndexNumberEnd}`
|
||||
: `S${queueItems[currentItemIndex].ParentIndexNumber}:E${queueItems[currentItemIndex].IndexNumber}`}
|
||||
</Typography>
|
||||
<div className="queue-item-image-container">
|
||||
{queueItems[currentItemIndex].ImageTags?.Primary ? (
|
||||
<img
|
||||
className="queue-item-image"
|
||||
src={api?.getItemImageUrl(
|
||||
queueItems[currentItemIndex]?.Id,
|
||||
"Primary",
|
||||
{
|
||||
tag: queueItems[currentItemIndex].ImageTags?.Primary,
|
||||
},
|
||||
)}
|
||||
alt={queueItems[currentItemIndex].Name ?? "image"}
|
||||
/>
|
||||
) : (queueItems[currentItemIndex].AlbumPrimaryImageTag
|
||||
?.length ?? -1) > 0 ? (
|
||||
<img
|
||||
className="queue-item-image"
|
||||
src={api?.getItemImageUrl(
|
||||
queueItems[currentItemIndex]?.AlbumId,
|
||||
"Primary",
|
||||
{
|
||||
tag: queueItems[currentItemIndex]
|
||||
.AlbumPrimaryImageTag[0],
|
||||
},
|
||||
)}
|
||||
alt={queueItems[currentItemIndex].Name ?? "image"}
|
||||
/>
|
||||
) : (
|
||||
<div className="queue-item-image-icon">
|
||||
{queueItems[currentItemIndex].Type &&
|
||||
getTypeIcon(queueItems[currentItemIndex].Type)}
|
||||
</div>
|
||||
)}
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translate(-50%,-50%)",
|
||||
fontSize: "2em",
|
||||
"--wght": "100",
|
||||
}}
|
||||
>
|
||||
equalizer
|
||||
</span>
|
||||
</div>
|
||||
<div className="queue-item-info">
|
||||
{queueItems[currentItemIndex].SeriesName ? (
|
||||
<>
|
||||
<Typography variant="subtitle1" width="100%">
|
||||
{queueItems[currentItemIndex].SeriesName}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
width="100%"
|
||||
style={{ opacity: 0.6 }}
|
||||
>
|
||||
{queueItems[currentItemIndex].Name}
|
||||
</Typography>
|
||||
</>
|
||||
) : (
|
||||
<Typography variant="subtitle1" width="100%">
|
||||
{queueItems[currentItemIndex].Name}
|
||||
</Typography>
|
||||
)}
|
||||
</div>
|
||||
</MenuItem>
|
||||
</>
|
||||
)}
|
||||
{queueItems.slice(currentItemIndex + 1, queueItems.length - 1)
|
||||
.length > 0 && (
|
||||
<Typography px="1em" my={2} variant="h5" fontWeight={300}>
|
||||
Queue:
|
||||
</Typography>
|
||||
)}
|
||||
{queueItems
|
||||
.slice(currentItemIndex, queueItems.length - 1)
|
||||
.slice(currentItemIndex + 1, queueItems.length - 1)
|
||||
.map((item, index) => {
|
||||
return (
|
||||
<MenuItem
|
||||
className="queue-item"
|
||||
disabled={index === 0}
|
||||
onClick={() =>
|
||||
handlePlay.mutate({ index: index + currentItemIndex })
|
||||
}
|
||||
@@ -102,41 +193,30 @@ const QueueButton = () => {
|
||||
src={api?.getItemImageUrl(item?.Id, "Primary", {
|
||||
tag: item.ImageTags?.Primary,
|
||||
})}
|
||||
alt={item.Name}
|
||||
alt={item.Name ?? "image"}
|
||||
/>
|
||||
) : item.AlbumPrimaryImageTag?.length > 0 ? (
|
||||
) : (item.AlbumPrimaryImageTag?.length ?? -1) > 0 ? (
|
||||
<img
|
||||
className="queue-item-image"
|
||||
src={api?.getItemImageUrl(item?.AlbumId, "Primary", {
|
||||
tag: item.AlbumPrimaryImageTag[0],
|
||||
})}
|
||||
alt={item.Name}
|
||||
alt={item.Name ?? "image"}
|
||||
/>
|
||||
) : (
|
||||
<div className="queue-item-image-icon">
|
||||
{getTypeIcon(item.Type)}
|
||||
{item.Type && getTypeIcon(item.Type)}
|
||||
</div>
|
||||
)}
|
||||
{index === 0 && (
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translate(-50%,-50%)",
|
||||
fontSize: "2em",
|
||||
"--wght": "100",
|
||||
}}
|
||||
>
|
||||
equalizer
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="queue-item-info">
|
||||
{item.SeriesName ? (
|
||||
<>
|
||||
<Typography variant="subtitle1" width="100%">
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
width="100%"
|
||||
sx={{ overflow: "hidden", textOverflow: "ellipsis" }}
|
||||
>
|
||||
{item.SeriesName}
|
||||
</Typography>
|
||||
<Typography
|
||||
@@ -148,9 +228,23 @@ const QueueButton = () => {
|
||||
</Typography>
|
||||
</>
|
||||
) : (
|
||||
<Typography variant="subtitle1" width="100%">
|
||||
{item.Name}
|
||||
</Typography>
|
||||
<>
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
width="100%"
|
||||
sx={{ overflow: "hidden", textOverflow: "ellipsis" }}
|
||||
>
|
||||
{item.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
width="100%"
|
||||
style={{ opacity: 0.6 }}
|
||||
sx={{ overflow: "hidden", textOverflow: "ellipsis" }}
|
||||
>
|
||||
{item.Artists?.join(", ")}
|
||||
</Typography>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</MenuItem>
|
||||
|
||||
@@ -49,7 +49,7 @@ const CardComponent = ({
|
||||
disableOverlay = false,
|
||||
overrideIcon,
|
||||
}: {
|
||||
item: BaseItemDto | null;
|
||||
item: BaseItemDto;
|
||||
cardTitle: string | undefined | null;
|
||||
cardCaption?: string | null | number;
|
||||
imageType: ImageType;
|
||||
@@ -65,31 +65,33 @@ const CardComponent = ({
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const navigate = useNavigate();
|
||||
const defaultOnClick = () => {
|
||||
switch (item.Type) {
|
||||
case BaseItemKind.BoxSet:
|
||||
navigate({ to: "/boxset/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Episode:
|
||||
navigate({ to: "/episode/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicAlbum:
|
||||
navigate({ to: "/album/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicArtist:
|
||||
navigate({ to: "/artist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Person:
|
||||
navigate({ to: "/person/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Series:
|
||||
navigate({ to: "/series/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Playlist:
|
||||
navigate({ to: "/playlist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
default:
|
||||
navigate({ to: "/item/$id", params: { id: item.Id } });
|
||||
break;
|
||||
if (item?.Id) {
|
||||
switch (item?.Type) {
|
||||
case BaseItemKind.BoxSet:
|
||||
navigate({ to: "/boxset/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Episode:
|
||||
navigate({ to: "/episode/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicAlbum:
|
||||
navigate({ to: "/album/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicArtist:
|
||||
navigate({ to: "/artist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Person:
|
||||
navigate({ to: "/person/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Series:
|
||||
navigate({ to: "/series/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Playlist:
|
||||
navigate({ to: "/playlist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
default:
|
||||
navigate({ to: "/item/$id", params: { id: item.Id } });
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -129,7 +131,7 @@ const CardComponent = ({
|
||||
overrideIcon === "User"
|
||||
? `${api.basePath}/Users/${item.Id}/Images/Primary`
|
||||
: api.getItemImageUrl(
|
||||
seriesId ? item.SeriesId : item.AlbumId ?? item.Id,
|
||||
seriesId ? item.SeriesId : (item.AlbumId ?? item.Id),
|
||||
imageType,
|
||||
{
|
||||
quality: 90,
|
||||
|
||||
@@ -53,8 +53,6 @@ export const CardScroller = ({
|
||||
},
|
||||
};
|
||||
|
||||
const [carouselRef, setCarouselRef] = useState();
|
||||
|
||||
return (
|
||||
<Box {...boxProps} className="card-scroller-container" mb={1}>
|
||||
<Box
|
||||
@@ -79,7 +77,7 @@ export const CardScroller = ({
|
||||
draggable
|
||||
responsive={responsive}
|
||||
arrows
|
||||
ref={(el) => setCarouselRef(el)}
|
||||
rtl={false}
|
||||
className="card-scroller"
|
||||
customTransition="all .6s"
|
||||
transitionDuration={600}
|
||||
|
||||
@@ -13,7 +13,6 @@ import { yellow } from "@mui/material/colors";
|
||||
|
||||
import { endsAt, getRuntime } from "@/utils/date/time";
|
||||
import { green, red } from "@mui/material/colors";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { getTypeIcon } from "../utils/iconsCollection";
|
||||
|
||||
@@ -23,66 +22,45 @@ import {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import LikeButton from "../buttons/likeButton";
|
||||
import MarkPlayedButton from "../buttons/markPlayedButton";
|
||||
import PlayButton from "../buttons/playButton";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
const availableSpecialRoutes = [
|
||||
BaseItemKind.Series,
|
||||
BaseItemKind.BoxSet,
|
||||
BaseItemKind.MusicAlbum,
|
||||
];
|
||||
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import("@jellyfin/sdk/lib/generated-client/models").BaseItemDto} item
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description Carousel slide component
|
||||
* @param {Props}
|
||||
* @returns {React.Component}
|
||||
*/
|
||||
const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
const usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const handleMoreInfo = () => {
|
||||
switch (item.Type) {
|
||||
case BaseItemKind.BoxSet:
|
||||
navigate({ to: "/boxset/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Episode:
|
||||
navigate({ to: "/episode/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicAlbum:
|
||||
navigate({ to: "/album/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicArtist:
|
||||
navigate({ to: "/artist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Person:
|
||||
navigate({ to: "/person/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Series:
|
||||
navigate({ to: "/series/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Playlist:
|
||||
navigate({ to: "/playlist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
default:
|
||||
navigate({ to: "/item/$id", params: { id: item.Id } });
|
||||
break;
|
||||
if (item.Id) {
|
||||
switch (item.Type) {
|
||||
case BaseItemKind.BoxSet:
|
||||
navigate({ to: "/boxset/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Episode:
|
||||
navigate({ to: "/episode/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicAlbum:
|
||||
navigate({ to: "/album/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicArtist:
|
||||
navigate({ to: "/artist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Person:
|
||||
navigate({ to: "/person/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Series:
|
||||
navigate({ to: "/series/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Playlist:
|
||||
navigate({ to: "/playlist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
default:
|
||||
navigate({ to: "/item/$id", params: { id: item.Id } });
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -100,7 +78,7 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
<div className="hero-carousel-background-container">
|
||||
{item.BackdropImageTags?.length ? (
|
||||
<img
|
||||
alt={item.Name}
|
||||
alt={item.Name ?? "item"}
|
||||
className="hero-carousel-background-image"
|
||||
src={
|
||||
item.ParentBackdropItemId
|
||||
@@ -155,7 +133,7 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
fontWeight={200}
|
||||
overflow="visible"
|
||||
>
|
||||
{!item.ImageTags.Logo ? (
|
||||
{!item.ImageTags?.Logo ? (
|
||||
item.Name
|
||||
) : (
|
||||
<img
|
||||
@@ -336,7 +314,7 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
<PlayButton
|
||||
item={item}
|
||||
itemId={item.Id}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
itemType={item.Type}
|
||||
currentAudioTrack={0}
|
||||
currentSubTrack={0}
|
||||
@@ -377,15 +355,15 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
||||
<LikeButton
|
||||
itemId={item.Id}
|
||||
queryKey={["home", "latestMedia"]}
|
||||
userId={user.data.Id}
|
||||
isFavorite={item.UserData.IsFavorite}
|
||||
userId={user?.Id}
|
||||
isFavorite={item.UserData?.IsFavorite}
|
||||
itemName={item.Name}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemId={item.Id}
|
||||
queryKey={["home", "latestMedia"]}
|
||||
userId={user.data.Id}
|
||||
isPlayed={item.UserData.Played}
|
||||
userId={user?.Id}
|
||||
isPlayed={item.UserData?.Played}
|
||||
itemName={item.Name}
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
/**
|
||||
* @description Latest Media Section
|
||||
@@ -19,17 +20,10 @@ export const LatestMediaSection = ({
|
||||
latestMediaLib,
|
||||
}: { latestMediaLib: BaseItemDto }) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
const usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const fetchLatestMedia = async (library: BaseItemDto) => {
|
||||
const media = await getUserLibraryApi(api).getLatestMedia({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
parentId: library.Id,
|
||||
limit: 16,
|
||||
fields: ["PrimaryImageAspectRatio"],
|
||||
@@ -39,7 +33,7 @@ export const LatestMediaSection = ({
|
||||
const data = useQuery({
|
||||
queryKey: ["home", "latestMedia", latestMediaLib.Id],
|
||||
queryFn: () => fetchLatestMedia(latestMediaLib),
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
refetchOnMount: true,
|
||||
});
|
||||
if (data.isPending) {
|
||||
@@ -80,7 +74,7 @@ export const LatestMediaSection = ({
|
||||
: "portrait"
|
||||
}
|
||||
queryKey={["home", "latestMedia", latestMediaLib.Id]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import Box from "@mui/material/Box";
|
||||
import Button from "@mui/material/Button";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { red } from "@mui/material/colors";
|
||||
import React from "react";
|
||||
|
||||
export const ErrorNotice = ({ error }: { error?: unknown }) => {
|
||||
console.log(error);
|
||||
export const ErrorNotice = ({ error }: { error?: Error }) => {
|
||||
console.error(error);
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@@ -23,14 +22,15 @@ export const ErrorNotice = ({ error }: { error?: unknown }) => {
|
||||
style={{
|
||||
fontSize: "10em",
|
||||
color: red[800],
|
||||
//@ts-ignore
|
||||
"--clr": "rgb(198 40 40 / 30%)",
|
||||
fontVariationSettings: '"FILL" 1, "wght" 400, "GRAD" 25, "opsz" 60',
|
||||
}}
|
||||
>
|
||||
error
|
||||
</div>
|
||||
<Typography variant="h3" fontWeight={300}>
|
||||
Something went wrong
|
||||
<Typography variant="h3" color="white" fontWeight={300}>
|
||||
Something went wrong.
|
||||
</Typography>
|
||||
<Typography
|
||||
fontFamily="JetBrains Mono Variable"
|
||||
@@ -45,8 +45,9 @@ export const ErrorNotice = ({ error }: { error?: unknown }) => {
|
||||
marginTop: "1em",
|
||||
// opacity: 0.6,
|
||||
}}
|
||||
color="gray"
|
||||
>
|
||||
{JSON.stringify(error.message)}
|
||||
{JSON.stringify(error?.message)}
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
import React, {
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import { motion } from "framer-motion";
|
||||
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import Fab from "@mui/material/Fab";
|
||||
import Grow from "@mui/material/Grow";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Paper from "@mui/material/Paper";
|
||||
import Popper from "@mui/material/Popper";
|
||||
import Slider from "@mui/material/Slider";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import WaveSurfer from "wavesurfer.js";
|
||||
|
||||
import { setAudioRef, useAudioPlayback } from "@/utils/store/audioPlayback";
|
||||
import useQueue from "@/utils/store/queue";
|
||||
|
||||
@@ -26,14 +14,16 @@ import { AnimatePresence } from "framer-motion";
|
||||
import "./audioPlayer.scss";
|
||||
|
||||
import { getRuntimeMusic, secToTicks, ticksToSec } from "@/utils/date/time";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import PlayNextButton from "@/components/buttons/playNextButton";
|
||||
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
||||
import QueueButton from "@/components/buttons/queueButton";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useNavigate, useRouteContext } from "@tanstack/react-router";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { playItemFromQueue } from "@/utils/store/playback";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
const AudioPlayer = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
@@ -49,17 +39,7 @@ const AudioPlayer = () => {
|
||||
state.currentItemIndex,
|
||||
]);
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
const usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
enabled: Boolean(display) && Boolean(api),
|
||||
});
|
||||
|
||||
const waveSurferContainerRef = useRef(null);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const playing = useMemo(() => {
|
||||
if (audioRef.current?.paused) return false;
|
||||
@@ -70,7 +50,7 @@ const AudioPlayer = () => {
|
||||
const [isMuted, setIsMuted] = useState(false);
|
||||
const [progress, setProgress] = useState(0);
|
||||
const [isScrubbing, setIsScrubbing] = useState(false);
|
||||
const [sliderProgress, setSliderProgress] = useState(false);
|
||||
const [sliderProgress, setSliderProgress] = useState(0);
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
@@ -113,7 +93,7 @@ const AudioPlayer = () => {
|
||||
>
|
||||
<div className="audio-player-image-container">
|
||||
<img
|
||||
alt={tracks[currentTrack]?.Name}
|
||||
alt={tracks[currentTrack]?.Name ?? "track"}
|
||||
className="audio-player-image"
|
||||
src={api?.getItemImageUrl(
|
||||
!item?.ImageTags.Primary ? item?.AlbumId : item?.Id,
|
||||
@@ -145,7 +125,7 @@ const AudioPlayer = () => {
|
||||
}}
|
||||
noWrap
|
||||
>
|
||||
by {item?.Artists.map((artist) => artist).join(",")}
|
||||
by {item?.Artists?.map((artist) => artist).join(",")}
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
@@ -215,8 +195,10 @@ const AudioPlayer = () => {
|
||||
value={isMuted ? 0 : volume * 100}
|
||||
step={1}
|
||||
max={100}
|
||||
onChange={(e, newVal) => {
|
||||
setVolume(newVal / 100);
|
||||
onChange={(_, newVal) => {
|
||||
Array.isArray(newVal)
|
||||
? setVolume(newVal[0] / 100)
|
||||
: setVolume(newVal / 100);
|
||||
audioRef.current.volume = newVal / 100;
|
||||
}}
|
||||
valueLabelDisplay="auto"
|
||||
@@ -260,6 +242,14 @@ const AudioPlayer = () => {
|
||||
[volume, isMuted, currentTrack],
|
||||
);
|
||||
|
||||
if (audioRef.current) {
|
||||
audioRef.current.addEventListener("ended", () => {
|
||||
if (tracks[currentTrack + 1]?.Id) {
|
||||
playItemFromQueue("next", user?.Id, api);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<AnimatePresence mode="sync">
|
||||
{display && (
|
||||
@@ -319,12 +309,14 @@ const AudioPlayer = () => {
|
||||
value={isScrubbing ? sliderProgress : progress}
|
||||
step={1}
|
||||
size="small"
|
||||
max={item?.RunTimeTicks}
|
||||
onChange={(e, value) => {
|
||||
max={item?.RunTimeTicks ?? 1}
|
||||
onChange={(_, value) => {
|
||||
setIsScrubbing(true);
|
||||
setSliderProgress(value);
|
||||
Array.isArray(value)
|
||||
? setSliderProgress(value[0])
|
||||
: setSliderProgress(value);
|
||||
}}
|
||||
onChangeCommitted={(e, value) => {
|
||||
onChangeCommitted={(_, value) => {
|
||||
setIsScrubbing(false);
|
||||
// console.log(ticksToSec(value * item?.RunTimeTicks));
|
||||
setProgress(value);
|
||||
|
||||
@@ -2,7 +2,11 @@ import Button from "@mui/material/Button";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
const ShowMoreText = ({ content, collapsedLines, extraProps }) => {
|
||||
const ShowMoreText = ({
|
||||
content,
|
||||
collapsedLines,
|
||||
extraProps,
|
||||
}: { content: string; collapsedLines: number; extraProps?: unknown }) => {
|
||||
const [displayFull, setDisplayFull] = useState(false);
|
||||
const [isOverflowing, setIsOverflowing] = useState(false);
|
||||
const textRef = useRef(null);
|
||||
@@ -34,7 +38,7 @@ const ShowMoreText = ({ content, collapsedLines, extraProps }) => {
|
||||
display: "-webkit-box",
|
||||
textOverflow: "ellipsis",
|
||||
overflow: "hidden",
|
||||
WebkitLineClamp: displayFull ? "none" : collapsedLines ?? 2,
|
||||
WebkitLineClamp: displayFull ? "none" : (collapsedLines ?? 2),
|
||||
WebkitBoxOrient: "vertical",
|
||||
width: "100%",
|
||||
}}
|
||||
+28
-11
@@ -1,9 +1,9 @@
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import {
|
||||
RouterProvider,
|
||||
createRouteMask,
|
||||
createRouter,
|
||||
} from "@tanstack/react-router";
|
||||
QueryClient,
|
||||
QueryClientProvider,
|
||||
useQuery,
|
||||
} from "@tanstack/react-query";
|
||||
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
||||
import React, { Suspense } from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
// Import the generated route tree
|
||||
@@ -25,6 +25,7 @@ const router = createRouter({
|
||||
createApi: undefined!,
|
||||
user: undefined,
|
||||
jellyfinSDK: undefined!,
|
||||
fetchCurrentUser: undefined!,
|
||||
},
|
||||
defaultPreload: "intent",
|
||||
});
|
||||
@@ -37,6 +38,10 @@ declare module "@tanstack/react-router" {
|
||||
}
|
||||
|
||||
import { ApiProvider, useApiInContext } from "./utils/store/api";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { ErrorBoundary } from "react-error-boundary";
|
||||
import { ErrorNotice } from "./components/notices/errorNotice/errorNotice";
|
||||
import { CentralProvider, useCentralStore } from "./utils/store/central";
|
||||
|
||||
export const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -55,8 +60,16 @@ function ProviderWrapper() {
|
||||
s.createApi,
|
||||
s.jellyfin,
|
||||
]);
|
||||
const [user, fetchCurrentUser] = useCentralStore((s) => [
|
||||
s.currentUser,
|
||||
s.fetchCurrentUser,
|
||||
]);
|
||||
if (api?.accessToken) fetchCurrentUser(api);
|
||||
return (
|
||||
<RouterProvider router={router} context={{ api, createApi, jellyfinSDK }} />
|
||||
<RouterProvider
|
||||
router={router}
|
||||
context={{ api, createApi, user, jellyfinSDK, fetchCurrentUser }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,11 +77,15 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||
<React.StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
{/* TODO: Create a proper loading fallback component */}
|
||||
<Suspense fallback={<h1>Loading in main.tsx</h1>}>
|
||||
<ApiProvider>
|
||||
<ProviderWrapper />
|
||||
</ApiProvider>
|
||||
</Suspense>
|
||||
<ErrorBoundary FallbackComponent={ErrorNotice}>
|
||||
<Suspense fallback={<h1>Loading in main.tsx</h1>}>
|
||||
<CentralProvider>
|
||||
<ApiProvider>
|
||||
<ProviderWrapper />
|
||||
</ApiProvider>
|
||||
</CentralProvider>
|
||||
</Suspense>
|
||||
</ErrorBoundary>
|
||||
</QueryClientProvider>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
|
||||
+8
-46
@@ -16,7 +16,6 @@ import { Route as IndexImport } from './routes/index'
|
||||
import { Route as ErrorCodeImport } from './routes/error/$code'
|
||||
import { Route as ApiSearchImport } from './routes/_api/search'
|
||||
import { Route as ApiLoginImport } from './routes/_api/login'
|
||||
import { Route as ApiLibraryImport } from './routes/_api/library'
|
||||
import { Route as ApiSearchIndexImport } from './routes/_api/search/index'
|
||||
import { Route as ApiPlayerIndexImport } from './routes/_api/player/index'
|
||||
import { Route as ApiHomeIndexImport } from './routes/_api/home/index'
|
||||
@@ -65,11 +64,6 @@ const ApiLoginRoute = ApiLoginImport.update({
|
||||
getParentRoute: () => ApiRoute,
|
||||
} as any)
|
||||
|
||||
const ApiLibraryRoute = ApiLibraryImport.update({
|
||||
path: '/library',
|
||||
getParentRoute: () => ApiRoute,
|
||||
} as any)
|
||||
|
||||
const ApiSearchIndexRoute = ApiSearchIndexImport.update({
|
||||
path: '/',
|
||||
getParentRoute: () => ApiSearchRoute,
|
||||
@@ -136,8 +130,8 @@ const ApiLoginListRoute = ApiLoginListImport.update({
|
||||
} as any)
|
||||
|
||||
const ApiLibraryIdRoute = ApiLibraryIdImport.update({
|
||||
path: '/$id',
|
||||
getParentRoute: () => ApiLibraryRoute,
|
||||
path: '/library/$id',
|
||||
getParentRoute: () => ApiRoute,
|
||||
} as any)
|
||||
|
||||
const ApiItemIdRoute = ApiItemIdImport.update({
|
||||
@@ -188,13 +182,6 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof ApiImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/_api/library': {
|
||||
id: '/_api/library'
|
||||
path: '/library'
|
||||
fullPath: '/library'
|
||||
preLoaderRoute: typeof ApiLibraryImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/login': {
|
||||
id: '/_api/login'
|
||||
path: '/login'
|
||||
@@ -253,10 +240,10 @@ declare module '@tanstack/react-router' {
|
||||
}
|
||||
'/_api/library/$id': {
|
||||
id: '/_api/library/$id'
|
||||
path: '/$id'
|
||||
path: '/library/$id'
|
||||
fullPath: '/library/$id'
|
||||
preLoaderRoute: typeof ApiLibraryIdImport
|
||||
parentRoute: typeof ApiLibraryImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/login/list': {
|
||||
id: '/_api/login/list'
|
||||
@@ -361,18 +348,6 @@ declare module '@tanstack/react-router' {
|
||||
|
||||
// Create and export the route tree
|
||||
|
||||
interface ApiLibraryRouteChildren {
|
||||
ApiLibraryIdRoute: typeof ApiLibraryIdRoute
|
||||
}
|
||||
|
||||
const ApiLibraryRouteChildren: ApiLibraryRouteChildren = {
|
||||
ApiLibraryIdRoute: ApiLibraryIdRoute,
|
||||
}
|
||||
|
||||
const ApiLibraryRouteWithChildren = ApiLibraryRoute._addFileChildren(
|
||||
ApiLibraryRouteChildren,
|
||||
)
|
||||
|
||||
interface ApiLoginRouteChildren {
|
||||
ApiLoginListRoute: typeof ApiLoginListRoute
|
||||
ApiLoginManualRoute: typeof ApiLoginManualRoute
|
||||
@@ -402,7 +377,6 @@ const ApiSearchRouteWithChildren = ApiSearchRoute._addFileChildren(
|
||||
)
|
||||
|
||||
interface ApiRouteChildren {
|
||||
ApiLibraryRoute: typeof ApiLibraryRouteWithChildren
|
||||
ApiLoginRoute: typeof ApiLoginRouteWithChildren
|
||||
ApiSearchRoute: typeof ApiSearchRouteWithChildren
|
||||
ApiAlbumIdRoute: typeof ApiAlbumIdRoute
|
||||
@@ -410,6 +384,7 @@ interface ApiRouteChildren {
|
||||
ApiBoxsetIdRoute: typeof ApiBoxsetIdRoute
|
||||
ApiEpisodeIdRoute: typeof ApiEpisodeIdRoute
|
||||
ApiItemIdRoute: typeof ApiItemIdRoute
|
||||
ApiLibraryIdRoute: typeof ApiLibraryIdRoute
|
||||
ApiPersonIdRoute: typeof ApiPersonIdRoute
|
||||
ApiPlayerAudioRoute: typeof ApiPlayerAudioRoute
|
||||
ApiPlaylistIdRoute: typeof ApiPlaylistIdRoute
|
||||
@@ -420,7 +395,6 @@ interface ApiRouteChildren {
|
||||
}
|
||||
|
||||
const ApiRouteChildren: ApiRouteChildren = {
|
||||
ApiLibraryRoute: ApiLibraryRouteWithChildren,
|
||||
ApiLoginRoute: ApiLoginRouteWithChildren,
|
||||
ApiSearchRoute: ApiSearchRouteWithChildren,
|
||||
ApiAlbumIdRoute: ApiAlbumIdRoute,
|
||||
@@ -428,6 +402,7 @@ const ApiRouteChildren: ApiRouteChildren = {
|
||||
ApiBoxsetIdRoute: ApiBoxsetIdRoute,
|
||||
ApiEpisodeIdRoute: ApiEpisodeIdRoute,
|
||||
ApiItemIdRoute: ApiItemIdRoute,
|
||||
ApiLibraryIdRoute: ApiLibraryIdRoute,
|
||||
ApiPersonIdRoute: ApiPersonIdRoute,
|
||||
ApiPlayerAudioRoute: ApiPlayerAudioRoute,
|
||||
ApiPlaylistIdRoute: ApiPlaylistIdRoute,
|
||||
@@ -442,7 +417,6 @@ const ApiRouteWithChildren = ApiRoute._addFileChildren(ApiRouteChildren)
|
||||
export interface FileRoutesByFullPath {
|
||||
'/': typeof IndexRoute
|
||||
'': typeof ApiRouteWithChildren
|
||||
'/library': typeof ApiLibraryRouteWithChildren
|
||||
'/login': typeof ApiLoginRouteWithChildren
|
||||
'/search': typeof ApiSearchRouteWithChildren
|
||||
'/error/$code': typeof ErrorCodeRoute
|
||||
@@ -471,7 +445,6 @@ export interface FileRoutesByFullPath {
|
||||
export interface FileRoutesByTo {
|
||||
'/': typeof IndexRoute
|
||||
'': typeof ApiRouteWithChildren
|
||||
'/library': typeof ApiLibraryRouteWithChildren
|
||||
'/login': typeof ApiLoginRouteWithChildren
|
||||
'/error/$code': typeof ErrorCodeRoute
|
||||
'/album/$id': typeof ApiAlbumIdRoute
|
||||
@@ -500,7 +473,6 @@ export interface FileRoutesById {
|
||||
__root__: typeof rootRoute
|
||||
'/': typeof IndexRoute
|
||||
'/_api': typeof ApiRouteWithChildren
|
||||
'/_api/library': typeof ApiLibraryRouteWithChildren
|
||||
'/_api/login': typeof ApiLoginRouteWithChildren
|
||||
'/_api/search': typeof ApiSearchRouteWithChildren
|
||||
'/error/$code': typeof ErrorCodeRoute
|
||||
@@ -531,7 +503,6 @@ export interface FileRouteTypes {
|
||||
fullPaths:
|
||||
| '/'
|
||||
| ''
|
||||
| '/library'
|
||||
| '/login'
|
||||
| '/search'
|
||||
| '/error/$code'
|
||||
@@ -559,7 +530,6 @@ export interface FileRouteTypes {
|
||||
to:
|
||||
| '/'
|
||||
| ''
|
||||
| '/library'
|
||||
| '/login'
|
||||
| '/error/$code'
|
||||
| '/album/$id'
|
||||
@@ -586,7 +556,6 @@ export interface FileRouteTypes {
|
||||
| '__root__'
|
||||
| '/'
|
||||
| '/_api'
|
||||
| '/_api/library'
|
||||
| '/_api/login'
|
||||
| '/_api/search'
|
||||
| '/error/$code'
|
||||
@@ -657,7 +626,6 @@ export const routeTree = rootRoute
|
||||
"/_api": {
|
||||
"filePath": "_api.tsx",
|
||||
"children": [
|
||||
"/_api/library",
|
||||
"/_api/login",
|
||||
"/_api/search",
|
||||
"/_api/album/$id",
|
||||
@@ -665,6 +633,7 @@ export const routeTree = rootRoute
|
||||
"/_api/boxset/$id",
|
||||
"/_api/episode/$id",
|
||||
"/_api/item/$id",
|
||||
"/_api/library/$id",
|
||||
"/_api/person/$id",
|
||||
"/_api/player/audio",
|
||||
"/_api/playlist/$id",
|
||||
@@ -674,13 +643,6 @@ export const routeTree = rootRoute
|
||||
"/_api/player/"
|
||||
]
|
||||
},
|
||||
"/_api/library": {
|
||||
"filePath": "_api/library.tsx",
|
||||
"parent": "/_api",
|
||||
"children": [
|
||||
"/_api/library/$id"
|
||||
]
|
||||
},
|
||||
"/_api/login": {
|
||||
"filePath": "_api/login.tsx",
|
||||
"parent": "/_api",
|
||||
@@ -722,7 +684,7 @@ export const routeTree = rootRoute
|
||||
},
|
||||
"/_api/library/$id": {
|
||||
"filePath": "_api/library/$id.tsx",
|
||||
"parent": "/_api/library"
|
||||
"parent": "/_api"
|
||||
},
|
||||
"/_api/login/list": {
|
||||
"filePath": "_api/login/list.tsx",
|
||||
|
||||
@@ -48,15 +48,17 @@ import type { UserDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||
import { DndProvider } from "react-dnd";
|
||||
import { HTML5Backend } from "react-dnd-html5-backend";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
|
||||
type ApiContext = {
|
||||
api: Api;
|
||||
createApi: (
|
||||
serverAddress: string | undefined,
|
||||
accessToken: string | undefined,
|
||||
serverAddress: string | undefined | null,
|
||||
accessToken: string | undefined | null,
|
||||
) => void;
|
||||
user: UserDto | null | undefined;
|
||||
jellyfinSDK: Jellyfin;
|
||||
fetchCurrentUser: (api: Api | undefined) => Promise<void>;
|
||||
};
|
||||
|
||||
export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
@@ -264,11 +266,12 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
<AudioPlayer />
|
||||
<Outlet />
|
||||
<ReactQueryDevtools />
|
||||
{/* <TanStackRouterDevtools /> */}
|
||||
<TanStackRouterDevtools />
|
||||
</SnackbarProvider>
|
||||
</ThemeProvider>
|
||||
</Suspense>
|
||||
</DndProvider>
|
||||
);
|
||||
},
|
||||
errorComponent: ErrorNotice,
|
||||
});
|
||||
+44
-47
@@ -1,70 +1,67 @@
|
||||
import { getDefaultServer, getServer } from "@/utils/storage/servers";
|
||||
import { getUser } from "@/utils/storage/user";
|
||||
import { axiosClient } from "@/utils/store/api";
|
||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
import { createFileRoute, redirect, useRouter } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createFileRoute("/_api")({
|
||||
beforeLoad: async ({ context, location }) => {
|
||||
// console.log(context.api);
|
||||
console.log(context.user);
|
||||
if (!context.api) {
|
||||
const currentServerId = await getDefaultServer();
|
||||
if (currentServerId) {
|
||||
const currentServer = await getServer(currentServerId);
|
||||
const apiTemp = context.jellyfinSDK.createApi(
|
||||
currentServer?.address,
|
||||
null,
|
||||
axiosClient,
|
||||
);
|
||||
try {
|
||||
await getSystemApi(apiTemp).getPingSystem();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw redirect({
|
||||
to: "/error/$code",
|
||||
params: {
|
||||
code: "101",
|
||||
},
|
||||
});
|
||||
}
|
||||
const userOnDisk = await getUser();
|
||||
if (userOnDisk) {
|
||||
if (location.pathname !== "/login/manual") {
|
||||
const apiTemp = context.jellyfinSDK.createApi(
|
||||
currentServer?.address,
|
||||
userOnDisk.AccessToken,
|
||||
);
|
||||
try {
|
||||
await getUserApi(apiTemp).getCurrentUser();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw redirect({
|
||||
to: "/login/manual",
|
||||
search: {
|
||||
redirect: location.href,
|
||||
},
|
||||
});
|
||||
}
|
||||
// return { api: apiTemp };
|
||||
}
|
||||
context.createApi(currentServer?.address, userOnDisk.AccessToken);
|
||||
} else {
|
||||
if (currentServer?.address) {
|
||||
const apiTemp = context.jellyfinSDK.createApi(
|
||||
currentServer?.address,
|
||||
null,
|
||||
undefined,
|
||||
);
|
||||
context.createApi(currentServer?.address, undefined); // Creates Api
|
||||
// return { api: apiTemp };
|
||||
try {
|
||||
await getSystemApi(apiTemp).getPingSystem();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw redirect({
|
||||
to: "/error/$code",
|
||||
params: {
|
||||
code: "101",
|
||||
},
|
||||
});
|
||||
}
|
||||
const userOnDisk = await getUser();
|
||||
if (userOnDisk) {
|
||||
if (location.pathname !== "/login/manual") {
|
||||
const apiTemp = context.jellyfinSDK.createApi(
|
||||
currentServer?.address,
|
||||
userOnDisk.AccessToken,
|
||||
);
|
||||
try {
|
||||
const user = await getUserApi(apiTemp).getCurrentUser();
|
||||
// return { user: user.data };
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw redirect({
|
||||
to: "/login/manual",
|
||||
search: {
|
||||
redirect: location.href,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
context.createApi(currentServer?.address, userOnDisk.AccessToken);
|
||||
} else {
|
||||
context.jellyfinSDK.createApi(currentServer?.address, undefined);
|
||||
context.createApi(currentServer?.address, undefined); // Creates Api
|
||||
|
||||
// return { api: apiTemp };
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (context.api) {
|
||||
if (context.api.accessToken && location.pathname !== "/login/manual") {
|
||||
try {
|
||||
return {
|
||||
user: await getUserApi(context.api).getCurrentUser(),
|
||||
}; // Verify user is able to authenticate
|
||||
await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw redirect({
|
||||
|
||||
@@ -52,6 +52,7 @@ import "./album.scss";
|
||||
import TagChip from "@/components/tagChip";
|
||||
import { Link, createFileRoute } from "@tanstack/react-router";
|
||||
import lyricsIcon from "../../../assets/icons/lyrics.svg";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
@@ -91,26 +92,18 @@ function MusicAlbumTitlePage() {
|
||||
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 user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const item = useQuery({
|
||||
queryKey: ["item", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
itemId: id,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
networkMode: "always",
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
@@ -119,7 +112,7 @@ function MusicAlbumTitlePage() {
|
||||
queryKey: ["item", id, "similarItem"],
|
||||
queryFn: async () => {
|
||||
const result = await getLibraryApi(api).getSimilarAlbums({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
itemId: item.data?.Id,
|
||||
limit: 16,
|
||||
});
|
||||
@@ -134,7 +127,7 @@ function MusicAlbumTitlePage() {
|
||||
queryKey: ["item", "musicTracks", id],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
parentId: item.data?.Id,
|
||||
sortOrder: [SortOrder.Ascending],
|
||||
sortBy: ["IndexNumber"],
|
||||
@@ -170,7 +163,7 @@ function MusicAlbumTitlePage() {
|
||||
) => {
|
||||
const url = generateAudioStreamUrl(
|
||||
item.Id,
|
||||
user.data?.Id,
|
||||
user?.Id,
|
||||
api.deviceInfo.id,
|
||||
api.basePath,
|
||||
);
|
||||
@@ -235,13 +228,13 @@ function MusicAlbumTitlePage() {
|
||||
item={item}
|
||||
audio
|
||||
itemType={item.data.Type}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<LikeButton
|
||||
itemId={item.data.Id}
|
||||
isFavorite={item.data.UserData?.IsFavorite}
|
||||
queryKey={["item", "musicTracks"]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
itemName={item.data.Name}
|
||||
/>
|
||||
</div>
|
||||
@@ -295,7 +288,7 @@ function MusicAlbumTitlePage() {
|
||||
itemId={track.Id}
|
||||
isFavorite={track.UserData?.IsFavorite}
|
||||
queryKey={["item", "musicTracks"]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
itemName={track.Name}
|
||||
/>
|
||||
</div>
|
||||
@@ -352,13 +345,13 @@ function MusicAlbumTitlePage() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{similarItems.data.TotalRecordCount > 0 && (
|
||||
{(similarItems.data.TotalRecordCount ?? -1) > 0 && (
|
||||
<CardScroller
|
||||
title="You might also like"
|
||||
displayCards={7}
|
||||
disableDecoration
|
||||
>
|
||||
{similarItems.data.Items.map((similar) => {
|
||||
{similarItems.data.Items?.map((similar) => {
|
||||
return (
|
||||
<Card
|
||||
key={similar.Id}
|
||||
@@ -390,13 +383,7 @@ function MusicAlbumTitlePage() {
|
||||
: "portrait"
|
||||
}
|
||||
queryKey={["item", id, "similarItem"]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!similar.ImageBlurHashes?.Primary &&
|
||||
similar.ImageBlurHashes?.Primary[
|
||||
Object.keys(similar.ImageBlurHashes.Primary)[0]
|
||||
]
|
||||
}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -37,6 +37,7 @@ import "./artist.scss";
|
||||
import IconLink from "@/components/iconLink";
|
||||
import { getTypeIcon } from "@/components/utils/iconsCollection";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
@@ -69,26 +70,19 @@ function ArtistTitlePage() {
|
||||
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",
|
||||
});
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const item = useQuery({
|
||||
queryKey: ["item", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: id,
|
||||
fields: [ItemFields.Crew],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
networkMode: "always",
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
@@ -102,7 +96,7 @@ function ArtistTitlePage() {
|
||||
sortOrder: [SortOrder.Descending],
|
||||
recursive: true,
|
||||
includeItemTypes: [BaseItemKind.MusicAlbum],
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
fields: [ItemFields.Overview],
|
||||
});
|
||||
return result.data;
|
||||
@@ -119,7 +113,7 @@ function ArtistTitlePage() {
|
||||
sortOrder: [SortOrder.Ascending],
|
||||
recursive: true,
|
||||
includeItemTypes: [BaseItemKind.Audio],
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
fields: [ItemFields.Overview],
|
||||
});
|
||||
return result.data;
|
||||
@@ -137,7 +131,7 @@ function ArtistTitlePage() {
|
||||
sortOrder: [SortOrder.Descending],
|
||||
recursive: true,
|
||||
includeItemTypes: [BaseItemKind.MusicAlbum],
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
@@ -295,8 +289,8 @@ function ArtistTitlePage() {
|
||||
itemName={item.data.Name}
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isFavorite={item.data.UserData.IsFavorite}
|
||||
userId={user.data.Id}
|
||||
isFavorite={item.data.UserData?.IsFavorite}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -314,7 +308,7 @@ function ArtistTitlePage() {
|
||||
marginTop: "1em",
|
||||
}}
|
||||
>
|
||||
{item.data.ExternalUrls.map((url) => (
|
||||
{item.data.ExternalUrls?.map((url) => (
|
||||
<IconLink url={url.Url} name={url.Name} />
|
||||
))}
|
||||
</div>
|
||||
@@ -358,7 +352,7 @@ function ArtistTitlePage() {
|
||||
setActiveArtistTab(newVal);
|
||||
}}
|
||||
>
|
||||
{artistTabs.map((tab, index) => {
|
||||
{artistTabs.map((tab) => {
|
||||
return (
|
||||
<Tab
|
||||
key={tab.title}
|
||||
@@ -391,11 +385,11 @@ function ArtistTitlePage() {
|
||||
}}
|
||||
>
|
||||
{artistDiscography.isSuccess &&
|
||||
artistDiscography.data.Items.map((tabitem) => {
|
||||
artistDiscography.data.Items?.map((tabitem) => {
|
||||
return (
|
||||
<ArtistAlbum
|
||||
key={tabitem.Id}
|
||||
user={user.data}
|
||||
user={user}
|
||||
album={tabitem}
|
||||
/>
|
||||
);
|
||||
@@ -422,13 +416,13 @@ function ArtistTitlePage() {
|
||||
}}
|
||||
>
|
||||
{artistSongs.isSuccess &&
|
||||
artistSongs.data.Items.map((tabitem) => {
|
||||
artistSongs.data.Items?.map((tabitem) => {
|
||||
return (
|
||||
<MusicTrack
|
||||
item={tabitem}
|
||||
key={tabitem.Id}
|
||||
queryKey={["item", id, "artist", "songs"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
@@ -455,7 +449,7 @@ function ArtistTitlePage() {
|
||||
className="grid"
|
||||
>
|
||||
{artistAppearances.isSuccess &&
|
||||
artistAppearances.data.Items.map((tabitem) => {
|
||||
artistAppearances.data.Items?.map((tabitem) => {
|
||||
return (
|
||||
<Card
|
||||
key={tabitem.Id}
|
||||
@@ -465,13 +459,7 @@ function ArtistTitlePage() {
|
||||
cardCaption={tabitem.AlbumArtist}
|
||||
cardType={"square"}
|
||||
queryKey={["item", id, "artist", "appearences"]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!tabitem.ImageBlurHashes?.Primary &&
|
||||
tabitem.ImageBlurHashes?.Primary[
|
||||
Object.keys(tabitem.ImageBlurHashes.Primary)[0]
|
||||
]
|
||||
}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -40,6 +40,7 @@ import "./boxset.scss";
|
||||
import IconLink from "@/components/iconLink";
|
||||
import { getTypeIcon } from "@/components/utils/iconsCollection";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
@@ -72,27 +73,18 @@ function BoxSetTitlePage() {
|
||||
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 user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const item = useQuery({
|
||||
queryKey: ["item", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: id,
|
||||
fields: [ItemFields.Crew],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
networkMode: "always",
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
@@ -101,7 +93,7 @@ function BoxSetTitlePage() {
|
||||
queryKey: ["item", id, "collection"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
parentId: item.data.Id,
|
||||
fields: [ItemFields.SeasonUserData, ItemFields.Overview],
|
||||
excludeLocationTypes: [LocationType.Virtual],
|
||||
@@ -117,8 +109,8 @@ function BoxSetTitlePage() {
|
||||
queryKey: ["item", id, "similarItem"],
|
||||
queryFn: async () => {
|
||||
const result = await getLibraryApi(api).getSimilarItems({
|
||||
userId: user.data.Id,
|
||||
itemId: item.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: item.data?.Id,
|
||||
limit: 16,
|
||||
});
|
||||
return result.data;
|
||||
@@ -370,7 +362,7 @@ function BoxSetTitlePage() {
|
||||
currentVideoTrack={0}
|
||||
currentAudioTrack={0}
|
||||
currentSubTrack={0}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
buttonProps={{
|
||||
fullWidth: true,
|
||||
}}
|
||||
@@ -382,14 +374,14 @@ function BoxSetTitlePage() {
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isFavorite={item.data.UserData.IsFavorite}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemName={item.data.Name}
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isPlayed={item.data.UserData.Played}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -437,7 +429,7 @@ function BoxSetTitlePage() {
|
||||
cardCaption={similar.ProductionYear}
|
||||
cardType={"portrait"}
|
||||
queryKey={["item", id, "collection"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!similar.ImageBlurHashes?.Primary &&
|
||||
similar.ImageBlurHashes?.Primary[
|
||||
@@ -487,7 +479,7 @@ function BoxSetTitlePage() {
|
||||
: "portrait"
|
||||
}
|
||||
queryKey={["item", id, "similarItem"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!similar.ImageBlurHashes?.Primary &&
|
||||
similar.ImageBlurHashes?.Primary[
|
||||
|
||||
@@ -65,6 +65,7 @@ import type MediaQualityInfo from "@/utils/types/mediaQualityInfo";
|
||||
|
||||
import IconLink from "@/components/iconLink";
|
||||
import { Link, createFileRoute } from "@tanstack/react-router";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
@@ -97,27 +98,19 @@ function EpisodeTitlePage() {
|
||||
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 user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const item = useQuery({
|
||||
queryKey: ["item", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: id,
|
||||
fields: [ItemFields.Crew],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
networkMode: "always",
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
@@ -126,9 +119,9 @@ function EpisodeTitlePage() {
|
||||
queryKey: ["item", id, "episode", "upcomingEpisodes"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
parentId: item.data.ParentId,
|
||||
startIndex: item.data.IndexNumber,
|
||||
userId: user?.Id,
|
||||
parentId: item.data?.ParentId ?? "",
|
||||
startIndex: item.data?.IndexNumber ?? 0,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
@@ -688,7 +681,7 @@ function EpisodeTitlePage() {
|
||||
currentVideoTrack={selectedVideoTrack}
|
||||
currentAudioTrack={selectedAudioTrack}
|
||||
currentSubTrack={selectedSubtitleTrack}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-row" style={{ gap: "1em" }}>
|
||||
@@ -701,14 +694,14 @@ function EpisodeTitlePage() {
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isFavorite={item.data.UserData.IsFavorite}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemName={item.data.Name}
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isPlayed={item.data.UserData.Played}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -812,7 +805,7 @@ function EpisodeTitlePage() {
|
||||
cardCaption={`S${episode.ParentIndexNumber}:E${episode.IndexNumber} - ${episode.Name}`}
|
||||
cardType="thumb"
|
||||
queryKey={["item", id, "episode", "upcomingEpisodes"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!episode.ImageBlurHashes?.Primary &&
|
||||
episode.ImageBlurHashes?.Primary[
|
||||
|
||||
@@ -12,6 +12,7 @@ import { BaseItemKind } 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 { createFileRoute } from "@tanstack/react-router";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
export const Route = createFileRoute("/_api/favorite/")({
|
||||
component: FavoritePage,
|
||||
@@ -21,21 +22,13 @@ function FavoritePage() {
|
||||
const api = Route.useRouteContext().api;
|
||||
const [setBackdrop] = useBackdropStore((state) => [state.setBackdrop]);
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
const usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
enabled: Boolean(api),
|
||||
});
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const movies = useQuery({
|
||||
queryKey: ["favorite", "movies"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
isFavorite: true,
|
||||
includeItemTypes: [BaseItemKind.Movie],
|
||||
recursive: true,
|
||||
@@ -48,7 +41,7 @@ function FavoritePage() {
|
||||
queryKey: ["favorite", "series"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
isFavorite: true,
|
||||
includeItemTypes: [BaseItemKind.Series],
|
||||
recursive: true,
|
||||
@@ -61,7 +54,7 @@ function FavoritePage() {
|
||||
queryKey: ["favorite", "musicAlbum"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
isFavorite: true,
|
||||
includeItemTypes: [BaseItemKind.MusicAlbum],
|
||||
recursive: true,
|
||||
@@ -74,7 +67,7 @@ function FavoritePage() {
|
||||
queryKey: ["favorite", "audio"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
isFavorite: true,
|
||||
includeItemTypes: [BaseItemKind.Audio],
|
||||
recursive: true,
|
||||
@@ -87,7 +80,7 @@ function FavoritePage() {
|
||||
queryKey: ["favorite", "book"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
isFavorite: true,
|
||||
includeItemTypes: [BaseItemKind.Book],
|
||||
recursive: true,
|
||||
@@ -100,7 +93,7 @@ function FavoritePage() {
|
||||
queryKey: ["favorite", "musicArtist"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
isFavorite: true,
|
||||
includeItemTypes: [BaseItemKind.MusicArtist],
|
||||
recursive: true,
|
||||
@@ -113,7 +106,7 @@ function FavoritePage() {
|
||||
queryKey: ["favorite", "person"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
isFavorite: true,
|
||||
includeItemTypes: [BaseItemKind.Person],
|
||||
recursive: true,
|
||||
@@ -148,7 +141,7 @@ function FavoritePage() {
|
||||
cardCaption={item.ProductionYear}
|
||||
cardType="portrait"
|
||||
queryKey={["favorite", "movies"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
@@ -176,7 +169,7 @@ function FavoritePage() {
|
||||
}`}
|
||||
cardType="portrait"
|
||||
queryKey={["favorite", "series"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
@@ -198,7 +191,7 @@ function FavoritePage() {
|
||||
cardCaption={item.ProductionYear}
|
||||
cardType="square"
|
||||
queryKey={["favorite", "audio"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
@@ -221,7 +214,7 @@ function FavoritePage() {
|
||||
cardCaption={item.AlbumArtist}
|
||||
cardType={"square"}
|
||||
queryKey={["favorite", "musicAlbum"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
@@ -244,7 +237,7 @@ function FavoritePage() {
|
||||
disableOverlay
|
||||
cardType={"portrait"}
|
||||
queryKey={["favorite", "book"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
@@ -266,7 +259,7 @@ function FavoritePage() {
|
||||
disableOverlay
|
||||
cardType={"square"}
|
||||
queryKey={["favorite", "musicArtist"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
@@ -288,7 +281,7 @@ function FavoritePage() {
|
||||
disableOverlay
|
||||
cardType={"square"}
|
||||
queryKey={["favorite", "person"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
|
||||
@@ -19,11 +19,10 @@ import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api";
|
||||
|
||||
import { Outlet, createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
|
||||
import { setBackdrop } from "@/utils/store/backdrop";
|
||||
|
||||
import CarouselSlide from "@/components/carouselSlide";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import {
|
||||
@@ -33,36 +32,25 @@ import {
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { ErrorBoundary } from "react-error-boundary";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
export const Route = createFileRoute("/_api/home/")({
|
||||
component: Home,
|
||||
onError: (err) => {
|
||||
console.log(err);
|
||||
},
|
||||
});
|
||||
|
||||
function Home() {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
const usr = await getUserApi(api).getCurrentUser();
|
||||
console.log(usr.data);
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
enabled: Boolean(api),
|
||||
});
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const libraries = useQuery({
|
||||
queryKey: ["libraries"],
|
||||
queryFn: async () => {
|
||||
const libs = await getUserViewsApi(api).getUserViews({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
});
|
||||
return libs.data;
|
||||
},
|
||||
enabled: !!user.data && !!api.accessToken,
|
||||
enabled: !!user?.Id && !!api.accessToken,
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
@@ -70,7 +58,7 @@ function Home() {
|
||||
queryKey: ["home", "latestMedia"],
|
||||
queryFn: async () => {
|
||||
const media = await getUserLibraryApi(api).getLatestMedia({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
fields: [
|
||||
ItemFields.Overview,
|
||||
ItemFields.ParentId,
|
||||
@@ -84,14 +72,14 @@ function Home() {
|
||||
});
|
||||
return media.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
|
||||
const resumeItemsVideo = useQuery({
|
||||
queryKey: ["home", "resume", "video"],
|
||||
queryFn: async () => {
|
||||
const resumeItems = await getItemsApi(api).getResumeItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
limit: 10,
|
||||
mediaTypes: ["Video"],
|
||||
enableUserData: true,
|
||||
@@ -99,7 +87,7 @@ function Home() {
|
||||
});
|
||||
return resumeItems.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
refetchOnMount: true,
|
||||
});
|
||||
|
||||
@@ -107,7 +95,7 @@ function Home() {
|
||||
queryKey: ["home", "resume", "audio"],
|
||||
queryFn: async () => {
|
||||
const resumeItems = await getItemsApi(api).getResumeItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
limit: 10,
|
||||
mediaTypes: ["Audio"],
|
||||
enableUserData: true,
|
||||
@@ -115,14 +103,14 @@ function Home() {
|
||||
});
|
||||
return resumeItems.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
|
||||
const upNextItems = useQuery({
|
||||
queryKey: ["home", "upNext"],
|
||||
queryFn: async () => {
|
||||
const upNext = await getTvShowsApi(api).getNextUp({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
fields: [
|
||||
ItemFields.PrimaryImageAspectRatio,
|
||||
ItemFields.MediaStreams,
|
||||
@@ -133,7 +121,7 @@ function Home() {
|
||||
});
|
||||
return upNext.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
refetchOnMount: true,
|
||||
});
|
||||
|
||||
@@ -234,12 +222,14 @@ function Home() {
|
||||
imageType="Primary"
|
||||
cardType="thumb"
|
||||
disableOverlay
|
||||
onClick={() =>
|
||||
navigate({
|
||||
to: "/library/$id",
|
||||
params: { id: item.Id ?? "" },
|
||||
})
|
||||
}
|
||||
onClick={() => {
|
||||
if (item.Id) {
|
||||
navigate({
|
||||
to: "/library/$id",
|
||||
params: { id: item.Id },
|
||||
});
|
||||
}
|
||||
}}
|
||||
overrideIcon={item.CollectionType}
|
||||
/>
|
||||
);
|
||||
@@ -296,7 +286,7 @@ function Home() {
|
||||
}
|
||||
cardType="thumb"
|
||||
queryKey={["home", "upNext"]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
@@ -349,7 +339,7 @@ function Home() {
|
||||
}
|
||||
cardType="thumb"
|
||||
queryKey={["home", "resume", "video"]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
@@ -380,7 +370,7 @@ function Home() {
|
||||
cardCaption={item.ProductionYear}
|
||||
cardType="thumb"
|
||||
queryKey={["home", "resume", "audio"]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -69,6 +69,7 @@ import type MediaQualityInfo from "@/utils/types/mediaQualityInfo";
|
||||
import IconLink from "@/components/iconLink";
|
||||
import { queryClient } from "@/main";
|
||||
import { Link, createFileRoute } from "@tanstack/react-router";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
@@ -102,26 +103,18 @@ function ItemDetail() {
|
||||
|
||||
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 user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const item = useQuery({
|
||||
queryKey: ["item", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
itemId: id,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
networkMode: "always",
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
@@ -134,28 +127,28 @@ function ItemDetail() {
|
||||
let result;
|
||||
if (item.data.Type === "Movie") {
|
||||
result = await getLibraryApi(api).getSimilarMovies({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: item.data.Id,
|
||||
limit: 16,
|
||||
});
|
||||
} else if (item.data.Type === "Series") {
|
||||
result = await getLibraryApi(api).getSimilarShows({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: item.data.Id,
|
||||
});
|
||||
} else if (item.data.Type === "MusicAlbum") {
|
||||
result = await getLibraryApi(api).getSimilarAlbums({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: item.data.Id,
|
||||
});
|
||||
} else if (item.data.Type === "MusicArtist") {
|
||||
result = await getLibraryApi(api).getSimilarArtists({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: item.data.Id,
|
||||
});
|
||||
} else {
|
||||
result = await getLibraryApi(api).getSimilarItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: item.data.Id,
|
||||
});
|
||||
}
|
||||
@@ -193,8 +186,6 @@ function ItemDetail() {
|
||||
const [selectedAudioTrack, setSelectedAudioTrack] = useState(null);
|
||||
const [selectedSubtitleTrack, setSelectedSubtitleTrack] = useState(null);
|
||||
|
||||
const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]);
|
||||
|
||||
const [directors, setDirectors] = useState([]);
|
||||
const [writers, setWriters] = useState([]);
|
||||
const [actors, setActors] = useState([]);
|
||||
@@ -694,7 +685,7 @@ function ItemDetail() {
|
||||
currentVideoTrack={selectedVideoTrack}
|
||||
currentAudioTrack={selectedAudioTrack}
|
||||
currentSubTrack={selectedSubtitleTrack}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
buttonProps={{
|
||||
fullWidth: true,
|
||||
}}
|
||||
@@ -710,14 +701,14 @@ function ItemDetail() {
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isFavorite={item.data.UserData.IsFavorite}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemName={item.data.Name}
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isPlayed={item.data.UserData.Played}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1043,7 +1034,7 @@ function ItemDetail() {
|
||||
: "portrait"
|
||||
}
|
||||
queryKey={["item", id, "similarItem"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!similar.ImageBlurHashes?.Primary &&
|
||||
similar.ImageBlurHashes?.Primary[
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import type {
|
||||
BaseItemKind,
|
||||
ItemSortBy,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
|
||||
type LibraryParamType = {
|
||||
currentViewType: BaseItemKind;
|
||||
sortAscending: boolean;
|
||||
sortBy: ItemSortBy;
|
||||
filters: {
|
||||
isPlayed: boolean;
|
||||
isUnPlayed: boolean;
|
||||
isResumable: boolean;
|
||||
isFavorite: boolean;
|
||||
isLiked: boolean;
|
||||
isUnliked: boolean;
|
||||
hasSubtitles: boolean;
|
||||
hasTrailer: boolean;
|
||||
hasSpecialFeature: boolean;
|
||||
hasThemeSong: boolean;
|
||||
hasThemeVideo: boolean;
|
||||
isBluRay: boolean;
|
||||
isDVD: boolean;
|
||||
isHD: undefined | boolean;
|
||||
isSD: boolean;
|
||||
is4K: boolean;
|
||||
is3D: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
export const Route = createFileRoute("/_api/library")({
|
||||
validateSearch: (search: Record<string, any>): LibraryParamType => {
|
||||
return {
|
||||
currentViewType: search.viewType,
|
||||
sortAscending: search.sortAscending,
|
||||
sortBy: search.sortBy,
|
||||
filters: search.filters,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -51,6 +51,8 @@ import type { AxiosResponse } from "axios";
|
||||
import "./library.scss";
|
||||
import LibraryItemsSkeleton from "@/components/skeleton/libraryItems";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
type SortByObject = { title: string; value: ItemSortBy };
|
||||
type ViewObject = { title: string; value: BaseItemKind | "Artist" };
|
||||
@@ -80,29 +82,22 @@ export const Route = createFileRoute("/_api/library/$id")({
|
||||
});
|
||||
|
||||
function LibraryView() {
|
||||
const api = Route.useRouteContext().api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
const { id } = Route.useParams();
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
const usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const currentLib = useQuery({
|
||||
queryKey: ["libraryView", "currentLib", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
itemId: id,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
networkMode: "always",
|
||||
staleTime: 0,
|
||||
});
|
||||
@@ -431,7 +426,11 @@ function LibraryView() {
|
||||
break;
|
||||
}
|
||||
// And they say typescript makes your code better :|
|
||||
const cachedVal = JSON.parse(sessionStorage.getItem(`library-${currentLib.data?.Id}-config_sort`) as string);
|
||||
const cachedVal = JSON.parse(
|
||||
sessionStorage.getItem(
|
||||
`library-${currentLib.data?.Id}-config_sort`,
|
||||
) as string,
|
||||
);
|
||||
// as {
|
||||
// sortAscending: boolean;
|
||||
// sortBy: ItemSortBy;
|
||||
@@ -448,13 +447,9 @@ function LibraryView() {
|
||||
() => {
|
||||
const cachedVal = sessionStorage.getItem(
|
||||
`library-${currentLib.data?.Id}-config_fliters`,
|
||||
);
|
||||
if (
|
||||
cachedVal !== null
|
||||
) {
|
||||
return JSON.parse(
|
||||
cachedVal
|
||||
);
|
||||
);
|
||||
if (cachedVal !== null) {
|
||||
return JSON.parse(cachedVal);
|
||||
}
|
||||
return {
|
||||
isPlayed: false,
|
||||
@@ -501,32 +496,32 @@ function LibraryView() {
|
||||
let result: AxiosResponse<BaseItemDtoQueryResult, any>;
|
||||
if (currentViewType === "MusicArtist") {
|
||||
result = await getArtistsApi(api).getAlbumArtists({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
parentId: id,
|
||||
});
|
||||
} else if (currentViewType === "Artist") {
|
||||
result = await getArtistsApi(api).getArtists({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
parentId: id,
|
||||
});
|
||||
} else if (currentViewType === "Person") {
|
||||
result = await getPersonsApi(api).getPersons({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
personTypes: ["Actor"],
|
||||
});
|
||||
} else if (currentViewType === "Genre") {
|
||||
result = await getGenresApi(api).getGenres({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
parentId: id,
|
||||
});
|
||||
} else if (currentViewType === "MusicGenre") {
|
||||
result = await getMusicGenresApi(api).getMusicGenres({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
parentId: id,
|
||||
});
|
||||
} else if (currentViewType === "Studio") {
|
||||
result = await getStudiosApi(api).getStudios({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
parentId: id,
|
||||
});
|
||||
} else if (currentViewType === "BoxSet") {
|
||||
@@ -543,7 +538,7 @@ function LibraryView() {
|
||||
if (filters.isFavorite) filtersArray.push(ItemFilter.IsFavorite);
|
||||
|
||||
result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
parentId: currentLib.data?.Id,
|
||||
recursive:
|
||||
currentLib.data?.CollectionType === "boxsets" ? undefined : true,
|
||||
@@ -578,7 +573,7 @@ function LibraryView() {
|
||||
if (filters.isFavorite) filtersArray.push(ItemFilter.IsFavorite);
|
||||
|
||||
result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
parentId: currentLib.data?.Id,
|
||||
recursive:
|
||||
currentLib.data?.CollectionType === "boxsets" ? undefined : true,
|
||||
@@ -603,7 +598,7 @@ function LibraryView() {
|
||||
return result.data;
|
||||
},
|
||||
// enabled: false,
|
||||
enabled: user.isSuccess && Boolean(currentViewType) && currentLib.isSuccess,
|
||||
enabled: user?.Id && Boolean(currentViewType) && currentLib.isSuccess,
|
||||
networkMode: "always",
|
||||
// gcTime: 0,
|
||||
});
|
||||
@@ -1172,7 +1167,7 @@ function LibraryView() {
|
||||
libraryId={currentLib.data.Id}
|
||||
genreId={item.Id}
|
||||
genreName={item.Name}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
);
|
||||
})
|
||||
@@ -1243,7 +1238,7 @@ function LibraryView() {
|
||||
: "portrait"
|
||||
}
|
||||
// queryKey={items}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>,
|
||||
);
|
||||
@@ -1314,7 +1309,7 @@ function LibraryView() {
|
||||
// },
|
||||
// },
|
||||
// ]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -1333,4 +1328,3 @@ function LibraryView() {
|
||||
}
|
||||
|
||||
export default LibraryView;
|
||||
|
||||
@@ -35,6 +35,7 @@ import "./person.scss";
|
||||
|
||||
import IconLink from "@/components/iconLink";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
@@ -74,27 +75,18 @@ 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 user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const item = useQuery({
|
||||
queryKey: ["item", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: id,
|
||||
fields: [ItemFields.Crew],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
networkMode: "always",
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
@@ -103,7 +95,7 @@ function PersonTitlePage() {
|
||||
queryKey: ["item", id, "personMovies"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
personIds: [id],
|
||||
includeItemTypes: [BaseItemKind.Movie],
|
||||
recursive: true,
|
||||
@@ -120,7 +112,7 @@ function PersonTitlePage() {
|
||||
queryKey: ["item", id, "personShows"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
personIds: [id],
|
||||
includeItemTypes: [BaseItemKind.Series],
|
||||
recursive: true,
|
||||
@@ -138,7 +130,7 @@ function PersonTitlePage() {
|
||||
queryKey: ["item", id, "personBooks"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
personIds: [id],
|
||||
includeItemTypes: [BaseItemKind.Book],
|
||||
recursive: true,
|
||||
@@ -155,7 +147,7 @@ function PersonTitlePage() {
|
||||
queryKey: ["item", id, "personPhotos"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
personIds: [id],
|
||||
includeItemTypes: [BaseItemKind.Photo],
|
||||
recursive: true,
|
||||
@@ -171,7 +163,7 @@ function PersonTitlePage() {
|
||||
queryKey: ["item", id, "personEpisodes"],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
personIds: [id],
|
||||
includeItemTypes: [BaseItemKind.Episode],
|
||||
recursive: true,
|
||||
@@ -343,7 +335,7 @@ function PersonTitlePage() {
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isFavorite={item.data.UserData.IsFavorite}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -480,7 +472,7 @@ function PersonTitlePage() {
|
||||
: "portrait"
|
||||
}
|
||||
queryKey={tab.queryKey}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!tabitem.ImageBlurHashes?.Primary &&
|
||||
tabitem.ImageBlurHashes?.Primary[
|
||||
|
||||
@@ -13,6 +13,7 @@ import ReactPlayer from "react-player";
|
||||
|
||||
import {
|
||||
changeSubtitleTrack,
|
||||
playItemFromQueue,
|
||||
toggleSubtitleTrack,
|
||||
usePlaybackStore,
|
||||
} from "@/utils/store/playback";
|
||||
@@ -47,11 +48,14 @@ import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
||||
import QueueButton from "@/components/buttons/queueButton";
|
||||
import OutroCard from "@/components/outroCard";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import useQueue from "@/utils/store/queue";
|
||||
import useQueue, { clearQueue } from "@/utils/store/queue";
|
||||
import { createFileRoute, useRouter } from "@tanstack/react-router";
|
||||
import { toNumber } from "lodash";
|
||||
import type { OnProgressProps } from "react-player/base";
|
||||
import type { TrackProps } from "react-player/file";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
const ticksDisplay = (ticks: number) => {
|
||||
const time = Math.round(ticks / 10000);
|
||||
@@ -87,6 +91,8 @@ function VideoPlayer() {
|
||||
const [hoveringOsd, setHoveringOsd] = useState(false);
|
||||
const player = useRef<ReactPlayer | null>(null);
|
||||
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const [
|
||||
playbackStream,
|
||||
item,
|
||||
@@ -195,6 +201,7 @@ function VideoPlayer() {
|
||||
},
|
||||
});
|
||||
usePlaybackStore.setState(usePlaybackStore.getInitialState());
|
||||
clearQueue();
|
||||
};
|
||||
|
||||
const handleShowOsd = () => {
|
||||
@@ -522,6 +529,15 @@ function VideoPlayer() {
|
||||
return () => clearTimeout(timeout);
|
||||
}, [volume]);
|
||||
|
||||
const handlePlaybackEnded = () => {
|
||||
//check if next track item exists
|
||||
if (queue[currentQueueItemIndex + 1].Id) {
|
||||
playItemFromQueue("next", user?.Id, api);
|
||||
} else {
|
||||
handleExitPlayer(); // Exit player if playback has finished and the queue is empty
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="video-player">
|
||||
<AnimatePresence>
|
||||
@@ -877,6 +893,7 @@ function VideoPlayer() {
|
||||
console.error(hls);
|
||||
console.error(hlsG);
|
||||
}}
|
||||
onEnded={handlePlaybackEnded}
|
||||
width="100vw"
|
||||
height="100vh"
|
||||
style={{
|
||||
|
||||
@@ -20,6 +20,7 @@ import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import "./playlist.scss";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
|
||||
@@ -58,27 +59,18 @@ function PlaylistTitlePage() {
|
||||
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 user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const item = useQuery({
|
||||
queryKey: ["item", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: id,
|
||||
fields: [ItemFields.Crew],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
networkMode: "always",
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
@@ -87,7 +79,7 @@ function PlaylistTitlePage() {
|
||||
queryKey: ["item", id, "similarItem"],
|
||||
queryFn: async () => {
|
||||
const result = await getLibraryApi(api).getSimilarAlbums({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: item.data.Id,
|
||||
limit: 16,
|
||||
});
|
||||
@@ -102,7 +94,7 @@ function PlaylistTitlePage() {
|
||||
queryKey: ["item", id, "musicTracks"],
|
||||
queryFn: async () => {
|
||||
const result = await getPlaylistsApi(api).getPlaylistItems({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
playlistId: item.data.Id,
|
||||
});
|
||||
return result.data;
|
||||
@@ -161,7 +153,7 @@ function PlaylistTitlePage() {
|
||||
item={track}
|
||||
key={track.Id}
|
||||
queryKey={["item", id, "musicTracks"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
playlistItem
|
||||
playlistItemId={item.data.Id}
|
||||
trackIndex={index}
|
||||
@@ -208,7 +200,7 @@ function PlaylistTitlePage() {
|
||||
: "portrait"
|
||||
}
|
||||
queryKey={["item", id, "similarItem"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!similar.ImageBlurHashes?.Primary &&
|
||||
similar.ImageBlurHashes?.Primary[
|
||||
|
||||
@@ -23,6 +23,7 @@ import { getSearchApi } from "@jellyfin/sdk/lib/utils/api/search-api";
|
||||
import "./search.scss";
|
||||
import { Dialog, Fab } from "@mui/material";
|
||||
import { Outlet, createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
export const Route = createFileRoute("/_api/search/")({
|
||||
component: SearchPage,
|
||||
@@ -37,15 +38,7 @@ function SearchPage() {
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
// const searchParam = useDebounce(query, 500);
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
const usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
enabled: Boolean(api),
|
||||
});
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const itemLimit = 12;
|
||||
|
||||
@@ -53,7 +46,7 @@ function SearchPage() {
|
||||
queryKey: ["search", "items", "Movie", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.Movie],
|
||||
recursive: true,
|
||||
@@ -61,13 +54,13 @@ function SearchPage() {
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: user.isSuccess,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
const series = useQuery({
|
||||
queryKey: ["search", "items", "Series", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.Series],
|
||||
recursive: true,
|
||||
@@ -75,13 +68,13 @@ function SearchPage() {
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: user.isSuccess,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
const musicAlbum = useQuery({
|
||||
queryKey: ["search", "items", "MusicAlbum", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.MusicAlbum],
|
||||
recursive: true,
|
||||
@@ -89,13 +82,13 @@ function SearchPage() {
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: user.isSuccess,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
const audio = useQuery({
|
||||
queryKey: ["search", "items", "Audio", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.Audio],
|
||||
recursive: true,
|
||||
@@ -103,13 +96,13 @@ function SearchPage() {
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: user.isSuccess,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
const book = useQuery({
|
||||
queryKey: ["search", "items", "Book", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.Book],
|
||||
recursive: true,
|
||||
@@ -117,13 +110,13 @@ function SearchPage() {
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: user.isSuccess,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
const musicArtists = useQuery({
|
||||
queryKey: ["search", "items", "MusicArtists", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.MusicArtist],
|
||||
recursive: true,
|
||||
@@ -131,32 +124,32 @@ function SearchPage() {
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: user.isSuccess,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
const person = useQuery({
|
||||
queryKey: ["search", "items", "Person", query],
|
||||
queryFn: async () => {
|
||||
const result = await getPersonsApi(api).getPersons({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
searchTerm: query,
|
||||
limit: itemLimit,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: user.isSuccess,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
const episodes = useQuery({
|
||||
queryKey: ["search", "items", "Episodes", query],
|
||||
queryFn: async () => {
|
||||
const result = await getSearchApi(api).getSearchHints({
|
||||
userId: user.data?.Id,
|
||||
userId: user?.Id,
|
||||
searchTerm: query,
|
||||
limit: itemLimit,
|
||||
includeItemTypes: ["Episode"],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: user.isSuccess,
|
||||
enabled: !!user?.Id,
|
||||
});
|
||||
|
||||
const [setBackdrop] = useBackdropStore((state) => [state.setBackdrop]);
|
||||
@@ -224,7 +217,7 @@ function SearchPage() {
|
||||
cardCaption={item.ProductionYear}
|
||||
cardType="portrait"
|
||||
queryKey={["search", "items", "Movie", query]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
@@ -252,7 +245,7 @@ function SearchPage() {
|
||||
}`}
|
||||
cardType="portrait"
|
||||
queryKey={["search", "items", "Series", query]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
item.ImageBlurHashes?.Primary[
|
||||
@@ -273,7 +266,7 @@ function SearchPage() {
|
||||
cardTitle={episode.Series}
|
||||
cardCaption={`S${episode.ParentIndexNumber}:E${episode.IndexNumber} - ${episode.Name}`}
|
||||
queryKey={["search", "items", "Episodes", query]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
disableRunTime
|
||||
/>
|
||||
);
|
||||
@@ -291,7 +284,7 @@ function SearchPage() {
|
||||
cardCaption={item.ProductionYear}
|
||||
cardType="square"
|
||||
queryKey={["search", "items", "Audio", query]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
))}
|
||||
</CardScroller>
|
||||
@@ -308,7 +301,7 @@ function SearchPage() {
|
||||
cardCaption={item.AlbumArtist}
|
||||
cardType={"square"}
|
||||
queryKey={["search", "items", "MusicAlbum", query]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
))}
|
||||
</CardScroller>
|
||||
@@ -325,7 +318,7 @@ function SearchPage() {
|
||||
disableOverlay
|
||||
cardType={"portrait"}
|
||||
queryKey={["search", "items", "Book", query]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
))}
|
||||
</CardScroller>
|
||||
@@ -341,7 +334,7 @@ function SearchPage() {
|
||||
disableOverlay
|
||||
cardType={"square"}
|
||||
queryKey={["search", "items", "MusicArtists", query]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
))}
|
||||
</CardScroller>
|
||||
@@ -357,7 +350,7 @@ function SearchPage() {
|
||||
disableOverlay
|
||||
cardType={"square"}
|
||||
queryKey={["search", "items", "Person", query]}
|
||||
userId={user.data?.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
))}
|
||||
</CardScroller>
|
||||
|
||||
@@ -61,6 +61,7 @@ import IconLink from "@/components/iconLink";
|
||||
import EpisodeSkeleton from "@/components/skeleton/episode";
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import { Link } from "@tanstack/react-router";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
function TabPanel(props) {
|
||||
const { children, value, index, ...other } = props;
|
||||
@@ -101,27 +102,18 @@ function SeriesTitlePage() {
|
||||
|
||||
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 user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const item = useQuery({
|
||||
queryKey: ["item", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: id,
|
||||
fields: [ItemFields.Crew],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
enabled: !!user?.Id,
|
||||
networkMode: "always",
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
@@ -130,7 +122,7 @@ function SeriesTitlePage() {
|
||||
queryKey: ["item", id, "similarItem"],
|
||||
queryFn: async () => {
|
||||
const result = await getLibraryApi(api).getSimilarShows({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: item.data.Id,
|
||||
limit: 16,
|
||||
});
|
||||
@@ -145,7 +137,7 @@ function SeriesTitlePage() {
|
||||
queryKey: ["item", id, "seasons"],
|
||||
queryFn: async () => {
|
||||
const result = await getTvShowsApi(api).getSeasons({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
seriesId: item.data.Id,
|
||||
// isSpecialSeason: false,
|
||||
});
|
||||
@@ -160,7 +152,7 @@ function SeriesTitlePage() {
|
||||
queryKey: ["item", id, "nextUp"],
|
||||
queryFn: async () => {
|
||||
const result = await getTvShowsApi(api).getNextUp({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
limit: 1,
|
||||
parentId: item.data.Id,
|
||||
disableFirstEpisode: true,
|
||||
@@ -189,7 +181,7 @@ function SeriesTitlePage() {
|
||||
queryKey: ["item", id, "season", currentSeason],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
itemId: seasons.data.Items[currentSeason].Id,
|
||||
});
|
||||
return result.data;
|
||||
@@ -203,7 +195,7 @@ function SeriesTitlePage() {
|
||||
queryKey: ["item", id, "season", currentSeason, "episodes"],
|
||||
queryFn: async () => {
|
||||
const result = await getTvShowsApi(api).getEpisodes({
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
seriesId: item.data.Id,
|
||||
seasonId: seasons.data.Items[currentSeason].Id,
|
||||
fields: [ItemFields.Overview],
|
||||
@@ -221,7 +213,7 @@ function SeriesTitlePage() {
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getSpecialFeatures({
|
||||
itemId: item.data.Id,
|
||||
userId: user.data.Id,
|
||||
userId: user?.Id,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
@@ -594,7 +586,7 @@ function SeriesTitlePage() {
|
||||
currentAudioTrack={0}
|
||||
currentVideoTrack={0}
|
||||
currentSubTrack="nosub"
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
buttonProps={{
|
||||
fullWidth: true,
|
||||
}}
|
||||
@@ -610,14 +602,14 @@ function SeriesTitlePage() {
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isFavorite={item.data.UserData.IsFavorite}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemName={item.data.Name}
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isPlayed={item.data.UserData.Played}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -870,7 +862,7 @@ function SeriesTitlePage() {
|
||||
`season ${currentSeason + 1}`,
|
||||
"episodes",
|
||||
]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
@@ -927,7 +919,7 @@ function SeriesTitlePage() {
|
||||
itemId={currentSeasonItem.data.Id}
|
||||
isFavorite={currentSeasonItem.data.UserData.IsFavorite}
|
||||
queryKey={["item", id, "season", currentSeason]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
itemName={currentSeasonItem.data.Name}
|
||||
/>
|
||||
)}
|
||||
@@ -937,7 +929,7 @@ function SeriesTitlePage() {
|
||||
itemId={currentSeasonItem.data.Id}
|
||||
isPlayed={currentSeasonItem.data.UserData.Played}
|
||||
queryKey={["item", id, "season", currentSeason]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
itemName={currentSeasonItem.data.Name}
|
||||
/>
|
||||
</>
|
||||
@@ -1007,7 +999,7 @@ function SeriesTitlePage() {
|
||||
<Typography variant="subtitle1" textAlign="center">
|
||||
{episode.IndexNumberEnd
|
||||
? `${episode.IndexNumber} / ${episode.IndexNumberEnd}`
|
||||
: episode.IndexNumber ?? 0}
|
||||
: (episode.IndexNumber ?? 0)}
|
||||
</Typography>
|
||||
<div
|
||||
className={
|
||||
@@ -1022,7 +1014,7 @@ function SeriesTitlePage() {
|
||||
itemId={episode.Id}
|
||||
itemType={BaseItemKind.Episode}
|
||||
itemUserData={episode.UserData}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
currentAudioTrack={0}
|
||||
currentVideoTrack={0}
|
||||
currentSubTrack="nosub"
|
||||
@@ -1112,7 +1104,7 @@ function SeriesTitlePage() {
|
||||
`season ${currentSeason + 1}`,
|
||||
"episodes",
|
||||
]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemId={episode.Id}
|
||||
@@ -1124,7 +1116,7 @@ function SeriesTitlePage() {
|
||||
`season ${currentSeason + 1}`,
|
||||
"episodes",
|
||||
]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
</motion.div>
|
||||
@@ -1157,7 +1149,7 @@ function SeriesTitlePage() {
|
||||
Object.keys(special.ImageBlurHashes.Primary)[0]
|
||||
]
|
||||
}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
onClick={() => {}}
|
||||
/>
|
||||
);
|
||||
@@ -1202,7 +1194,7 @@ function SeriesTitlePage() {
|
||||
: "portrait"
|
||||
}
|
||||
queryKey={["item", id, "similarItem"]}
|
||||
userId={user.data.Id}
|
||||
userId={user?.Id}
|
||||
imageBlurhash={
|
||||
!!similar.ImageBlurHashes?.Primary &&
|
||||
similar.ImageBlurHashes?.Primary[
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { getDefaultServer } from "@/utils/storage/servers";
|
||||
import { getUser } from "@/utils/storage/user";
|
||||
import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||
import { useQueryErrorResetBoundary } from "@tanstack/react-query";
|
||||
import { createFileRoute, redirect, useRouter } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
|
||||
export const Route = createFileRoute("/")({
|
||||
errorComponent: (error) => {
|
||||
console.error(error.error);
|
||||
},
|
||||
beforeLoad: async () => {
|
||||
const currentServerId = await getDefaultServer();
|
||||
const userOnDisk = await getUser();
|
||||
|
||||
@@ -40,10 +40,12 @@ export const setDefaultServer = async (
|
||||
|
||||
/**
|
||||
* Get a Server
|
||||
* @returns {ServerInfo}
|
||||
*/
|
||||
export const getServer = async (serverId: string | null) => {
|
||||
export const getServer = async (
|
||||
serverId: string | null,
|
||||
): Promise<ServerInfo | undefined> => {
|
||||
const servers = await getAllServers();
|
||||
|
||||
return servers.find((server) => server.id === serverId);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ type ApiStore = {
|
||||
createApi: (serverAddress: string, accessToken?: string | undefined) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export const axiosClient = axios.create({
|
||||
// adapter: axiosTauriApiAdapter,
|
||||
headers: {
|
||||
@@ -50,12 +53,7 @@ export const ApiProvider = ({ children }: { children: ReactNode }) => {
|
||||
jellyfin: jellyfin,
|
||||
createApi: (serverAddress, accessToken?) =>
|
||||
set((state) => {
|
||||
const apiTemp = state.jellyfin.createApi(
|
||||
serverAddress,
|
||||
accessToken,
|
||||
axiosClient,
|
||||
);
|
||||
console.info(apiTemp);
|
||||
const apiTemp = state.jellyfin.createApi(serverAddress, accessToken);
|
||||
return {
|
||||
...state,
|
||||
api: apiTemp,
|
||||
@@ -69,7 +67,7 @@ export const ApiProvider = ({ children }: { children: ReactNode }) => {
|
||||
export function useApiInContext<T>(selector?: (state: ApiStore) => T) {
|
||||
const store = useContext(ApiContext);
|
||||
if (!store) {
|
||||
throw new Error("Missing StoreProvider");
|
||||
throw new Error("Missing ApiProvider");
|
||||
}
|
||||
return useStore(store, selector!);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import { create } from "zustand";
|
||||
import { version } from "../../../package.json";
|
||||
import { getAllServers, getDefaultServer, getServer } from "../storage/servers";
|
||||
import { getUser } from "../storage/user";
|
||||
/**
|
||||
* Central Store controls the base state required by the app
|
||||
*/
|
||||
export const useCentralStore = create(() => ({
|
||||
defaultServerOnDisk: async () => await getDefaultServer(),
|
||||
defaultServerInfoOnDisk: async () => {
|
||||
const a = await getDefaultServer();
|
||||
return await getServer(a);
|
||||
},
|
||||
allServersOnDisk: async () => await getAllServers(),
|
||||
userOnDisk: async () => await getUser(),
|
||||
/** This is the initial route that app goes to just after app startups */
|
||||
initialRoute: null,
|
||||
clientVersion: version,
|
||||
appReady: false,
|
||||
}));
|
||||
|
||||
/**
|
||||
* Sets app inital route
|
||||
* @param {string} route
|
||||
*/
|
||||
export const setInitialRoute = (route) => {
|
||||
useCentralStore.setState((state) => ({ ...state, initialRoute: route }));
|
||||
};
|
||||
|
||||
export const setAppReady = (appReady) => {
|
||||
useCentralStore.setState((state) => ({ ...state, appReady }));
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
import React from "react";
|
||||
import { createStore, StoreApi, useStore } from "zustand";
|
||||
import { version } from "../../../package.json";
|
||||
import {
|
||||
getAllServers,
|
||||
getDefaultServer,
|
||||
getServer,
|
||||
ServerInfo,
|
||||
} from "../storage/servers";
|
||||
import { getUser } from "../storage/user";
|
||||
import { useApiInContext } from "./api";
|
||||
import { Api } from "@jellyfin/sdk";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { createContext, useContext, useState } from "react";
|
||||
import { type UserDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { type ReactNode } from "@tanstack/react-router";
|
||||
|
||||
type CentralStore = {
|
||||
defaultServerOnDisk: () => Promise<string | null>;
|
||||
defaultServerInfoOnDisk: () => Promise<ServerInfo | undefined>;
|
||||
allServersOnDisk: () => Promise<ServerInfo[]>;
|
||||
userOnDisk: () => Promise<{
|
||||
Name: string;
|
||||
AccessToken: string;
|
||||
} | null>;
|
||||
clientVersion: string;
|
||||
currentUser: null | UserDto;
|
||||
fetchCurrentUser: (api: Api | undefined) => Promise<void>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets app inital route
|
||||
* @deprecated
|
||||
*/
|
||||
export const setInitialRoute = (route) => {
|
||||
// useCentralStore.setState((state) => ({ ...state, initialRoute: route }));
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export const setAppReady = (appReady) => {
|
||||
// useCentralStore.setState((state) => ({ ...state, appReady }));
|
||||
};
|
||||
|
||||
const CentralContext = createContext<StoreApi<CentralStore>>(null!);
|
||||
|
||||
export const CentralProvider = ({ children }: { children: ReactNode }) => {
|
||||
const [store] = useState(() =>
|
||||
createStore<CentralStore>()((set) => ({
|
||||
defaultServerOnDisk: async () => await getDefaultServer(),
|
||||
defaultServerInfoOnDisk: async () => {
|
||||
const a = await getDefaultServer();
|
||||
return await getServer(a);
|
||||
},
|
||||
allServersOnDisk: async () => await getAllServers(),
|
||||
userOnDisk: async () => await getUser(),
|
||||
clientVersion: version,
|
||||
currentUser: null,
|
||||
fetchCurrentUser: async (api) => {
|
||||
if (api) {
|
||||
const user = (await getUserApi(api).getCurrentUser()).data;
|
||||
set((s) => ({ ...s, currentUser: user }));
|
||||
}
|
||||
},
|
||||
})),
|
||||
);
|
||||
return (
|
||||
<CentralContext.Provider value={store}>{children}</CentralContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export function useCentralStore<T>(selector?: (state: CentralStore) => T) {
|
||||
const store = useContext(CentralContext);
|
||||
if (!store) {
|
||||
throw new Error("Missing CentralProvider");
|
||||
}
|
||||
return useStore(store, selector!);
|
||||
}
|
||||
@@ -23,4 +23,12 @@ export const setTrackIndex = (index: number) => {
|
||||
useQueue.setState((state) => ({ ...state, currentItemIndex: index }));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Resets the Queue store
|
||||
*/
|
||||
export const clearQueue = () => {
|
||||
useQueue.setState(useQueue.getInitialState());
|
||||
};
|
||||
|
||||
export default useQueue;
|
||||
Reference in new issue
Block a user