refactor: remove virtualization from library page #465

This commit is contained in:
Prayag Prajapati committed 2025-03-25 21:37:14 +05:30
1 parent b916560c6a
commit 7086892843
3 files changed
+93 -123

No files matched your search

+30 -32
View File
@@ -122,38 +122,36 @@ const CardComponent = ({
? getTypeIcon(overrideIcon) ? getTypeIcon(overrideIcon)
: getTypeIcon(item.Type ?? "universal")} : getTypeIcon(item.Type ?? "universal")}
</div> </div>
{inView && ( <img
<img alt={item.Name ?? "blink"}
alt={item.Name ?? "blink"} src={
src={ api
api ? overrideIcon === "User"
? overrideIcon === "User" ? `${api?.basePath}/Users/${item.Id}/Images/Primary`
? `${api?.basePath}/Users/${item.Id}/Images/Primary` : getImageUrlsApi(api).getItemImageUrlById(
: getImageUrlsApi(api).getItemImageUrlById( (seriesId ? item.SeriesId : (item.AlbumId ?? item.Id)) ??
(seriesId ? item.SeriesId : (item.AlbumId ?? item.Id)) ?? "",
"", imageType,
imageType, {
{ quality: 90,
quality: 90, fillWidth: cardType === "thumb" ? 560 : 320,
fillWidth: cardType === "thumb" ? 560 : 320, },
}, )
) : ""
: "" }
} style={{
style={{ height: "100%",
height: "100%", width: "100%",
width: "100%", opacity: 0,
opacity: 0, display: inView ? "block" : "none",
}} }}
loading="lazy" loading="lazy"
onLoad={(e) => { onLoad={(e) => {
e.currentTarget.style.setProperty("opacity", "1"); e.currentTarget.style.setProperty("opacity", "1");
}} }}
onLoadStart={(e) => console.log(e)} onLoadStart={(e) => console.log(e)}
className="card-image" className="card-image"
/> />
)}
{inView && !disableOverlay && ( {inView && !disableOverlay && (
<div className="card-overlay"> <div className="card-overlay">
<PlayButton <PlayButton
+57 -91
View File
@@ -218,6 +218,9 @@ function Library() {
case CollectionType.Playlists: case CollectionType.Playlists:
result = [{ title: "Playlist", value: BaseItemKind.Playlist }]; result = [{ title: "Playlist", value: BaseItemKind.Playlist }];
break; break;
case CollectionType.Books:
result = [{ title: "Books", value: BaseItemKind.Book }];
break;
default: default:
result = []; result = [];
} }
@@ -517,6 +520,14 @@ function Library() {
}, },
]; ];
break; break;
case CollectionType.Books:
result = [
{
title: "Name",
value: ItemSortBy.SortName,
},
];
break;
} }
// And they say typescript makes your code better :| // And they say typescript makes your code better :|
const cachedVal = JSON.parse( const cachedVal = JSON.parse(
@@ -661,8 +672,7 @@ function Library() {
result = await getItemsApi(api).getItems({ result = await getItemsApi(api).getItems({
userId: user?.Id, userId: user?.Id,
parentId: currentLib.data?.Id, parentId: currentLib.data?.Id,
recursive: recursive: true,
currentLib.data?.CollectionType === "boxsets" ? undefined : true,
includeItemTypes: [currentViewType], includeItemTypes: [currentViewType],
sortOrder: [ sortOrder: [
sortAscending ? SortOrder.Ascending : SortOrder.Descending, sortAscending ? SortOrder.Ascending : SortOrder.Descending,
@@ -1333,95 +1343,51 @@ function Library() {
} }
/> />
) : currentViewType !== BaseItemKind.Audio ? ( ) : currentViewType !== BaseItemKind.Audio ? (
<div <div className="library-items-container">
style={{ {items.data?.Items?.map((item) => (
height: virtualizer.getTotalSize(), <Card
width: "100%", item={item}
position: "relative", key={item?.Id}
}} seriesId={item?.SeriesId}
> cardTitle={
{virtualizer.getVirtualItems().map((virtualRow) => { item?.Type === BaseItemKind.Episode
const index = virtualRow.index; ? item.SeriesName
const displayItems = []; : item?.Name
const fromIndex = index * itemsPerRow; }
const toIndex = Math.min( imageType={"Primary"}
fromIndex + itemsPerRow, cardCaption={
items.data?.TotalRecordCount ?? 0, item?.Type === BaseItemKind.Episode
); ? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
for (let i = fromIndex; i < toIndex; i++) { : item?.Type === BaseItemKind.Series
const item = items.data?.Items?.[i]; ? `${item.ProductionYear} - ${
if (!item) return null; item.EndDate
displayItems.push( ? new Date(item.EndDate).toLocaleString([], {
<div year: "numeric",
className="library-virtual-item" })
key={i} : "Present"
data-index={virtualRow.index} }`
ref={virtualizer.measureElement} : item?.ProductionYear
> }
<Card disableOverlay={
item={item} item?.Type === BaseItemKind.Person ||
seriesId={item?.SeriesId} item?.Type === BaseItemKind.Genre ||
cardTitle={ item?.Type === BaseItemKind.MusicGenre ||
item?.Type === BaseItemKind.Episode item?.Type === BaseItemKind.Studio
? item.SeriesName }
: item?.Name cardType={
} item?.Type === BaseItemKind.MusicAlbum ||
imageType={"Primary"} item?.Type === BaseItemKind.Audio ||
cardCaption={ item?.Type === BaseItemKind.Genre ||
item?.Type === BaseItemKind.Episode item?.Type === BaseItemKind.MusicGenre ||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}` item?.Type === BaseItemKind.Studio ||
: item?.Type === BaseItemKind.Series item?.Type === BaseItemKind.Playlist
? `${item.ProductionYear} - ${ ? "square"
item.EndDate : "portrait"
? new Date(item.EndDate).toLocaleString( }
[], // queryKey={items}
{ userId={user?.Id}
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>,
);
}
return (
<div
className="library-virtual-item-row"
key={virtualRow.key}
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: virtualRow.size,
transform: `translateY(${virtualRow.start}px)`,
}}
>
{displayItems}
</div>
);
})}
</div> </div>
) : ( ) : (
<div <div
+6
View File
@@ -80,6 +80,12 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
&-container{
display: grid;
grid-template-columns: repeat(auto-fit, minmax(10em, 1fr)) ;
gap: 1.6em;
padding: 1em 4.4em;
}
} }
&-filter { &-filter {
width: 100%; width: 100%;