Fix libraryPage
This commit is contained in:
2 files changed
+85
-46
No files matched your search
@@ -31,7 +31,6 @@ const init = async () => {
|
||||
const defaultServerInfo = await getServer(defaultServerOnDisk);
|
||||
createApi(defaultServerInfo.address);
|
||||
const userOnDisk = await getUser();
|
||||
console.log(userOnDisk);
|
||||
if (userOnDisk) {
|
||||
try {
|
||||
const auth = await useApi
|
||||
|
||||
@@ -52,6 +52,7 @@ import { useBackdropStore } from "../../utils/store/backdrop";
|
||||
|
||||
import "./library.module.scss";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
|
||||
const LibraryView = () => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
@@ -85,19 +86,18 @@ const LibraryView = () => {
|
||||
setSortBy(e.target.value);
|
||||
};
|
||||
|
||||
const fetchLib = async (libraryId) => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
ids: [libraryId],
|
||||
fields: [ItemFields.RecursiveItemCount],
|
||||
});
|
||||
return result.data;
|
||||
};
|
||||
const currentLib = useQuery({
|
||||
queryKey: ["libraryView", "currentLib", id],
|
||||
queryFn: () => fetchLib(id),
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data.Id,
|
||||
itemId: [id],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!user.data,
|
||||
networkMode: "always",
|
||||
gcTime: 0,
|
||||
});
|
||||
|
||||
const [isPlayed, setIsPlayed] = useState(false);
|
||||
@@ -127,15 +127,20 @@ const LibraryView = () => {
|
||||
const [viewType, setViewType] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (currentLib.isError) {
|
||||
console.error(currentLib.error);
|
||||
}
|
||||
console.log(currentLib.isSuccess);
|
||||
if (currentLib.isSuccess) {
|
||||
if (currentLib.data.Items[0].CollectionType == "movies") {
|
||||
setViewType(null);
|
||||
if (currentLib.data.CollectionType == "movies") {
|
||||
setCurrentViewType(BaseItemKind.Movie);
|
||||
setViewType([
|
||||
{ title: "Movies", value: BaseItemKind.Movie },
|
||||
{ title: "Genres", value: BaseItemKind.Genre },
|
||||
{ title: "Studios", value: BaseItemKind.Studio },
|
||||
]);
|
||||
} else if (currentLib.data.Items[0].CollectionType == "music") {
|
||||
} else if (currentLib.data.CollectionType == "music") {
|
||||
setCurrentViewType(BaseItemKind.MusicAlbum);
|
||||
setViewType([
|
||||
{ title: "Albums", value: BaseItemKind.MusicAlbum },
|
||||
@@ -143,18 +148,14 @@ const LibraryView = () => {
|
||||
{ title: "Artists", value: BaseItemKind.MusicArtist },
|
||||
{ title: "Genres", value: BaseItemKind.MusicGenre },
|
||||
]);
|
||||
} else if (
|
||||
currentLib.data.Items[0].CollectionType == "tvshows"
|
||||
) {
|
||||
} else if (currentLib.data.CollectionType == "tvshows") {
|
||||
setCurrentViewType(BaseItemKind.Series);
|
||||
setViewType([
|
||||
{ title: "Series", value: BaseItemKind.Series },
|
||||
{ title: "Genres", value: BaseItemKind.Genre },
|
||||
{ title: "Networks", value: BaseItemKind.Studio },
|
||||
]);
|
||||
} else if (
|
||||
currentLib.data.Items[0].CollectionType == "playlists"
|
||||
) {
|
||||
} else if (currentLib.data.CollectionType == "playlists") {
|
||||
setCurrentViewType(BaseItemKind.PlaylistsFolder);
|
||||
setViewType([
|
||||
{
|
||||
@@ -167,8 +168,7 @@ const LibraryView = () => {
|
||||
setCurrentViewType("none");
|
||||
setViewType([]);
|
||||
}
|
||||
|
||||
if (currentLib.data.Items[0].CollectionType == "movies") {
|
||||
if (currentLib.data.CollectionType == "movies") {
|
||||
setSortBy("SortName");
|
||||
setSortByData([
|
||||
{ title: "Name", value: "SortName" },
|
||||
@@ -180,9 +180,7 @@ const LibraryView = () => {
|
||||
{ title: "Runtime", value: "Runtime" },
|
||||
{ title: "Random", value: "Random" },
|
||||
]);
|
||||
} else if (
|
||||
currentLib.data.Items[0].CollectionType == "tvshows"
|
||||
) {
|
||||
} else if (currentLib.data.CollectionType == "tvshows") {
|
||||
setSortBy("SortName");
|
||||
setSortByData([
|
||||
{ title: "Name", value: "SortName" },
|
||||
@@ -193,7 +191,7 @@ const LibraryView = () => {
|
||||
{ title: "Release Date", value: "PremiereDate" },
|
||||
{ title: "Random", value: "Random" },
|
||||
]);
|
||||
} else if (currentLib.data.Items[0].CollectionType == "music") {
|
||||
} else if (currentLib.data.CollectionType == "music") {
|
||||
setSortBy("Name");
|
||||
setSortByData([
|
||||
{ title: "Name", value: "Name" },
|
||||
@@ -293,10 +291,9 @@ const LibraryView = () => {
|
||||
} else {
|
||||
result = await getItemsApi(api).getItems({
|
||||
userId: user.data.Id,
|
||||
parentId: currentLib.data.Items[0].Id,
|
||||
parentId: currentLib.data.Id,
|
||||
recursive:
|
||||
currentLib.data.Items[0].CollectionType ==
|
||||
"boxsets"
|
||||
currentLib.data.CollectionType == "boxsets"
|
||||
? undefined
|
||||
: true,
|
||||
includeItemTypes: [currentViewType],
|
||||
@@ -325,8 +322,13 @@ const LibraryView = () => {
|
||||
}
|
||||
return result.data;
|
||||
},
|
||||
enabled: user.isSuccess && Boolean(currentViewType),
|
||||
// enabled: false,
|
||||
enabled:
|
||||
user.isSuccess &&
|
||||
Boolean(currentViewType) &&
|
||||
currentLib.isSuccess,
|
||||
networkMode: "always",
|
||||
// gcTime: 0,
|
||||
});
|
||||
|
||||
const disabledSortViews = [
|
||||
@@ -347,9 +349,26 @@ const LibraryView = () => {
|
||||
useState(() => {
|
||||
// Remove App backdrop in library page
|
||||
setAppBackdrop("", "");
|
||||
console.log(items);
|
||||
console.log(items.isSuccess);
|
||||
}, []);
|
||||
|
||||
if (items.isError) {
|
||||
console.error(items.error);
|
||||
}
|
||||
if (currentLib.isPending) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: "fixed",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translate(-50%, -50%)",
|
||||
}}
|
||||
>
|
||||
<CircularProgress size={72} thickness={1.4} />
|
||||
</div>
|
||||
);
|
||||
} else if (currentLib.isSuccess) {
|
||||
return (
|
||||
<main className="scrollY library">
|
||||
<div
|
||||
@@ -378,13 +397,15 @@ const LibraryView = () => {
|
||||
{currentLib.isPending ? (
|
||||
<CircularProgress sx={{ p: 1 }} />
|
||||
) : (
|
||||
currentLib.data.Items[0].Name
|
||||
currentLib.data.Name
|
||||
)}
|
||||
</Typography>
|
||||
<Chip
|
||||
label={
|
||||
items.isPending ? (
|
||||
<CircularProgress sx={{ p: 1.5 }} />
|
||||
!items.isSuccess ? (
|
||||
<CircularProgress
|
||||
sx={{ p: 1.5 }}
|
||||
/>
|
||||
) : (
|
||||
items.data.TotalRecordCount
|
||||
)
|
||||
@@ -395,7 +416,9 @@ const LibraryView = () => {
|
||||
<div className="library-items">
|
||||
<div className="library-items-header">
|
||||
<div className="library-items-options">
|
||||
{disabledSortViews.includes(currentViewType) ? (
|
||||
{disabledSortViews.includes(
|
||||
currentViewType,
|
||||
) ? (
|
||||
<></>
|
||||
) : (
|
||||
<>
|
||||
@@ -424,7 +447,9 @@ const LibraryView = () => {
|
||||
(option, index) => (
|
||||
<MenuItem
|
||||
key={index}
|
||||
value={option.value}
|
||||
value={
|
||||
option.value
|
||||
}
|
||||
>
|
||||
{option.title}
|
||||
</MenuItem>
|
||||
@@ -451,21 +476,25 @@ const LibraryView = () => {
|
||||
}}
|
||||
size="small"
|
||||
>
|
||||
{viewType.map((option, index) => (
|
||||
{viewType.map(
|
||||
(option, index) => (
|
||||
<MenuItem
|
||||
key={index}
|
||||
value={option.value}
|
||||
value={
|
||||
option.value
|
||||
}
|
||||
>
|
||||
{option.title}
|
||||
</MenuItem>
|
||||
))}
|
||||
),
|
||||
)}
|
||||
</TextField>
|
||||
</>
|
||||
)}
|
||||
|
||||
{currentLib.isSuccess &&
|
||||
allowedFilterViews.includes(
|
||||
currentLib.data.Items[0].CollectionType,
|
||||
currentLib.data.CollectionType,
|
||||
) && (
|
||||
<>
|
||||
<Divider
|
||||
@@ -1068,7 +1097,8 @@ const LibraryView = () => {
|
||||
</Accordion>
|
||||
)}
|
||||
{!onlyStatusFilterViews.includes(
|
||||
currentLib.data.Items[0]
|
||||
currentLib.data
|
||||
.Items[0]
|
||||
.CollectionType,
|
||||
) && (
|
||||
<Accordion className="library-filter-accordian">
|
||||
@@ -1247,7 +1277,7 @@ const LibraryView = () => {
|
||||
</Popper>
|
||||
</div>
|
||||
</div>
|
||||
{items.isPending ? (
|
||||
{!items.isSuccess ? (
|
||||
<Box
|
||||
sx={{
|
||||
position: "absolute",
|
||||
@@ -1278,7 +1308,9 @@ const LibraryView = () => {
|
||||
return (
|
||||
<GenreView
|
||||
key={item.Id}
|
||||
libraryId={currentLib.data.Items[0].Id}
|
||||
libraryId={
|
||||
currentLib.data.Items[0].Id
|
||||
}
|
||||
genreId={item.Id}
|
||||
genreName={item.Name}
|
||||
userId={user.data.Id}
|
||||
@@ -1393,7 +1425,8 @@ const LibraryView = () => {
|
||||
hasThemeVideo:
|
||||
hasThemeVideo,
|
||||
},
|
||||
qualityFilters: {
|
||||
qualityFilters:
|
||||
{
|
||||
isBluRay:
|
||||
isBluRay,
|
||||
isDVD: isDVD,
|
||||
@@ -1405,7 +1438,8 @@ const LibraryView = () => {
|
||||
]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes
|
||||
!!item
|
||||
.ImageBlurHashes
|
||||
?.Primary &&
|
||||
item.ImageBlurHashes
|
||||
?.Primary[
|
||||
@@ -1440,13 +1474,16 @@ const LibraryView = () => {
|
||||
{
|
||||
currentViewType:
|
||||
currentViewType,
|
||||
sortAscending: sortAscending,
|
||||
sortAscending:
|
||||
sortAscending,
|
||||
sortBy: sortBy,
|
||||
playbackFilters: filterArray,
|
||||
playbackFilters:
|
||||
filterArray,
|
||||
extraFilters: {
|
||||
hasSubtitles:
|
||||
hasSubtitles,
|
||||
hasTrailer: hasTrailer,
|
||||
hasTrailer:
|
||||
hasTrailer,
|
||||
hasSpecialFeature:
|
||||
hasSpecialFeature,
|
||||
hasThemeSong:
|
||||
@@ -1508,6 +1545,9 @@ const LibraryView = () => {
|
||||
{items.isError && <ErrorNotice />}
|
||||
</main>
|
||||
);
|
||||
} else if (currentLib.isError) {
|
||||
return <h6>{currentLib.error}</h6>;
|
||||
}
|
||||
};
|
||||
|
||||
export default LibraryView;
|
||||
Reference in new issue
Block a user