feat: add new library page with performance improvements
This commit is contained in:
29 files changed
+2020
-645
No files matched your search
@@ -0,0 +1,33 @@
|
||||
.alpha-selector {
|
||||
position: sticky;
|
||||
top: 80px;
|
||||
right: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 4px;
|
||||
margin-left: auto;
|
||||
user-select: none;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.alpha-letter {
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
padding: 6px 8px;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
color: rgba(255,255,255,0.7);
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.alpha-letter.active {
|
||||
background: rgba(255,255,255,0.12);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.alpha-letter:hover {
|
||||
background: rgba(255,255,255,0.08);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { getRouteApi } from "@tanstack/react-router";
|
||||
import React, { useMemo } from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { useLibraryStateStore } from "@/utils/store/libraryState";
|
||||
import "./alphaSelector.scss";
|
||||
|
||||
const libraryRoute = getRouteApi("/_api/library/$id");
|
||||
|
||||
export const AlphaSelector = React.memo(function AlphaSelector() {
|
||||
const { id: currentLibraryId } = libraryRoute.useParams();
|
||||
const { nameStartsWith } = useLibraryStateStore(
|
||||
useShallow((s) => ({
|
||||
nameStartsWith: s.libraries[currentLibraryId || ""]?.nameStartsWith,
|
||||
})),
|
||||
);
|
||||
const updateLibrary = useLibraryStateStore((s) => s.updateLibrary);
|
||||
|
||||
const letters = useMemo(() => {
|
||||
const arr = Array.from({ length: 26 }, (_, i) =>
|
||||
String.fromCharCode(65 + i),
|
||||
);
|
||||
return ["All", ...arr];
|
||||
}, []);
|
||||
|
||||
const handleSelect = (letter: string) => {
|
||||
const value = letter === "All" ? undefined : letter;
|
||||
if (currentLibraryId)
|
||||
updateLibrary(currentLibraryId, { nameStartsWith: value });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="alpha-selector">
|
||||
{letters.map((l) => {
|
||||
const active = (nameStartsWith || "All") === l;
|
||||
return (
|
||||
<button
|
||||
key={l}
|
||||
className={active ? "alpha-letter active" : "alpha-letter"}
|
||||
onClick={() => handleSelect(l)}
|
||||
aria-label={`Filter by ${l}`}
|
||||
type="button"
|
||||
>
|
||||
{l}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export default AlphaSelector;
|
||||
@@ -1,20 +1,48 @@
|
||||
|
||||
.appBar {
|
||||
transition: background-color $transition-time-fast,
|
||||
backdrop-filter $transition-time-fast,
|
||||
box-shadow $transition-time-default !important;
|
||||
// Limit transitions to cheaper properties; avoid animating box-shadow directly
|
||||
transition: background-color $transition-time-fast;
|
||||
padding: 0.8em ($page-margin - 1.7em);
|
||||
z-index: 999 !important;
|
||||
.flex {
|
||||
transition: $transition-time-fast;
|
||||
// Avoid animating padding; it causes layout reflow on each frame.
|
||||
transition: background-color $transition-time-fast;
|
||||
// Avoid using will-change: scroll-position; it can degrade performance when misused
|
||||
// will-change: opacity, transform;
|
||||
border-radius: 1000px;
|
||||
position: relative;
|
||||
|
||||
// Pseudo-element handles elevation shadow; we animate its opacity
|
||||
&::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
backdrop-filter: blur(40px);
|
||||
inset: -0.35em;
|
||||
pointer-events: none;
|
||||
border-radius: inherit;
|
||||
box-shadow: 0 0 25px rgb(0 0 0 / 0.45);
|
||||
background: rgb(0 0 0 / 0.4);
|
||||
opacity: 0;
|
||||
z-index: -1;
|
||||
transition: opacity $transition-time-fast;
|
||||
}
|
||||
}
|
||||
|
||||
// Inner content wrapper that we can scale without causing layout reflow
|
||||
.flex-inner {
|
||||
transform-origin: top center;
|
||||
transition: transform $transition-time-fast;
|
||||
}
|
||||
&.elevated{
|
||||
.flex {
|
||||
padding: 0.5em;
|
||||
background: rgb(0 0 0 / 0.4);
|
||||
backdrop-filter: blur(40px);
|
||||
box-shadow: 0 0 25px rgb(0 0 0 / 0.45);
|
||||
&::after {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply a subtle scale to simulate shrink without layout changes
|
||||
.flex-inner {
|
||||
transform: scaleY(0.95);
|
||||
}
|
||||
}
|
||||
&-avatar {
|
||||
|
||||
@@ -1,37 +1,29 @@
|
||||
import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api";
|
||||
import MuiAppBar from "@mui/material/AppBar";
|
||||
import Avatar from "@mui/material/Avatar";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import ListItemIcon from "@mui/material/ListItemIcon";
|
||||
import Menu from "@mui/material/Menu";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import useScrollTrigger from "@mui/material/useScrollTrigger";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { useLocation, useNavigate, useRouter } from "@tanstack/react-router";
|
||||
import React, {
|
||||
type MouseEventHandler,
|
||||
useCallback,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useLocation, useNavigate } from "@tanstack/react-router";
|
||||
import React, { useCallback, useMemo, useState } from "react";
|
||||
|
||||
import { delUser } from "@/utils/storage/user";
|
||||
import "./appBar.scss";
|
||||
|
||||
import { Divider, Drawer, List, ListItem, ListItemButton } from "@mui/material";
|
||||
|
||||
import { useShallow } from "zustand/shallow";
|
||||
// removed search placeholder; library state now managed via zustand
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import useHeaderStore from "@/utils/store/header";
|
||||
import {
|
||||
setSettingsDialogOpen,
|
||||
setSettingsTabValue,
|
||||
} from "@/utils/store/settings";
|
||||
import BackButton from "../buttons/backButton";
|
||||
import ListItemLink from "../listItemLink";
|
||||
import { UserAvatarMenu } from "../userAvatarMenu";
|
||||
import { getTypeIcon } from "../utils/iconsCollection";
|
||||
|
||||
|
||||
const MemoizeBackButton = React.memo(BackButton);
|
||||
|
||||
const HIDDEN_PATHS = [
|
||||
@@ -41,25 +33,21 @@ const HIDDEN_PATHS = [
|
||||
"/player",
|
||||
"/error",
|
||||
"/settings",
|
||||
"/library",
|
||||
];
|
||||
|
||||
export const AppBar = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const createApi = useApiInContext((s) => s.createApi);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const router = useRouter();
|
||||
|
||||
const display = !HIDDEN_PATHS.some(
|
||||
(path) => location.pathname.startsWith(path) || location.pathname === "/",
|
||||
);
|
||||
|
||||
|
||||
const [user, resetCurrentUser] = useCentralStore((s) => [
|
||||
s.currentUser,
|
||||
s.resetCurrentUser,
|
||||
]);
|
||||
const [user] = useCentralStore((s) => [s.currentUser]);
|
||||
const libraries = useQuery({
|
||||
queryKey: ["libraries"],
|
||||
queryFn: async () => {
|
||||
@@ -80,34 +68,6 @@ export const AppBar = () => {
|
||||
threshold: 20,
|
||||
});
|
||||
|
||||
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
|
||||
const openMenu = Boolean(anchorEl);
|
||||
const handleMenuOpen: MouseEventHandler<HTMLButtonElement> = useCallback(
|
||||
(event) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
},
|
||||
[],
|
||||
);
|
||||
const handleMenuClose = useCallback(() => {
|
||||
setAnchorEl(null);
|
||||
}, []);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const handleLogout = useCallback(async () => {
|
||||
console.log("Logging out user...");
|
||||
await api?.logout();
|
||||
createApi(api?.basePath ?? "", undefined);
|
||||
console.log(api);
|
||||
resetCurrentUser();
|
||||
delUser();
|
||||
sessionStorage.removeItem("accessToken");
|
||||
queryClient.clear();
|
||||
await router.invalidate();
|
||||
setAnchorEl(null);
|
||||
navigate({ to: "/login", replace: true });
|
||||
}, [api]);
|
||||
|
||||
|
||||
const [showDrawer, setShowDrawer] = useState(false);
|
||||
|
||||
const appBarStyling = useMemo(() => {
|
||||
@@ -116,9 +76,6 @@ export const AppBar = () => {
|
||||
paddingRight: "0 !important",
|
||||
};
|
||||
}, []);
|
||||
const menuStyle = useMemo(() => {
|
||||
return { mt: 2 };
|
||||
}, []);
|
||||
|
||||
const drawerPaperProps = useMemo(() => {
|
||||
return {
|
||||
@@ -145,7 +102,7 @@ export const AppBar = () => {
|
||||
navigate({ to: "/favorite" });
|
||||
}, []);
|
||||
|
||||
const menuButtonSx = useMemo(() => ({ p: 0 }), []);
|
||||
useHeaderStore(useShallow((s) => ({ pageTitle: s.pageTitle })));
|
||||
|
||||
if (!display) {
|
||||
return null;
|
||||
@@ -188,80 +145,7 @@ export const AppBar = () => {
|
||||
<IconButton onClick={handleNavigateToFavorite}>
|
||||
<div className="material-symbols-rounded">favorite</div>
|
||||
</IconButton>
|
||||
<IconButton sx={menuButtonSx} onClick={handleMenuOpen}>
|
||||
{!!user?.Id &&
|
||||
(user?.PrimaryImageTag === undefined ? (
|
||||
<Avatar className="appBar-avatar" alt={user?.Name ?? "image"}>
|
||||
<span className="material-symbols-rounded appBar-avatar-icon">
|
||||
account_circle
|
||||
</span>
|
||||
</Avatar>
|
||||
) : (
|
||||
<Avatar
|
||||
className="appBar-avatar"
|
||||
src={`${api?.basePath}/Users/${user?.Id}/Images/Primary`}
|
||||
alt={user?.Name ?? "image"}
|
||||
>
|
||||
<span className="material-symbols-rounded appBar-avatar-icon">
|
||||
account_circle
|
||||
</span>
|
||||
</Avatar>
|
||||
))}
|
||||
</IconButton>
|
||||
<Menu
|
||||
anchorEl={anchorEl}
|
||||
open={openMenu}
|
||||
onClose={handleMenuClose}
|
||||
sx={menuStyle}
|
||||
disableScrollLock
|
||||
>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
handleLogout();
|
||||
handleMenuClose();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">logout</div>
|
||||
</ListItemIcon>
|
||||
Logout
|
||||
</MenuItem>
|
||||
<Divider />
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
setSettingsDialogOpen(true);
|
||||
setSettingsTabValue(1);
|
||||
handleMenuClose();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">settings</div>
|
||||
</ListItemIcon>
|
||||
Settings
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
navigate({ to: "/settings/preferences" });
|
||||
handleMenuClose();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">tune</div>
|
||||
</ListItemIcon>
|
||||
Preferences
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
navigate({ to: "/settings/about" });
|
||||
handleMenuClose();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">info</div>
|
||||
</ListItemIcon>
|
||||
About
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<UserAvatarMenu />
|
||||
</div>
|
||||
</MuiAppBar>
|
||||
<Drawer
|
||||
@@ -298,9 +182,7 @@ export const AppBar = () => {
|
||||
className="library-drawer-item"
|
||||
key={library.Id}
|
||||
to="/library/$id"
|
||||
params={{
|
||||
id: library.Id ?? "",
|
||||
}}
|
||||
params={{ id: library.Id ?? "" }}
|
||||
icon={
|
||||
library.CollectionType &&
|
||||
getTypeIcon(library.CollectionType)
|
||||
|
||||
@@ -24,6 +24,10 @@ export default function Backdrop() {
|
||||
animate={{ opacity: 1 }}
|
||||
key={backdropHash}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{
|
||||
duration: 2,
|
||||
ease: "easeInOut",
|
||||
}}
|
||||
className="app-backdrop-container"
|
||||
>
|
||||
<BlurhashCanvas
|
||||
|
||||
@@ -33,6 +33,7 @@ const CardComponent = ({
|
||||
onClick,
|
||||
disableOverlay = false,
|
||||
overrideIcon,
|
||||
skipInView = false,
|
||||
}: {
|
||||
item: BaseItemDto;
|
||||
cardTitle: string | undefined | null;
|
||||
@@ -46,6 +47,7 @@ const CardComponent = ({
|
||||
onClick?: () => void;
|
||||
disableOverlay?: boolean;
|
||||
overrideIcon?: any;
|
||||
skipInView?: boolean;
|
||||
}) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const navigate = useNavigate();
|
||||
@@ -82,6 +84,7 @@ const CardComponent = ({
|
||||
|
||||
const { ref, inView } = useInView({
|
||||
threshold: 0.1,
|
||||
skip: skipInView,
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -120,7 +123,7 @@ const CardComponent = ({
|
||||
? getTypeIcon(overrideIcon)
|
||||
: getTypeIcon(item.Type ?? "universal")}
|
||||
</div>
|
||||
{inView && (
|
||||
{(skipInView || inView) && (
|
||||
<img
|
||||
alt={item.Name ?? "blink"}
|
||||
src={
|
||||
@@ -148,11 +151,10 @@ const CardComponent = ({
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.setProperty("opacity", "1");
|
||||
}}
|
||||
onLoadStart={(e) => console.log(e)}
|
||||
className="card-image"
|
||||
/>
|
||||
)}
|
||||
{inView && !disableOverlay && (
|
||||
{(skipInView || inView) && !disableOverlay && (
|
||||
<div className="card-overlay">
|
||||
<PlayButton
|
||||
item={item}
|
||||
@@ -201,7 +203,7 @@ const CardComponent = ({
|
||||
</div>
|
||||
<div
|
||||
className="card-text-container"
|
||||
style={{ display: hideText ? "none" : "block" }}
|
||||
style={{ display: hideText ? "none" : "block", marginLeft: "0.2em" }}
|
||||
>
|
||||
<Typography mt={1} variant="subtitle2" noWrap style={{ opacity: 0.9 }}>
|
||||
{cardTitle}
|
||||
|
||||
@@ -0,0 +1,509 @@
|
||||
import { getGenresApi } from "@jellyfin/sdk/lib/utils/api/genres-api";
|
||||
import { getMusicGenresApi } from "@jellyfin/sdk/lib/utils/api/music-genres-api";
|
||||
import {
|
||||
Accordion,
|
||||
AccordionDetails,
|
||||
AccordionSummary,
|
||||
Button,
|
||||
Checkbox,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
FormControlLabel,
|
||||
FormGroup,
|
||||
IconButton,
|
||||
Stack,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { getRouteApi } from "@tanstack/react-router";
|
||||
import React, { useMemo, useRef, useState } from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import type { FILTERS } from "@/utils/constants/library";
|
||||
import { getLibraryQueryOptions } from "@/utils/queries/library";
|
||||
import { useLibraryStateStore } from "@/utils/store/libraryState";
|
||||
|
||||
const route = getRouteApi("/_api/library/$id");
|
||||
|
||||
const FILTER_LABELS: Record<FILTERS, string> = {
|
||||
isPlayed: "Played",
|
||||
isUnPlayed: "Unplayed",
|
||||
isResumable: "Resumable",
|
||||
isFavorite: "Favorite",
|
||||
hasSubtitles: "Has Subtitles",
|
||||
hasTrailer: "Has Trailer",
|
||||
hasSpecialFeature: "Special Feature",
|
||||
hasThemeSong: "Theme Song",
|
||||
hasThemeVideo: "Theme Video",
|
||||
isSD: "SD",
|
||||
isHD: "HD",
|
||||
is4K: "4K",
|
||||
is3D: "3D",
|
||||
};
|
||||
|
||||
interface FiltersDialogProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const FiltersDialog: React.FC<FiltersDialogProps> = React.memo(
|
||||
({ open, onClose }) => {
|
||||
const { id: currentLibraryId } = route.useParams();
|
||||
const { api, user } = route.useRouteContext();
|
||||
const { routeFilters, routeVideoTypes, routeGenreIds } =
|
||||
useLibraryStateStore(
|
||||
useShallow((s) => {
|
||||
const slice = s.libraries[currentLibraryId || ""];
|
||||
return {
|
||||
routeFilters: slice?.filters,
|
||||
routeVideoTypes: slice?.videoTypesState,
|
||||
routeGenreIds: slice?.genreIds,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const updateLibrary = useLibraryStateStore((s) => s.updateLibrary);
|
||||
const initial = useMemo(
|
||||
() => ({ ...(routeFilters || {}) }),
|
||||
[routeFilters],
|
||||
);
|
||||
const [localFilters, setLocalFilters] =
|
||||
useState<Record<string, boolean | undefined>>(initial);
|
||||
const initialVideo = useMemo(
|
||||
() => ({ ...(routeVideoTypes || {}) }),
|
||||
[routeVideoTypes],
|
||||
);
|
||||
const [localVideoTypes, setLocalVideoTypes] =
|
||||
useState<Record<string, boolean>>(initialVideo);
|
||||
const initialGenres = useMemo(
|
||||
() => [...(routeGenreIds || [])] as string[],
|
||||
[routeGenreIds],
|
||||
);
|
||||
const [localGenreIds, setLocalGenreIds] = useState<string[]>(initialGenres);
|
||||
const dirty = useMemo(
|
||||
() =>
|
||||
JSON.stringify(initial) !== JSON.stringify(localFilters) ||
|
||||
JSON.stringify(initialVideo) !== JSON.stringify(localVideoTypes) ||
|
||||
JSON.stringify(initialGenres) !== JSON.stringify(localGenreIds),
|
||||
[
|
||||
initial,
|
||||
localFilters,
|
||||
initialVideo,
|
||||
localVideoTypes,
|
||||
initialGenres,
|
||||
localGenreIds,
|
||||
],
|
||||
);
|
||||
const debounceRef = useRef<number | null>(null);
|
||||
const currentLibrary = useSuspenseQuery(
|
||||
getLibraryQueryOptions(api, user?.Id, currentLibraryId),
|
||||
);
|
||||
const collectionType = currentLibrary.data.CollectionType;
|
||||
const isVideoCollection = ["movies", "tvshows", "boxsets"].includes(
|
||||
String(collectionType || "").toLowerCase(),
|
||||
);
|
||||
|
||||
// Fetch genres for this library (music uses music-genres API)
|
||||
const { data: genresData } = useQuery({
|
||||
queryKey: ["library", "genres", currentLibraryId, collectionType],
|
||||
queryFn: async () => {
|
||||
if (!api || !user?.Id || !currentLibraryId) return { Items: [] } as any;
|
||||
if (String(collectionType || "").toLowerCase() === "music") {
|
||||
const res = await getMusicGenresApi(api).getMusicGenres({
|
||||
parentId: currentLibraryId,
|
||||
userId: user.Id,
|
||||
});
|
||||
return res.data;
|
||||
}
|
||||
const res = await getGenresApi(api).getGenres({
|
||||
parentId: currentLibraryId,
|
||||
userId: user.Id,
|
||||
});
|
||||
return res.data;
|
||||
},
|
||||
staleTime: 10 * 60 * 1000,
|
||||
enabled: !!open && !!api && !!user?.Id && !!currentLibraryId,
|
||||
});
|
||||
|
||||
const handleToggle = (key: FILTERS) => {
|
||||
setLocalFilters((prev) => {
|
||||
const next = { ...prev };
|
||||
// isHD special: undefined if unchecked instead of false
|
||||
if (key === "isHD") {
|
||||
if (next[key]) delete next[key];
|
||||
else next[key] = true;
|
||||
} else {
|
||||
next[key] = !next[key];
|
||||
}
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
const apply = () => {
|
||||
if (!currentLibraryId) return;
|
||||
if (debounceRef.current) window.clearTimeout(debounceRef.current);
|
||||
debounceRef.current = window.setTimeout(() => {
|
||||
updateLibrary(currentLibraryId, {
|
||||
filters: localFilters as any,
|
||||
videoTypesState: localVideoTypes as any,
|
||||
genreIds: localGenreIds as any,
|
||||
});
|
||||
onClose();
|
||||
}, 40);
|
||||
};
|
||||
|
||||
const clearAll = () => {
|
||||
setLocalFilters({});
|
||||
setLocalVideoTypes({});
|
||||
setLocalGenreIds([]);
|
||||
};
|
||||
|
||||
const restore = () => setLocalFilters(initial);
|
||||
const restoreVideo = () => setLocalVideoTypes(initialVideo);
|
||||
const restoreGenres = () => setLocalGenreIds(initialGenres);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onClose={onClose} fullWidth maxWidth="sm" keepMounted>
|
||||
<DialogTitle>Filters</DialogTitle>
|
||||
<DialogContent dividers>
|
||||
<Stack spacing={1.25}>
|
||||
<Accordion
|
||||
disableGutters
|
||||
sx={{
|
||||
backgroundColor: "transparent",
|
||||
boxShadow: "none",
|
||||
m: 0,
|
||||
"&:before": { display: "none" },
|
||||
"&:not(:last-of-type)": {
|
||||
borderBottom: "1px solid rgba(255,255,255,0.12)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<AccordionSummary
|
||||
sx={{
|
||||
minHeight: 40,
|
||||
"& .MuiAccordionSummary-content": { my: 0 },
|
||||
}}
|
||||
expandIcon={
|
||||
<div className="material-symbols-rounded">expand_more</div>
|
||||
}
|
||||
>
|
||||
<Typography variant="subtitle2">General</Typography>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails sx={{ px: 1.5, py: 1.25 }}>
|
||||
<FormGroup>
|
||||
{(
|
||||
[
|
||||
"isPlayed",
|
||||
"isUnPlayed",
|
||||
"isResumable",
|
||||
"isFavorite",
|
||||
] as FILTERS[]
|
||||
).map((k) => (
|
||||
<FormControlLabel
|
||||
key={k}
|
||||
control={
|
||||
<Checkbox
|
||||
checked={!!localFilters[k]}
|
||||
onChange={() => handleToggle(k)}
|
||||
size="small"
|
||||
/>
|
||||
}
|
||||
label={FILTER_LABELS[k]}
|
||||
/>
|
||||
))}
|
||||
</FormGroup>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
|
||||
{isVideoCollection && (
|
||||
<Accordion
|
||||
disableGutters
|
||||
sx={{
|
||||
backgroundColor: "transparent",
|
||||
boxShadow: "none",
|
||||
m: 0,
|
||||
"&:before": { display: "none" },
|
||||
"&:not(:last-of-type)": {
|
||||
borderBottom: "1px solid rgba(255,255,255,0.12)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<AccordionSummary
|
||||
sx={{
|
||||
minHeight: 40,
|
||||
"& .MuiAccordionSummary-content": { my: 0 },
|
||||
}}
|
||||
expandIcon={
|
||||
<div className="material-symbols-rounded">expand_more</div>
|
||||
}
|
||||
>
|
||||
<Typography variant="subtitle2">Video features</Typography>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails sx={{ px: 1.5, py: 1.25 }}>
|
||||
<FormGroup>
|
||||
{(
|
||||
[
|
||||
"hasSubtitles",
|
||||
"hasTrailer",
|
||||
"hasSpecialFeature",
|
||||
"hasThemeSong",
|
||||
"hasThemeVideo",
|
||||
] as FILTERS[]
|
||||
).map((k) => (
|
||||
<FormControlLabel
|
||||
key={k}
|
||||
control={
|
||||
<Checkbox
|
||||
checked={!!localFilters[k]}
|
||||
onChange={() => handleToggle(k)}
|
||||
size="small"
|
||||
/>
|
||||
}
|
||||
label={FILTER_LABELS[k]}
|
||||
/>
|
||||
))}
|
||||
</FormGroup>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
)}
|
||||
|
||||
{isVideoCollection && (
|
||||
<Accordion
|
||||
disableGutters
|
||||
sx={{
|
||||
backgroundColor: "transparent",
|
||||
boxShadow: "none",
|
||||
m: 0,
|
||||
"&:before": { display: "none" },
|
||||
"&:not(:last-of-type)": {
|
||||
borderBottom: "1px solid rgba(255,255,255,0.12)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<AccordionSummary
|
||||
sx={{
|
||||
minHeight: 40,
|
||||
"& .MuiAccordionSummary-content": { my: 0 },
|
||||
}}
|
||||
expandIcon={
|
||||
<div className="material-symbols-rounded">expand_more</div>
|
||||
}
|
||||
>
|
||||
<Typography variant="subtitle2">Resolution</Typography>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails sx={{ px: 1.5, py: 1.25 }}>
|
||||
<FormGroup>
|
||||
{(["isSD", "isHD", "is4K", "is3D"] as FILTERS[]).map(
|
||||
(k) => (
|
||||
<FormControlLabel
|
||||
key={k}
|
||||
control={
|
||||
<Checkbox
|
||||
checked={!!localFilters[k]}
|
||||
onChange={() => handleToggle(k)}
|
||||
size="small"
|
||||
/>
|
||||
}
|
||||
label={FILTER_LABELS[k]}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
</FormGroup>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
)}
|
||||
|
||||
{isVideoCollection && (
|
||||
<Accordion
|
||||
disableGutters
|
||||
sx={{
|
||||
backgroundColor: "transparent",
|
||||
boxShadow: "none",
|
||||
m: 0,
|
||||
"&:before": { display: "none" },
|
||||
"&:not(:last-of-type)": {
|
||||
borderBottom: "1px solid rgba(255,255,255,0.12)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<AccordionSummary
|
||||
sx={{
|
||||
minHeight: 40,
|
||||
"& .MuiAccordionSummary-content": { my: 0 },
|
||||
}}
|
||||
expandIcon={
|
||||
<div className="material-symbols-rounded">expand_more</div>
|
||||
}
|
||||
>
|
||||
<Typography variant="subtitle2">Media type</Typography>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails sx={{ px: 1.5, py: 1.25 }}>
|
||||
<FormGroup>
|
||||
{(["BluRay", "Dvd", "Iso", "VideoFile"] as const).map(
|
||||
(k) => (
|
||||
<FormControlLabel
|
||||
key={k}
|
||||
control={
|
||||
<Checkbox
|
||||
checked={!!(localVideoTypes as any)[k]}
|
||||
onChange={() =>
|
||||
setLocalVideoTypes((prev) => ({
|
||||
...(prev || {}),
|
||||
[k]: !(prev as any)?.[k],
|
||||
}))
|
||||
}
|
||||
size="small"
|
||||
/>
|
||||
}
|
||||
label={k}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
</FormGroup>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
)}
|
||||
|
||||
{/* Genres (all collection types) */}
|
||||
{(genresData?.Items?.length || 0) > 0 && (
|
||||
<Accordion
|
||||
disableGutters
|
||||
sx={{
|
||||
backgroundColor: "transparent",
|
||||
boxShadow: "none",
|
||||
m: 0,
|
||||
"&:before": { display: "none" },
|
||||
}}
|
||||
>
|
||||
<AccordionSummary
|
||||
sx={{
|
||||
minHeight: 40,
|
||||
"& .MuiAccordionSummary-content": { my: 0 },
|
||||
}}
|
||||
expandIcon={
|
||||
<div className="material-symbols-rounded">expand_more</div>
|
||||
}
|
||||
>
|
||||
<Typography variant="subtitle2">Genres</Typography>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails sx={{ px: 1.5, py: 1.25 }}>
|
||||
<FormGroup>
|
||||
{(genresData?.Items || []).map((g: any) => (
|
||||
<FormControlLabel
|
||||
key={g.Id}
|
||||
control={
|
||||
<Checkbox
|
||||
checked={localGenreIds.includes(g.Id)}
|
||||
onChange={() =>
|
||||
setLocalGenreIds((prev) =>
|
||||
prev.includes(g.Id)
|
||||
? prev.filter((id) => id !== g.Id)
|
||||
: [...prev, g.Id],
|
||||
)
|
||||
}
|
||||
size="small"
|
||||
/>
|
||||
}
|
||||
label={g.Name}
|
||||
/>
|
||||
))}
|
||||
</FormGroup>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
)}
|
||||
</Stack>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button
|
||||
onClick={clearAll}
|
||||
color="inherit"
|
||||
disabled={Object.keys(localFilters).length === 0}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
restore();
|
||||
restoreVideo();
|
||||
restoreGenres();
|
||||
}}
|
||||
color="inherit"
|
||||
disabled={!dirty}
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
<Button onClick={onClose}>Cancel</Button>
|
||||
<Button onClick={apply} disabled={!dirty} variant="contained">
|
||||
Apply
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
},
|
||||
);
|
||||
(FiltersDialog as any).displayName = "FiltersDialog";
|
||||
|
||||
export const FiltersDialogTrigger: React.FC = () => {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const { id: currentLibraryId } = route.useParams();
|
||||
const { filters, videoTypesState, genreIds } = useLibraryStateStore(
|
||||
useShallow((s) => {
|
||||
const slice = s.libraries[currentLibraryId || ""];
|
||||
return {
|
||||
filters: slice?.filters,
|
||||
videoTypesState: slice?.videoTypesState,
|
||||
genreIds: slice?.genreIds,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const activeCount = useMemo(() => {
|
||||
const a = Object.values(filters || {}).filter((v) => v === true).length;
|
||||
const b = Object.values(videoTypesState || {}).filter(
|
||||
(v) => v === true,
|
||||
).length;
|
||||
const c = (genreIds || []).length;
|
||||
return a + b + c;
|
||||
}, [filters, videoTypesState, genreIds]);
|
||||
return (
|
||||
<>
|
||||
<Tooltip
|
||||
title={activeCount ? `${activeCount} active filters` : "Filters"}
|
||||
>
|
||||
<IconButton
|
||||
onClick={() => setOpen(true)}
|
||||
aria-label="Open filters dialog"
|
||||
>
|
||||
<div
|
||||
className="material-symbols-rounded"
|
||||
style={{ position: "relative" }}
|
||||
>
|
||||
filter_list
|
||||
{activeCount > 0 && (
|
||||
<span
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: -2,
|
||||
right: -4,
|
||||
background: "#ff4081",
|
||||
color: "#fff",
|
||||
fontSize: 10,
|
||||
borderRadius: 8,
|
||||
lineHeight: 1,
|
||||
padding: "2px 4px",
|
||||
fontFamily: "Plus Jakarta Sans Variable",
|
||||
}}
|
||||
>
|
||||
{activeCount}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<FiltersDialog open={open} onClose={() => setOpen(false)} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default FiltersDialog;
|
||||
@@ -0,0 +1,362 @@
|
||||
import type { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { ItemSortBy, SortOrder } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import {
|
||||
AppBar,
|
||||
Chip,
|
||||
IconButton,
|
||||
MenuItem,
|
||||
TextField,
|
||||
Typography,
|
||||
useScrollTrigger,
|
||||
} from "@mui/material";
|
||||
import { useQueryClient, useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { getRouteApi, useNavigate } from "@tanstack/react-router";
|
||||
import type { ChangeEvent } from "react";
|
||||
import React, { useCallback, useEffect, useMemo } from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { AVAILABLE_VIEWS, SORT_BY_OPTIONS } from "@/utils/constants/library";
|
||||
import { getLibraryQueryOptions } from "@/utils/queries/library";
|
||||
// import removed: header reads name/count from Zustand slice
|
||||
import { useLibraryStateStore } from "@/utils/store/libraryState";
|
||||
import "./libraryHeader.scss";
|
||||
import BackButton from "../buttons/backButton";
|
||||
import { FiltersDialogTrigger } from "../filtersDialog";
|
||||
import { UserAvatarMenu } from "../userAvatarMenu";
|
||||
|
||||
const route = getRouteApi("/_api/library/$id");
|
||||
|
||||
const MemoizeBackButton = React.memo(BackButton);
|
||||
|
||||
export const LibraryHeader = () => {
|
||||
const { id: currentLibraryId } = route.useParams();
|
||||
const { api, user } = route.useRouteContext();
|
||||
const navigate = useNavigate();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// Zustand library state (selected via shallow comparator)
|
||||
const {
|
||||
currentViewType,
|
||||
storeSortBy,
|
||||
storeSortAscending,
|
||||
filters,
|
||||
vts,
|
||||
nameStartsWith,
|
||||
genreIds,
|
||||
libraryNameFromStore,
|
||||
itemsTotalCount,
|
||||
} = useLibraryStateStore(
|
||||
useShallow((s) => {
|
||||
const slice = s.libraries[currentLibraryId || ""];
|
||||
return {
|
||||
currentViewType: slice?.currentViewType,
|
||||
storeSortBy: slice?.sortBy,
|
||||
storeSortAscending: slice?.sortAscending,
|
||||
filters: slice?.filters,
|
||||
vts: slice?.videoTypesState,
|
||||
nameStartsWith: slice?.nameStartsWith,
|
||||
genreIds: slice?.genreIds,
|
||||
libraryNameFromStore: slice?.libraryName,
|
||||
itemsTotalCount: slice?.itemsTotalCount,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const { initLibrary, updateLibrary } = useLibraryStateStore(
|
||||
useShallow((s) => ({
|
||||
initLibrary: s.initLibrary,
|
||||
updateLibrary: s.updateLibrary,
|
||||
})),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentLibraryId) return;
|
||||
// If the slice isn't initialized, these fields will be undefined
|
||||
if (
|
||||
currentViewType === undefined &&
|
||||
storeSortBy === undefined &&
|
||||
storeSortAscending === undefined
|
||||
) {
|
||||
initLibrary(currentLibraryId, {
|
||||
sortBy: ItemSortBy.Name,
|
||||
sortAscending: true,
|
||||
});
|
||||
}
|
||||
}, [
|
||||
currentLibraryId,
|
||||
currentViewType,
|
||||
storeSortBy,
|
||||
storeSortAscending,
|
||||
initLibrary,
|
||||
]);
|
||||
const currentLibrary = useSuspenseQuery(
|
||||
getLibraryQueryOptions(api, user?.Id, currentLibraryId),
|
||||
);
|
||||
const scrollTrigger = useScrollTrigger({
|
||||
disableHysteresis: true,
|
||||
threshold: 20,
|
||||
});
|
||||
|
||||
const compatibleViews = useMemo(
|
||||
() =>
|
||||
AVAILABLE_VIEWS.filter((v) =>
|
||||
v.compatibleCollectionTypes.includes(
|
||||
currentLibrary.data.CollectionType as any,
|
||||
),
|
||||
),
|
||||
[currentLibrary.data.CollectionType],
|
||||
);
|
||||
// Values from store
|
||||
const sortBy = (storeSortBy ?? ItemSortBy.Name) as string;
|
||||
const sortAscending = storeSortAscending ?? true;
|
||||
const effectiveViewType = currentViewType as any;
|
||||
const effectiveSortByRaw = sortBy;
|
||||
const effectiveSortAscending = sortAscending;
|
||||
|
||||
const normalizedViewType = useMemo(() => {
|
||||
const values = compatibleViews.map((v) => v.value);
|
||||
if (effectiveViewType && values.includes(effectiveViewType as any))
|
||||
return effectiveViewType as any;
|
||||
return values[0] as BaseItemKind | "Artist";
|
||||
}, [effectiveViewType, compatibleViews]);
|
||||
|
||||
const normalizedSortBy = useMemo(() => {
|
||||
const compatibleOptions = SORT_BY_OPTIONS.filter(
|
||||
(option) =>
|
||||
option.compatibleViewTypes?.includes(normalizedViewType as any) ||
|
||||
option.compatibleCollectionTypes?.includes(
|
||||
currentLibrary.data.CollectionType as any,
|
||||
),
|
||||
);
|
||||
const compatibleValues = compatibleOptions.map((opt) =>
|
||||
Array.isArray(opt.value) ? opt.value.join(",") : String(opt.value),
|
||||
);
|
||||
const current = String(effectiveSortByRaw ?? "");
|
||||
if (current && compatibleValues.includes(current)) return current;
|
||||
return compatibleValues[0] ?? String(ItemSortBy.Name);
|
||||
}, [
|
||||
effectiveSortByRaw,
|
||||
normalizedViewType,
|
||||
currentLibrary.data.CollectionType,
|
||||
]);
|
||||
|
||||
const handleChangeViewType = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const next = e.target.value as unknown as BaseItemKind | "Artist";
|
||||
if (currentLibraryId)
|
||||
updateLibrary(currentLibraryId, { currentViewType: next });
|
||||
};
|
||||
const handleChangeSortBy = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const next = e.target.value as unknown as string;
|
||||
if (currentLibraryId) updateLibrary(currentLibraryId, { sortBy: next });
|
||||
};
|
||||
const handleSortAscendingToggle = () => {
|
||||
if (currentLibraryId)
|
||||
updateLibrary(currentLibraryId, {
|
||||
sortAscending: !effectiveSortAscending,
|
||||
});
|
||||
};
|
||||
|
||||
// (Video type multi-select temporarily removed; logic cleaned to reduce overhead.)
|
||||
|
||||
// Prefetch helpers to reduce perceived latency on sort changes
|
||||
// filters, vts, nameStartsWith, genreIds are already selected above
|
||||
// Prefetch handler will be attached on menu items below
|
||||
const prefetchItems = useCallback(
|
||||
async (sortByValue: string, asc: boolean) => {
|
||||
if (!api || !user?.Id || !currentLibraryId || !normalizedViewType) return;
|
||||
const key = [
|
||||
"library",
|
||||
"items",
|
||||
currentLibraryId,
|
||||
{
|
||||
currentViewType: normalizedViewType,
|
||||
sortAscending: asc,
|
||||
sortBy: sortByValue,
|
||||
filters,
|
||||
videoTypesState: vts,
|
||||
nameStartsWith,
|
||||
genreIds,
|
||||
},
|
||||
] as const;
|
||||
await queryClient.prefetchQuery({
|
||||
queryKey: key,
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.Id!,
|
||||
parentId: currentLibraryId,
|
||||
recursive: true,
|
||||
includeItemTypes: [normalizedViewType as any],
|
||||
sortOrder: [asc ? SortOrder.Ascending : SortOrder.Descending],
|
||||
sortBy: String(sortByValue).split(",") as any,
|
||||
enableUserData: true,
|
||||
nameStartsWith: nameStartsWith || undefined,
|
||||
genreIds: genreIds && genreIds.length > 0 ? genreIds : undefined,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
staleTime: 5_000,
|
||||
});
|
||||
},
|
||||
[
|
||||
api,
|
||||
user?.Id,
|
||||
currentLibraryId,
|
||||
normalizedViewType,
|
||||
filters,
|
||||
vts,
|
||||
nameStartsWith,
|
||||
genreIds,
|
||||
queryClient,
|
||||
],
|
||||
);
|
||||
|
||||
const disableSortOption = useMemo(
|
||||
() =>
|
||||
!normalizedViewType ||
|
||||
!SORT_BY_OPTIONS.some(
|
||||
(option) =>
|
||||
option.compatibleViewTypes?.includes(normalizedViewType as any) ||
|
||||
option.compatibleCollectionTypes?.includes(
|
||||
currentLibrary.data.CollectionType as any,
|
||||
),
|
||||
),
|
||||
[normalizedViewType, currentLibrary.data.CollectionType],
|
||||
);
|
||||
|
||||
const appBarStyling = useMemo(
|
||||
() => ({ backgroundColor: "transparent", paddingRight: "0 !important" }),
|
||||
[],
|
||||
);
|
||||
|
||||
// Read values from Zustand: name set by route, count set by grid
|
||||
const libraryName = libraryNameFromStore ?? currentLibrary.data.Name;
|
||||
const totalCount = itemsTotalCount;
|
||||
|
||||
const handleNavigateToSearch = useCallback(
|
||||
() => navigate({ to: "/search", search: { query: "" } }),
|
||||
[navigate],
|
||||
);
|
||||
const handleNavigateToHome = useCallback(
|
||||
() => navigate({ to: "/home" }),
|
||||
[navigate],
|
||||
);
|
||||
const handleNavigateToFavorite = useCallback(
|
||||
() => navigate({ to: "/favorite" }),
|
||||
[navigate],
|
||||
);
|
||||
|
||||
return (
|
||||
<AppBar
|
||||
className={
|
||||
scrollTrigger
|
||||
? "library-header scrolling flex flex-row"
|
||||
: "library-header flex flex-row"
|
||||
}
|
||||
style={appBarStyling}
|
||||
elevation={0}
|
||||
color="transparent"
|
||||
>
|
||||
<div className="flex flex-row" style={{ gap: "0.6em" }}>
|
||||
<IconButton disabled>
|
||||
<div className="material-symbols-rounded">menu</div>
|
||||
</IconButton>
|
||||
<MemoizeBackButton />
|
||||
<IconButton onClick={handleNavigateToHome}>
|
||||
<div
|
||||
className={
|
||||
location.pathname === "/home"
|
||||
? "material-symbols-rounded fill"
|
||||
: "material-symbols-rounded"
|
||||
}
|
||||
>
|
||||
home
|
||||
</div>
|
||||
</IconButton>
|
||||
</div>
|
||||
<div
|
||||
className="flex flex-row library-header-center"
|
||||
style={{ gap: "0.6em" }}
|
||||
>
|
||||
<div
|
||||
className="library-title-count flex flex-row flex-align-center"
|
||||
title={`${libraryName}${typeof totalCount === "number" ? ` · ${totalCount.toLocaleString()} items` : ""}`}
|
||||
>
|
||||
<Typography variant="subtitle1" noWrap align="center">
|
||||
{libraryName}
|
||||
</Typography>
|
||||
{typeof totalCount === "number" && (
|
||||
<Chip label={totalCount} sx={{ px: 0.5, ml: 1 }} />
|
||||
)}
|
||||
</div>
|
||||
<TextField
|
||||
select
|
||||
size="small"
|
||||
value={String(normalizedViewType)}
|
||||
onChange={handleChangeViewType}
|
||||
>
|
||||
{compatibleViews.map((v) => (
|
||||
<MenuItem key={String(v.value)} value={String(v.value)}>
|
||||
{v.title}
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
<IconButton
|
||||
onClick={handleSortAscendingToggle}
|
||||
aria-label="Toggle sort order"
|
||||
>
|
||||
<div
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
transform: sortAscending ? "rotateX(0deg)" : "rotateX(180deg)",
|
||||
}}
|
||||
>
|
||||
sort
|
||||
</div>
|
||||
</IconButton>
|
||||
<TextField
|
||||
select
|
||||
size="small"
|
||||
value={normalizedSortBy}
|
||||
onChange={handleChangeSortBy}
|
||||
disabled={disableSortOption}
|
||||
>
|
||||
{SORT_BY_OPTIONS.map((option) => {
|
||||
const isCompatible =
|
||||
option.compatibleViewTypes?.includes(currentViewType as any) ||
|
||||
option.compatibleCollectionTypes?.includes(
|
||||
currentLibrary.data.CollectionType as any,
|
||||
);
|
||||
if (!isCompatible) return null;
|
||||
const valueStr = Array.isArray(option.value)
|
||||
? option.value.join(",")
|
||||
: option.value;
|
||||
return (
|
||||
<MenuItem
|
||||
key={
|
||||
Array.isArray(option.value)
|
||||
? option.value.join(",")
|
||||
: option.value
|
||||
}
|
||||
value={valueStr}
|
||||
onMouseEnter={() =>
|
||||
prefetchItems(String(valueStr), sortAscending)
|
||||
}
|
||||
>
|
||||
{option.title}
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</TextField>
|
||||
<FiltersDialogTrigger />
|
||||
</div>
|
||||
<div className="flex flex-row" style={{ gap: "0.6em" }}>
|
||||
<IconButton onClick={handleNavigateToSearch}>
|
||||
<div className="material-symbols-rounded">search</div>
|
||||
</IconButton>
|
||||
<IconButton onClick={handleNavigateToFavorite}>
|
||||
<div className="material-symbols-rounded">favorite</div>
|
||||
</IconButton>
|
||||
<UserAvatarMenu />
|
||||
</div>
|
||||
</AppBar>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
.library-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
inset: 1em 1em auto 1em !important;
|
||||
border-radius: 9999px;
|
||||
margin: 0 auto;
|
||||
width: fit-content;
|
||||
position: sticky;
|
||||
width: calc(100vw - 4em) !important;
|
||||
z-index: 10;
|
||||
padding: 0.25em !important;
|
||||
transition: all 0.2s ease-in-out;
|
||||
|
||||
&::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
backdrop-filter: blur(40px);
|
||||
inset: -0.35em;
|
||||
pointer-events: none;
|
||||
border-radius: inherit;
|
||||
box-shadow: 0 0 25px rgb(0 0 0 / 0.45);
|
||||
background: rgb(0 0 0 / 0.4);
|
||||
opacity: 0;
|
||||
z-index: -1;
|
||||
transition: opacity $transition-time-fast;
|
||||
}
|
||||
|
||||
&.scrolling {
|
||||
&::after {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,239 +1,315 @@
|
||||
import {
|
||||
type BaseItemDtoQueryResult,
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
ItemFilter,
|
||||
type ItemSortBy,
|
||||
SortOrder,
|
||||
VideoType,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getArtistsApi } from "@jellyfin/sdk/lib/utils/api/artists-api";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { getPersonsApi } from "@jellyfin/sdk/lib/utils/api/persons-api";
|
||||
import { getStudiosApi } from "@jellyfin/sdk/lib/utils/api/studios-api";
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { getRouteApi } from "@tanstack/react-router";
|
||||
import type { AxiosResponse } from "axios";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { useVirtualizer } from "@tanstack/react-virtual";
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import "./libraryItemsGrid.scss";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import { getLibraryQueryOptions } from "@/utils/queries/library";
|
||||
import { getLibraryItemsQueryOptions } from "@/utils/queries/libraryItems";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { useLibraryStateStore } from "@/utils/store/libraryState";
|
||||
import { Card } from "../card/card";
|
||||
|
||||
const libraryRoute = getRouteApi("/_api/library/$id");
|
||||
|
||||
/**
|
||||
* Virtualized library items grid.
|
||||
* Virtualizes vertical scrolling only; items are arranged into responsive columns.
|
||||
* Assumptions:
|
||||
* - Card aspect ratio handled by CSS; we approximate a fixed height for virtualization.
|
||||
* - Width changes trigger re-measure via ResizeObserver.
|
||||
* Future improvements:
|
||||
* - Dynamic row height based on item type.
|
||||
* - Horizontal virtualization for extremely wide displays.
|
||||
*/
|
||||
const LibraryItemsGrid = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const { id: currentLibraryId } = libraryRoute.useParams();
|
||||
const {
|
||||
currentViewType,
|
||||
sortAscending = true,
|
||||
sortBy = "SortName",
|
||||
filters = {},
|
||||
videoTypesState = {},
|
||||
} = libraryRoute.useSearch();
|
||||
const currentLibraryId = libraryRoute.useParams().id;
|
||||
sortAscending,
|
||||
sortBy,
|
||||
filters,
|
||||
videoTypesState,
|
||||
nameStartsWith,
|
||||
genreIds,
|
||||
} = useLibraryStateStore(
|
||||
useShallow((s) => {
|
||||
const slice = s.libraries[currentLibraryId || ""];
|
||||
return {
|
||||
currentViewType: slice?.currentViewType,
|
||||
sortAscending: slice?.sortAscending ?? true,
|
||||
sortBy: slice?.sortBy ?? "Name",
|
||||
filters: slice?.filters,
|
||||
videoTypesState: slice?.videoTypesState,
|
||||
nameStartsWith: slice?.nameStartsWith,
|
||||
genreIds: slice?.genreIds,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const updateLibrary = useLibraryStateStore((s) => s.updateLibrary);
|
||||
const currentLibrary = useSuspenseQuery(
|
||||
getLibraryQueryOptions(api, user?.Id, currentLibraryId),
|
||||
);
|
||||
const items = useSuspenseQuery({
|
||||
queryKey: [
|
||||
"library",
|
||||
"items",
|
||||
currentLibraryId,
|
||||
{
|
||||
currentViewType: currentViewType,
|
||||
sortAscending: sortAscending,
|
||||
sortBy: sortBy,
|
||||
filters,
|
||||
videoTypesState,
|
||||
// genreFilter,
|
||||
},
|
||||
],
|
||||
queryFn: async () => {
|
||||
if (!api) return null;
|
||||
let result: AxiosResponse<BaseItemDtoQueryResult, any>;
|
||||
if (currentViewType === "MusicArtist") {
|
||||
result = await getArtistsApi(api).getAlbumArtists({
|
||||
userId: user?.Id,
|
||||
parentId: currentLibraryId,
|
||||
});
|
||||
} else if (currentViewType === "Artist") {
|
||||
result = await getArtistsApi(api).getArtists({
|
||||
userId: user?.Id,
|
||||
parentId: currentLibraryId,
|
||||
});
|
||||
} else if (currentViewType === "Person") {
|
||||
result = await getPersonsApi(api).getPersons({
|
||||
userId: user?.Id,
|
||||
personTypes: ["Actor"],
|
||||
});
|
||||
} else if (currentViewType === "Studio") {
|
||||
result = await getStudiosApi(api).getStudios({
|
||||
userId: user?.Id,
|
||||
parentId: currentLibraryId,
|
||||
});
|
||||
} else if (currentViewType === "BoxSet") {
|
||||
const videoTypes: VideoType[] = [];
|
||||
if (videoTypesState.BluRay) videoTypes.push(VideoType.BluRay);
|
||||
if (videoTypesState.Dvd) videoTypes.push(VideoType.Dvd);
|
||||
if (videoTypesState.Iso) videoTypes.push(VideoType.Iso);
|
||||
if (videoTypesState.VideoFile) videoTypes.push(VideoType.VideoFile);
|
||||
|
||||
const filtersArray: ItemFilter[] = [];
|
||||
if (filters.isPlayed) filtersArray.push(ItemFilter.IsPlayed);
|
||||
if (filters.isUnPlayed) filtersArray.push(ItemFilter.IsUnplayed);
|
||||
if (filters.isResumable) filtersArray.push(ItemFilter.IsResumable);
|
||||
if (filters.isFavorite) filtersArray.push(ItemFilter.IsFavorite);
|
||||
|
||||
result = await getItemsApi(api).getItems({
|
||||
userId: user?.Id,
|
||||
parentId: currentLibraryId,
|
||||
recursive:
|
||||
currentLibrary.data.CollectionType === "boxsets" ? undefined : true,
|
||||
// includeItemTypes: [currentViewType],
|
||||
sortOrder: [
|
||||
sortAscending ? SortOrder.Ascending : SortOrder.Descending,
|
||||
],
|
||||
sortBy: sortBy.split(",") as ItemSortBy[],
|
||||
filters: filtersArray,
|
||||
hasSubtitles: filters.hasSubtitles ? true : undefined,
|
||||
hasTrailer: filters.hasTrailer ? true : undefined,
|
||||
hasSpecialFeature: filters.hasSpecialFeature ? true : undefined,
|
||||
hasThemeSong: filters.hasThemeSong ? true : undefined,
|
||||
hasThemeVideo: filters.hasThemeVideo ? true : undefined,
|
||||
videoTypes: videoTypes,
|
||||
isHd: filters.isSD ? true : filters.isHD || undefined,
|
||||
is4K: filters.is4K || undefined,
|
||||
is3D: filters.is3D || undefined,
|
||||
enableUserData: true,
|
||||
// genreIds: genreFilter,
|
||||
});
|
||||
} else {
|
||||
const videoTypes: VideoType[] = [];
|
||||
if (videoTypesState.BluRay) videoTypes.push(VideoType.BluRay);
|
||||
if (videoTypesState.Dvd) videoTypes.push(VideoType.Dvd);
|
||||
if (videoTypesState.Iso) videoTypes.push(VideoType.Iso);
|
||||
if (videoTypesState.VideoFile) videoTypes.push(VideoType.VideoFile);
|
||||
|
||||
const filtersArray: ItemFilter[] = [];
|
||||
if (filters.isPlayed) filtersArray.push(ItemFilter.IsPlayed);
|
||||
if (filters.isUnPlayed) filtersArray.push(ItemFilter.IsUnplayed);
|
||||
if (filters.isResumable) filtersArray.push(ItemFilter.IsResumable);
|
||||
if (filters.isFavorite) filtersArray.push(ItemFilter.IsFavorite);
|
||||
if (!currentViewType) {
|
||||
throw new Error("currentViewType is required");
|
||||
}
|
||||
result = await getItemsApi(api).getItems({
|
||||
userId: user?.Id,
|
||||
parentId: currentLibraryId,
|
||||
recursive: true,
|
||||
includeItemTypes: [currentViewType],
|
||||
sortOrder: [
|
||||
sortAscending ? SortOrder.Ascending : SortOrder.Descending,
|
||||
],
|
||||
sortBy: sortBy.split(",") as ItemSortBy[],
|
||||
filters: filtersArray,
|
||||
hasSubtitles: filters.hasSubtitles ? true : undefined,
|
||||
hasTrailer: filters.hasTrailer ? true : undefined,
|
||||
hasSpecialFeature: filters.hasSpecialFeature ? true : undefined,
|
||||
hasThemeSong: filters.hasThemeSong ? true : undefined,
|
||||
hasThemeVideo: filters.hasThemeVideo ? true : undefined,
|
||||
videoTypes: videoTypes,
|
||||
isHd: filters.isSD ? true : filters.isHD || undefined,
|
||||
is4K: filters.is4K || undefined,
|
||||
is3D: filters.is3D || undefined,
|
||||
enableUserData: true,
|
||||
// genreIds: genreFilter,
|
||||
});
|
||||
}
|
||||
return result.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
const items = useSuspenseQuery(
|
||||
getLibraryItemsQueryOptions(api, user?.Id, currentLibraryId, {
|
||||
currentViewType,
|
||||
sortAscending,
|
||||
sortBy,
|
||||
filters,
|
||||
videoTypesState,
|
||||
nameStartsWith,
|
||||
genreIds,
|
||||
collectionType: currentLibrary.data.CollectionType as any,
|
||||
}),
|
||||
);
|
||||
// --- Backdrop ---
|
||||
const setBackdrop = useBackdropStore(useShallow((s) => s.setBackdrop));
|
||||
const [currentBackdropIndex, setCurrentBackdropIndex] = useState(1);
|
||||
const backdropItems = useMemo(() => {
|
||||
if (items.isSuccess) {
|
||||
const temp = items.data?.Items?.filter(
|
||||
(item) => Object.keys(item.ImageBlurHashes?.Backdrop ?? {}).length > 0,
|
||||
);
|
||||
const backdropItem = temp?.[0];
|
||||
|
||||
const currentBackdropItemHash =
|
||||
backdropItem?.ImageBlurHashes?.Backdrop?.[
|
||||
Object.keys(backdropItem?.ImageBlurHashes?.Backdrop ?? {})[0]
|
||||
];
|
||||
setBackdrop(currentBackdropItemHash);
|
||||
|
||||
return temp;
|
||||
}
|
||||
}, [items]);
|
||||
const backdropIndexRef = useRef(0);
|
||||
const backdropItems = useMemo<BaseItemDto[]>(() => {
|
||||
if (!items.isSuccess || !items.data?.Items) return [];
|
||||
return items.data.Items.filter(
|
||||
(item) => Object.keys(item.ImageBlurHashes?.Backdrop ?? {}).length > 0,
|
||||
);
|
||||
}, [items.isSuccess, items.data?.Items]);
|
||||
useEffect(() => {
|
||||
if (backdropItems?.length === 0 || !api || !backdropItems) {
|
||||
return; // No backdrop items available
|
||||
}
|
||||
if (!api || !backdropItems || backdropItems.length === 0) return;
|
||||
// Set initial backdrop once when items change
|
||||
const firstBackdrop = backdropItems[0];
|
||||
const firstKey = Object.keys(
|
||||
firstBackdrop?.ImageBlurHashes?.Backdrop ?? {},
|
||||
)[0];
|
||||
const initialHash = firstBackdrop?.ImageBlurHashes?.Backdrop?.[firstKey];
|
||||
if (initialHash) setBackdrop(initialHash);
|
||||
backdropIndexRef.current = 0;
|
||||
|
||||
const intervalId = setInterval(() => {
|
||||
const currentBackdropItemHash =
|
||||
backdropItems[currentBackdropIndex].ImageBlurHashes?.Backdrop?.[
|
||||
Object.keys(
|
||||
backdropItems[currentBackdropIndex].ImageBlurHashes?.Backdrop ?? {},
|
||||
)[0]
|
||||
];
|
||||
if (!currentBackdropItemHash) return; // No backdrop image available
|
||||
setBackdrop(currentBackdropItemHash);
|
||||
setCurrentBackdropIndex(
|
||||
(prevIndex) => (prevIndex + 1) % backdropItems.length,
|
||||
backdropIndexRef.current =
|
||||
(backdropIndexRef.current + 1) % backdropItems.length;
|
||||
const idx = backdropIndexRef.current;
|
||||
const keys = Object.keys(
|
||||
backdropItems[idx]?.ImageBlurHashes?.Backdrop ?? {},
|
||||
);
|
||||
const nextHash = backdropItems[idx]?.ImageBlurHashes?.Backdrop?.[keys[0]];
|
||||
if (nextHash) {
|
||||
// Defer backdrop update to idle/raf to avoid blocking UI
|
||||
const schedule =
|
||||
(window as any).requestIdleCallback || window.requestAnimationFrame;
|
||||
schedule(() => setBackdrop(nextHash));
|
||||
}
|
||||
}, 10_000); // Update backdrop every 10s
|
||||
return () => clearInterval(intervalId);
|
||||
}, [backdropItems]);
|
||||
}, [api, backdropItems, setBackdrop]);
|
||||
// --- Virtualization setup ---
|
||||
const parentRef = useRef<HTMLDivElement | null>(null);
|
||||
const scrollParentRef = useRef<HTMLElement | null>(null);
|
||||
const [containerWidth, setContainerWidth] = useState<number>(0);
|
||||
|
||||
// Determine column count based on container width (simple heuristic)
|
||||
const [columns, setColumns] = useState(1);
|
||||
const measureColumns = useCallback(() => {
|
||||
if (!parentRef.current) return;
|
||||
const width = parentRef.current.clientWidth;
|
||||
setContainerWidth(width);
|
||||
// Base desired approximate card width (including gap) 180px
|
||||
const ideal = Math.max(1, Math.floor(width / 180));
|
||||
setColumns(ideal);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
measureColumns();
|
||||
if (!parentRef.current) return;
|
||||
// Find the page's scroll container ('.scrollY') to avoid nested scrolling
|
||||
scrollParentRef.current = parentRef.current.closest(
|
||||
".scrollY",
|
||||
) as HTMLElement | null;
|
||||
const ro = new ResizeObserver(() => measureColumns());
|
||||
ro.observe(parentRef.current);
|
||||
return () => ro.disconnect();
|
||||
}, [measureColumns]);
|
||||
|
||||
const itemCount = items.data?.Items?.length ?? 0;
|
||||
// Compute number of virtual rows
|
||||
const rowCount = Math.ceil(itemCount / columns);
|
||||
|
||||
// Estimated row height (depends on card type). Using 260px as base (portrait taller)
|
||||
// Compute card width minus gaps
|
||||
const cardGap = 16; // px gap between cards
|
||||
const cardWidth = useMemo(() => {
|
||||
if (columns <= 0) return 180;
|
||||
const totalGap = (columns - 1) * cardGap;
|
||||
return Math.floor((containerWidth - totalGap) / columns);
|
||||
}, [columns, containerWidth]);
|
||||
|
||||
// Approximate tallest card height (portrait ratio ~ 2:3 => height ≈ width / 0.666) + text/footer area
|
||||
// We add a small buffer (20px) for hover overlays and progress bars
|
||||
const estimatedTallCardHeight = useMemo(
|
||||
() => Math.round(cardWidth / 0.666666 + 90),
|
||||
[cardWidth],
|
||||
);
|
||||
|
||||
const estimateRowHeight = useCallback(
|
||||
() => estimatedTallCardHeight,
|
||||
[estimatedTallCardHeight],
|
||||
);
|
||||
|
||||
const virtualizer = useVirtualizer({
|
||||
count: rowCount,
|
||||
getScrollElement: () => scrollParentRef.current,
|
||||
estimateSize: estimateRowHeight,
|
||||
overscan: 2,
|
||||
});
|
||||
|
||||
const virtualItems = virtualizer.getVirtualItems();
|
||||
|
||||
// Update count in Zustand so header can display it without extra fetches
|
||||
useEffect(() => {
|
||||
const total = items.data?.TotalRecordCount;
|
||||
if (currentLibraryId && typeof total === "number") {
|
||||
updateLibrary(currentLibraryId, { itemsTotalCount: total });
|
||||
}
|
||||
}, [items.data?.TotalRecordCount, currentLibraryId, updateLibrary]);
|
||||
|
||||
return (
|
||||
<div className="library-items-container">
|
||||
{items.data?.Items?.map((item) => (
|
||||
<Card
|
||||
item={item}
|
||||
key={item?.Id}
|
||||
seriesId={item?.SeriesId}
|
||||
cardTitle={
|
||||
item?.Type === BaseItemKind.Episode ? item.SeriesName : item?.Name
|
||||
}
|
||||
imageType={"Primary"}
|
||||
cardCaption={
|
||||
item?.Type === BaseItemKind.Episode
|
||||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
||||
: item?.Type === BaseItemKind.Series
|
||||
? `${item.ProductionYear} - ${
|
||||
item.EndDate
|
||||
? new Date(item.EndDate).toLocaleString([], {
|
||||
year: "numeric",
|
||||
})
|
||||
: "Present"
|
||||
}`
|
||||
: item?.ProductionYear
|
||||
}
|
||||
disableOverlay={
|
||||
item?.Type === BaseItemKind.Person ||
|
||||
item?.Type === BaseItemKind.Genre ||
|
||||
item?.Type === BaseItemKind.MusicGenre ||
|
||||
item?.Type === BaseItemKind.Studio
|
||||
}
|
||||
cardType={
|
||||
item?.Type === BaseItemKind.MusicAlbum ||
|
||||
item?.Type === BaseItemKind.Audio ||
|
||||
item?.Type === BaseItemKind.Genre ||
|
||||
item?.Type === BaseItemKind.MusicGenre ||
|
||||
item?.Type === BaseItemKind.Studio ||
|
||||
item?.Type === BaseItemKind.Playlist
|
||||
? "square"
|
||||
: "portrait"
|
||||
}
|
||||
// queryKey={items}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
))}
|
||||
<div
|
||||
ref={parentRef}
|
||||
className="library-items-container virtualized"
|
||||
style={{ position: "relative" }}
|
||||
>
|
||||
{items.isSuccess && itemCount === 0 ? (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
minHeight: 240,
|
||||
width: "100%",
|
||||
opacity: 0.8,
|
||||
}}
|
||||
>
|
||||
<div style={{ textAlign: "center" }}>
|
||||
<div
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: 48, marginBottom: 8 }}
|
||||
>
|
||||
sentiment_dissatisfied
|
||||
</div>
|
||||
<div style={{ fontSize: 16 }}>No items to show</div>
|
||||
<div style={{ fontSize: 13, marginTop: 6 }}>
|
||||
Try adjusting filters, sort, or the A–Z selector.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
style={{
|
||||
position: "relative",
|
||||
height: virtualizer.getTotalSize(),
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
{virtualItems.map((row) => {
|
||||
const startIndex = row.index * columns;
|
||||
const endIndex = Math.min(startIndex + columns, itemCount);
|
||||
return (
|
||||
<div
|
||||
key={row.key}
|
||||
style={{
|
||||
position: "absolute",
|
||||
transform: `translateY(${row.start}px)`,
|
||||
left: 0,
|
||||
width: "100%",
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "flex-start",
|
||||
gap: `${cardGap}px`,
|
||||
// Allow natural height; virtualizer will update size after measurement.
|
||||
paddingBottom: "0.6em",
|
||||
}}
|
||||
data-index={row.index}
|
||||
ref={(el) => {
|
||||
if (el) virtualizer.measureElement(el);
|
||||
}}
|
||||
>
|
||||
{items.data?.Items?.slice(startIndex, endIndex).map(
|
||||
(item: BaseItemDto, localIndex: number) => {
|
||||
return (
|
||||
<div
|
||||
key={item?.Id ?? localIndex}
|
||||
style={{
|
||||
width: `${cardWidth}px`,
|
||||
flex: "0 0 auto",
|
||||
// Override default card margins to avoid compounding with gaps
|
||||
margin: 0,
|
||||
}}
|
||||
>
|
||||
<Card
|
||||
item={item}
|
||||
seriesId={item?.SeriesId}
|
||||
skipInView
|
||||
cardTitle={
|
||||
item?.Type === BaseItemKind.Episode
|
||||
? item.SeriesName
|
||||
: item?.Name
|
||||
}
|
||||
imageType={"Primary"}
|
||||
cardCaption={
|
||||
item?.Type === BaseItemKind.Episode
|
||||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
||||
: item?.Type === BaseItemKind.Series
|
||||
? `${item.ProductionYear} - ${
|
||||
item.EndDate
|
||||
? new Date(item.EndDate).toLocaleString(
|
||||
[],
|
||||
{
|
||||
year: "numeric",
|
||||
},
|
||||
)
|
||||
: "Present"
|
||||
}`
|
||||
: item?.ProductionYear
|
||||
}
|
||||
disableOverlay={
|
||||
item?.Type === BaseItemKind.Person ||
|
||||
item?.Type === BaseItemKind.Genre ||
|
||||
item?.Type === BaseItemKind.MusicGenre ||
|
||||
item?.Type === BaseItemKind.Studio
|
||||
}
|
||||
cardType={
|
||||
item?.Type === BaseItemKind.MusicAlbum ||
|
||||
item?.Type === BaseItemKind.Audio ||
|
||||
item?.Type === BaseItemKind.Genre ||
|
||||
item?.Type === BaseItemKind.MusicGenre ||
|
||||
item?.Type === BaseItemKind.Studio ||
|
||||
item?.Type === BaseItemKind.Playlist
|
||||
? "square"
|
||||
: "portrait"
|
||||
}
|
||||
userId={user?.Id}
|
||||
// Inline style overrides to neutralize original margins for virtualization
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Overrides for virtualized library items layout to prevent horizontal overflow
|
||||
.library-items-container.virtualized {
|
||||
overflow-x: hidden;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
display: block !important; // override grid from route styles
|
||||
padding: 0 !important; // override padding from route styles
|
||||
position: relative; // required for absolutely positioned rows
|
||||
gap: 0 !important;
|
||||
justify-items: normal !important;
|
||||
align-content: stretch !important;
|
||||
> .card {
|
||||
max-width: none !important;
|
||||
}
|
||||
// Ensure no unintended padding expands width
|
||||
padding-right: 0;
|
||||
padding-left: 0;
|
||||
.card {
|
||||
margin-right: 0 !important;
|
||||
margin-bottom: 0.6em !important; // keep a consistent vertical rhythm
|
||||
}
|
||||
.card-image-container {
|
||||
// Remove box shadow spread from affecting layout width calculation
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
|
||||
// When page has audio-playing class, avoid extra bottom padding causing scrollbars
|
||||
.audio-playing .library-items-container.virtualized {
|
||||
padding-bottom: 8em; // mimic original intent without affecting width
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useScrollTrigger } from "@mui/material";
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { getRouteApi, useNavigate } from "@tanstack/react-router";
|
||||
import React, { type ChangeEvent, useMemo } from "react";
|
||||
import {
|
||||
AVAILABLE_VIEWS,
|
||||
type FILTERS,
|
||||
SORT_BY_OPTIONS,
|
||||
} from "@/utils/constants/library";
|
||||
import { getLibraryQueryOptions } from "@/utils/queries/library";
|
||||
|
||||
const route = getRouteApi("/_api/library/$id");
|
||||
|
||||
const LibraryMenu = () => {
|
||||
const { currentViewType, sortAscending, filters, sortBy } = route.useSearch();
|
||||
const { id: currentLibraryId } = route.useParams();
|
||||
const { api, user } = route.useRouteContext();
|
||||
const currentLibrary = useSuspenseQuery(
|
||||
getLibraryQueryOptions(api, user?.Id, currentLibraryId),
|
||||
);
|
||||
const scrollTrigger = useScrollTrigger({
|
||||
disableHysteresis: true,
|
||||
threshold: 20,
|
||||
});
|
||||
const navigate = useNavigate();
|
||||
const _handleSortAsecendingToggle = () => {
|
||||
navigate({
|
||||
search: {
|
||||
sortAscending: !sortAscending,
|
||||
sortBy,
|
||||
},
|
||||
to: "/library/$id",
|
||||
params: {
|
||||
id: currentLibraryId ?? "",
|
||||
},
|
||||
});
|
||||
};
|
||||
const _handleChangeSortBy = () => {
|
||||
navigate({
|
||||
search: {
|
||||
sortBy,
|
||||
},
|
||||
to: "/library/$id",
|
||||
params: {
|
||||
id: currentLibraryId ?? "",
|
||||
},
|
||||
});
|
||||
};
|
||||
const _handleChangeCurrentViewType = (viewType: BaseItemKind) => {
|
||||
navigate({
|
||||
search: {
|
||||
currentViewType: viewType,
|
||||
},
|
||||
to: "/library/$id",
|
||||
params: {
|
||||
id: currentLibraryId ?? "",
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const [filterButtonAnchorEl, setFilterButtonAnchorEl] =
|
||||
React.useState<null | HTMLElement>(null);
|
||||
const _filterMenuOpen = useMemo(
|
||||
() => Boolean(filterButtonAnchorEl),
|
||||
[filterButtonAnchorEl],
|
||||
);
|
||||
const _handleFilterDropdown = (event: React.MouseEvent<HTMLElement>) => {
|
||||
setFilterButtonAnchorEl(event.currentTarget);
|
||||
};
|
||||
|
||||
const _handleFilterChange = (key: FILTERS, value: boolean) => {
|
||||
// Update filter state and navigate
|
||||
navigate({
|
||||
search: {
|
||||
filters: { ...filters, [key]: value },
|
||||
},
|
||||
to: "/library/$id",
|
||||
params: {
|
||||
id: currentLibraryId ?? "",
|
||||
},
|
||||
});
|
||||
// Close the filter menu
|
||||
setFilterButtonAnchorEl(null);
|
||||
};
|
||||
|
||||
const _disableSortOption = useMemo(() => {
|
||||
return (
|
||||
!currentViewType ||
|
||||
!SORT_BY_OPTIONS.some(
|
||||
(option) =>
|
||||
option.compatibleViewTypes?.includes(currentViewType as any) ||
|
||||
option.compatibleCollectionTypes?.includes(
|
||||
currentLibrary.data.CollectionType as any,
|
||||
),
|
||||
)
|
||||
);
|
||||
}, [currentViewType, currentLibrary.data.CollectionType]);
|
||||
const _disableFilters = useMemo(() => {
|
||||
switch (currentViewType) {
|
||||
case BaseItemKind.Movie:
|
||||
case BaseItemKind.Audio:
|
||||
case BaseItemKind.Series:
|
||||
case BaseItemKind.BoxSet:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}, [currentViewType]);
|
||||
|
||||
if (!filters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
scrollTrigger
|
||||
? "library-items-header glass scrolling"
|
||||
: "library-items-header"
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default LibraryMenu;
|
||||
@@ -0,0 +1,144 @@
|
||||
import {
|
||||
Avatar,
|
||||
Divider,
|
||||
IconButton,
|
||||
ListItemIcon,
|
||||
Menu,
|
||||
MenuItem,
|
||||
} from "@mui/material";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useNavigate, useRouter } from "@tanstack/react-router";
|
||||
import React, {
|
||||
type MouseEventHandler,
|
||||
useCallback,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import { delUser } from "@/utils/storage/user";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import {
|
||||
setSettingsDialogOpen,
|
||||
setSettingsTabValue,
|
||||
} from "@/utils/store/settings";
|
||||
|
||||
export const UserAvatarMenu = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const createApi = useApiInContext((s) => s.createApi);
|
||||
const [user, resetCurrentUser] = useCentralStore((s) => [
|
||||
s.currentUser,
|
||||
s.resetCurrentUser,
|
||||
]);
|
||||
const navigate = useNavigate();
|
||||
const router = useRouter();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
|
||||
const openMenu = Boolean(anchorEl);
|
||||
|
||||
const handleMenuOpen: MouseEventHandler<HTMLButtonElement> = useCallback(
|
||||
(event) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const handleMenuClose = useCallback(() => {
|
||||
setAnchorEl(null);
|
||||
}, []);
|
||||
|
||||
const handleLogout = useCallback(async () => {
|
||||
console.log("Logging out user...");
|
||||
await api?.logout();
|
||||
createApi(api?.basePath ?? "", undefined);
|
||||
resetCurrentUser();
|
||||
delUser();
|
||||
sessionStorage.removeItem("accessToken");
|
||||
queryClient.clear();
|
||||
await router.invalidate();
|
||||
setAnchorEl(null);
|
||||
navigate({ to: "/login", replace: true });
|
||||
}, [api, createApi, navigate, queryClient, resetCurrentUser, router]);
|
||||
|
||||
const menuButtonSx = useMemo(() => ({ p: 0 }), []);
|
||||
const menuStyle = useMemo(() => ({ mt: 2 }), []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<IconButton sx={menuButtonSx} onClick={handleMenuOpen}>
|
||||
{!!user?.Id &&
|
||||
(user?.PrimaryImageTag === undefined ? (
|
||||
<Avatar className="appBar-avatar" alt={user?.Name ?? "image"}>
|
||||
<span className="material-symbols-rounded appBar-avatar-icon">
|
||||
account_circle
|
||||
</span>
|
||||
</Avatar>
|
||||
) : (
|
||||
<Avatar
|
||||
className="appBar-avatar"
|
||||
src={`${api?.basePath}/Users/${user?.Id}/Images/Primary`}
|
||||
alt={user?.Name ?? "image"}
|
||||
>
|
||||
<span className="material-symbols-rounded appBar-avatar-icon">
|
||||
account_circle
|
||||
</span>
|
||||
</Avatar>
|
||||
))}
|
||||
</IconButton>
|
||||
<Menu
|
||||
anchorEl={anchorEl}
|
||||
open={openMenu}
|
||||
onClose={handleMenuClose}
|
||||
sx={menuStyle}
|
||||
disableScrollLock
|
||||
>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
handleLogout();
|
||||
handleMenuClose();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">logout</div>
|
||||
</ListItemIcon>
|
||||
Logout
|
||||
</MenuItem>
|
||||
<Divider />
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
setSettingsDialogOpen(true);
|
||||
setSettingsTabValue(1);
|
||||
handleMenuClose();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">settings</div>
|
||||
</ListItemIcon>
|
||||
Settings
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
navigate({ to: "/settings/preferences" });
|
||||
handleMenuClose();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">tune</div>
|
||||
</ListItemIcon>
|
||||
Preferences
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
navigate({ to: "/settings/about" });
|
||||
handleMenuClose();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">info</div>
|
||||
</ListItemIcon>
|
||||
About
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user