diff --git a/package.json b/package.json index 3d8e048..a687a76 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@tanem/react-nprogress": "^5.0.51", "@tanstack/react-query": "^5.28.4", "@tanstack/react-query-devtools": "^5.28.4", + "@tanstack/react-virtual": "^3.4.0", "@tauri-apps/api": "^1.5.3", "@types/node": "^20.11.28", "@types/react": "^18.2.66", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b67cf92..9e7928e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,6 +35,9 @@ dependencies: '@tanstack/react-query-devtools': specifier: ^5.28.4 version: 5.28.6(@tanstack/react-query@5.28.6)(react@18.2.0) + '@tanstack/react-virtual': + specifier: ^3.4.0 + version: 3.4.0(react-dom@18.2.0)(react@18.2.0) '@tauri-apps/api': specifier: ^1.5.3 version: 1.5.3 @@ -1391,6 +1394,21 @@ packages: react: 18.2.0 dev: false + /@tanstack/react-virtual@3.4.0(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-GZN4xn/Tg5w7gvYeVcMVCeL4pEyUhvg+Cp6KX2Z01C4FRNxIWMgIQ9ibgMarNQfo+gt0PVLcEER4A9sNv/jlow==} + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + dependencies: + '@tanstack/virtual-core': 3.4.0 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + + /@tanstack/virtual-core@3.4.0: + resolution: {integrity: sha512-75jXqXxqq5M5Veb9KP1STi8kA5u408uOOAefk2ftHDGCpUk3RP6zX++QqfbmHJTBiU72NQ+ghgCZVts/Wocz8Q==} + dev: false + /@tauri-apps/api@1.5.3: resolution: {integrity: sha512-zxnDjHHKjOsrIzZm6nO5Xapb/BxqUq1tc7cGkFXsFkGTsSWgCPH1D8mm0XS9weJY2OaR73I3k3S+b7eSzJDfqA==} engines: {node: '>= 14.6.0', npm: '>= 6.6.0', yarn: '>= 1.19.1'} diff --git a/src/App.tsx b/src/App.tsx index 30d8559..fd9801c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -407,7 +407,7 @@ function AppReady() {
{ @@ -430,9 +430,9 @@ function AppReady() { onLoad={() => { setBackdropLoading(false); }} - loading="eager" + loading="lazy" style={{ - transition: "opacity 0.8s", + transition: "opacity 1.2s", }} /> @@ -449,72 +449,72 @@ function AppReady() { {audioPlayerVisible && } - } /> - - - Unable to reach server - - - - Unable to connect to the jellyfin server. - - - - - - - - } - /> - } /> + } /> + + + Unable to reach server + + + + Unable to connect to the jellyfin server. + + + + + + + + } + /> + } /> - } /> - } /> - } /> - } - /> - } /> - } /> - } /> - } /> - } - errorElement={
Error
} - /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + } /> + } /> + } /> + } + /> + } /> + } /> + } /> + } /> + } + errorElement={
Error
} + /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } />
diff --git a/src/components/appBar/appBar.module.scss b/src/components/appBar/appBar.module.scss index 983e70c..52332db 100644 --- a/src/components/appBar/appBar.module.scss +++ b/src/components/appBar/appBar.module.scss @@ -4,6 +4,7 @@ backdrop-filter $transition-time-fast, box-shadow $transition-time-default !important; padding: 0.8em ($page-margin - 1.7em); + z-index: 999 !important; .flex { transition: $transition-time-fast; border-radius: 1000px; diff --git a/src/routes/library/index.jsx b/src/routes/library/index.tsx similarity index 83% rename from src/routes/library/index.jsx rename to src/routes/library/index.tsx index 7cfd248..d7e8cf9 100644 --- a/src/routes/library/index.jsx +++ b/src/routes/library/index.tsx @@ -2,7 +2,7 @@ import { motion } from "framer-motion"; import React, { useState, useEffect, useLayoutEffect } from "react"; import { useParams } from "react-router-dom"; -import { useQuery } from "@tanstack/react-query"; +import { useInfiniteQuery, useQuery } from "@tanstack/react-query"; import Accordion from "@mui/material/Accordion"; import AccordionDetails from "@mui/material/AccordionDetails"; @@ -35,6 +35,7 @@ import { Card } from "../../components/card/card"; import { EmptyNotice } from "../../components/notices/emptyNotice/emptyNotice"; import { + type BaseItemDtoQueryResult, BaseItemKind, ItemFields, SortOrder, @@ -42,15 +43,37 @@ import { import GenreView from "../../components/layouts/library/genreView"; import MusicTrack from "../../components/musicTrack"; import { ErrorNotice } from "../../components/notices/errorNotice/errorNotice"; -import { useBackdropStore } from "../../utils/store/backdrop"; +import { setBackdrop, useBackdropStore } from "../../utils/store/backdrop"; import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; +import { useScrollTrigger } from "@mui/material"; +import { useVirtualizer, useWindowVirtualizer } from "@tanstack/react-virtual"; +import type { AxiosResponse } from "axios"; +import { enqueueSnackbar } from "notistack"; import { useApi } from "../../utils/store/api"; import "./library.module.scss"; +const useWindowWidth = () => { + const [width, setWidth] = React.useState(window.innerWidth); + + React.useEffect(() => { + const onResize = () => setWidth(window.innerWidth); + + window.addEventListener("resize", onResize, { + capture: false, + passive: true, + }); + + return () => { + window.removeEventListener("resize", onResize); + }; + }, []); + + return width; +}; + const LibraryView = () => { const [api] = useApi((state) => [state.api]); - const [page, setPage] = useState(1); const maxDisplayItems = 100; const { id } = useParams(); @@ -221,7 +244,6 @@ const LibraryView = () => { "libraryView", "currentLibItems", id, - `page: ${page}`, { currentViewType: currentViewType, sortAscending: sortAscending, @@ -244,41 +266,31 @@ const LibraryView = () => { }, ], queryFn: async () => { - let result; + let result: AxiosResponse; if (currentViewType === "MusicArtist") { result = await getArtistsApi(api).getAlbumArtists({ userId: user.data.Id, parentId: id, - startIndex: maxDisplayItems * (page - 1), - limit: maxDisplayItems, }); } else if (currentViewType === "Person") { result = await getPersonsApi(api).getPersons({ userId: user.data.Id, personTypes: ["Actor"], - startIndex: maxDisplayItems * (page - 1), - limit: maxDisplayItems, }); } else if (currentViewType === "Genre") { result = await getGenresApi(api).getGenres({ userId: user.data.Id, parentId: id, - startIndex: maxDisplayItems * (page - 1), - limit: maxDisplayItems, }); } else if (currentViewType === "MusicGenre") { result = await getMusicGenresApi(api).getMusicGenres({ userId: user.data.Id, parentId: id, - startIndex: maxDisplayItems * (page - 1), - limit: maxDisplayItems, }); } else if (currentViewType === "Studio") { result = await getStudiosApi(api).getStudios({ userId: user.data.Id, parentId: id, - startIndex: maxDisplayItems * (page - 1), - limit: maxDisplayItems, }); } else { result = await getItemsApi(api).getItems({ @@ -301,8 +313,6 @@ const LibraryView = () => { isHd: isHD || undefined, is4K: is4K || undefined, is3D: is3D || undefined, - startIndex: maxDisplayItems * (page - 1), - limit: maxDisplayItems, enableUserData: true, }); } @@ -314,6 +324,27 @@ const LibraryView = () => { // gcTime: 0, }); + const cardSize = + items.data?.Items[0].Type === BaseItemKind.MusicAlbum || + items.data?.Items[0].Type === BaseItemKind.Audio || + items.data?.Items[0].Type === BaseItemKind.Genre || + items.data?.Items[0].Type === BaseItemKind.MusicGenre || + items.data?.Items[0].Type === BaseItemKind.Studio || + items.data?.Items[0].Type === BaseItemKind.Playlist + ? 260 + : 356; // This is going to be approx height of each card in libraryView + const windowWidth = useWindowWidth(); + const itemsPerRow = Math.max(1, Math.floor(windowWidth / 200)); + + const count = Math.ceil( + Number.parseInt(items.data?.TotalRecordCount) / itemsPerRow, + ); + const virtualizer = useWindowVirtualizer({ + count, + estimateSize: () => cardSize, + overscan: 7, + }); + const disabledSortViews = [ "MusicArtist", "Person", @@ -327,13 +358,38 @@ const LibraryView = () => { const [filterButtonAnchorEl, setFilterButtonAnchorEl] = useState(null); const [filterMenuOpen, setFilterMenuOpen] = useState(false); - const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]); + const scrollTrigger = useScrollTrigger({ + disableHysteresis: true, + threshold: 20, + }); + + const [backdropItems, setBackdropItems] = useState([]); + useEffect(() => { + // Filter all items having backdrop images for library backdrop + if (items.isSuccess) { + const backdropItemsTemp = items.data.Items?.filter( + (item) => item.BackdropImageTags?.length > 0, + ); + setBackdropItems(backdropItemsTemp); + } + }, [items.dataUpdatedAt]); useEffect(() => { - // Remove App backdrop in library page - setAppBackdrop("", ""); - // console.log(items.isSuccess); - }, []); + if (backdropItems.length > 0) { + const intervalId = setInterval(() => { + const itemIndex = Math.floor(Math.random() * backdropItems?.length); + const backdropItem = backdropItems[itemIndex]; + // enqueueSnackbar("Running"); + setBackdrop( + api?.getItemImageUrl(backdropItem.Id, "Backdrop", { + tag: backdropItem.BackdropImageTags[0], + }), + backdropItem.Id, + ); + }, 10000); // Update backdrop every 10s + return () => clearInterval(intervalId); + } + }, [backdropItems]); if (items.isError) { console.error(items.error); @@ -358,12 +414,15 @@ const LibraryView = () => {
{
-
+
{disabledSortViews.includes(currentViewType) ? ( <> @@ -963,7 +1028,7 @@ const LibraryView = () => {
- {!items.isSuccess ? ( + {items.isPending ? ( { ); }) ) : currentViewType !== BaseItemKind.Audio ? ( -
- {items.data.Items.map((item) => { +
+ {virtualizer.getVirtualItems().map((virtualRow) => { + const index = virtualRow.index; + const displayItems = []; + const fromIndex = index * itemsPerRow; + const toIndex = Math.min( + fromIndex + itemsPerRow, + items.data?.TotalRecordCount, + ); + for (let i = fromIndex; i < toIndex; i++) { + const item = items.data?.Items[i]; + displayItems.push( +
+ +
, + ); + } + return ( +
+ {displayItems} +
+ ); + })} + {/* {items.data?.Items?.map((item) => { return ( { item.Type === BaseItemKind.Episode ? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}` : item.Type === BaseItemKind.Series - ? `${item.ProductionYear} - ${ + ? `${item.ProductionYear} - ${ item.EndDate ? new Date(item.EndDate).toLocaleString([], { year: "numeric", - }) + }) : "Present" - }` - : item.ProductionYear + }` + : item.ProductionYear } disableOverlay={ item.Type === BaseItemKind.Person || @@ -1068,7 +1250,6 @@ const LibraryView = () => { "libraryView", "currentLibItems", id, - `page: ${page}`, { currentViewType: currentViewType, sortAscending: sortAscending, @@ -1100,7 +1281,7 @@ const LibraryView = () => { /> ); - })} + })} */}
) : (
{ "libraryView", "currentLibItems", id, - `page: ${page}`, { currentViewType: currentViewType, sortAscending: sortAscending, @@ -1144,33 +1324,6 @@ const LibraryView = () => { ))}
)} - - {items.isSuccess && items.data.TotalRecordCount > maxDisplayItems && ( - - - {maxDisplayItems * (page - 1)} -{" "} - {items.data.TotalRecordCount <= maxDisplayItems * page - ? items.data.TotalRecordCount - : maxDisplayItems * page}{" "} - of {items.data.TotalRecordCount} - - { - setPage(val); - }} - count={Math.ceil(items.data.TotalRecordCount / maxDisplayItems)} - sx={{ - width: "fit-content", - }} - /> - - )}
{items.isError && } diff --git a/src/routes/library/library.module.scss b/src/routes/library/library.module.scss index 490cdf7..2f5c13a 100644 --- a/src/routes/library/library.module.scss +++ b/src/routes/library/library.module.scss @@ -18,7 +18,7 @@ &-icon { font-size: 3em; fill: url(#clr-gradient-default) !important; - + &-container { position: absolute; top: 0; @@ -49,27 +49,34 @@ align-items: start; } &-items { - height: calc(100vh - 8.4em); + height: fit-content; overflow-y: auto; overflow-x: hidden; - padding: 1.5em 1em; + padding: 1.5em $page-margin; + padding-top: 4em; &-header { - position: absolute; + position: fixed; top: 4.4em; z-index: 10; display: flex; align-items: center; justify-content: center; - width: 100%; - height: 4em; + height: fit-content; + left: 50%; + transform: translate(-50%); + border-radius: 100px; + overflow: hidden; + transition: $transition-time-default; + z-index: 1000; + &.scrolling { + background: rgb(0 0 0 / 0.4) !important; + top: 1em; + } } &-options { padding: 0.5em 1.2em; gap: 0.5em; - background: $clr-background-opacity-0_5; - border-radius: 100px; overflow: hidden; - backdrop-filter: blur(10px); display: flex; align-items: center; justify-content: center; @@ -82,15 +89,14 @@ max-height: 32em; background: rgb(0 0 0 / 0.65); border-radius: $border-radius-default; - box-shadow: 0 0 10px rgb(0 0 0 / 0.4); backdrop-filter: blur(10px); overflow-y: overlay; } - + width: 100%; justify-content: space-between; margin: 0 0.5em !important; - + &-title { justify-self: start; } @@ -115,4 +121,29 @@ } } } -} + + // Fix card width with virtual rows + .card { + width: 100%; + height: fit-content; + margin: 0; + } + // Layout css for dynamic virtual rows + &-virtual-item{ + &-row{ + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + flex-basis: 14%; + } + width: 14%; + height: fit-content; + display: inline-flex; + flex-direction: row; + justify-content: center; + align-items: center; + padding: 0.75em; + } + +} \ No newline at end of file diff --git a/src/styles/global.scss b/src/styles/global.scss index 5e78b25..27f51ae 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -291,6 +291,6 @@ h1 { } .glass { - background: rgb(255 255 255 / 0.1) !important; + background: rgb(0 0 0 / 0.1) !important; backdrop-filter: blur(40px); } \ No newline at end of file