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