refactor: use suspense queries to fetch page data

This commit is contained in:
Prayag Prajapati committed 2025-05-21 23:12:17 +05:30
1 parent dfb8eeee12
commit 18d55a4af6
27 files changed
+2140 -1493

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- <script src="http://localhost:8097"></script> -->
<script src="http://localhost:8097"></script>
<title>Blink</title>
<style>
.app-loading {
+29 -27
View File
@@ -20,51 +20,51 @@
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@fontsource-variable/jetbrains-mono": "^5.2.5",
"@fontsource-variable/noto-sans": "^5.2.6",
"@fontsource-variable/noto-sans": "^5.2.7",
"@fontsource-variable/plus-jakarta-sans": "^5.2.5",
"@fontsource-variable/space-grotesk": "^5.2.6",
"@fontsource-variable/space-grotesk": "^5.2.7",
"@jellyfin/sdk": "0.11.0",
"@million/lint": "^1.0.14",
"@mui/lab": "7.0.0-beta.11",
"@mui/material": "7.0.2",
"@mui/lab": "7.0.0-beta.12",
"@mui/material": "7.1.0",
"@popperjs/core": "^2.11.8",
"@react-spring/web": "^9.7.5",
"@react-spring/web": "^10.0.1",
"@tanem/react-nprogress": "^5.0.55",
"@tanstack/react-form": "^1.7.0",
"@tanstack/react-query": "^5.74.4",
"@tanstack/react-query-devtools": "^5.74.6",
"@tanstack/react-router": "^1.117.1",
"@tanstack/react-router-devtools": "^1.117.1",
"@tanstack/react-virtual": "^3.13.6",
"@tanstack/react-form": "^1.11.2",
"@tanstack/react-query": "^5.76.1",
"@tanstack/react-query-devtools": "^5.76.1",
"@tanstack/react-router": "^1.120.5",
"@tanstack/react-router-devtools": "^1.120.6",
"@tanstack/react-virtual": "^3.13.9",
"@tauri-apps/api": "2.5.0",
"@tauri-apps/plugin-clipboard-manager": "2.2.2",
"@tauri-apps/plugin-dialog": "2.2.1",
"@tauri-apps/plugin-dialog": "2.2.2",
"@tauri-apps/plugin-notification": "2.2.2",
"@tauri-apps/plugin-process": "2.2.1",
"@tauri-apps/plugin-store": "github:tauri-apps/tauri-plugin-store#v2",
"@tauri-apps/plugin-updater": "2.7.1",
"@tauri-apps/plugin-upload": "2.2.1",
"@tauri-apps/plugin-window-state": "~2.2.2",
"@types/node": "^22.15.2",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2",
"@types/node": "^22.15.21",
"@types/react": "^19.1.5",
"@types/react-dom": "^19.1.5",
"axios": "^1.9.0",
"axios-tauri-api-adapter": "^2.0.6",
"blurhash": "^2.0.5",
"framer-motion": "^12.9.2",
"immer": "^10.1.1",
"jassub": "^1.7.18",
"libpgs": "^0.8.1",
"lodash": "^4.17.21",
"material-symbols": "^0.31.2",
"material-symbols": "^0.31.3",
"million": "^3.1.11",
"motion": "^12.12.1",
"notistack": "^3.0.2",
"react": "^19.1.0",
"react-blurhash": "^0.3.0",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^19.1.0",
"react-error-boundary": "^5.0.0",
"react-error-boundary": "^6.0.0",
"react-intersection-observer": "^9.16.0",
"react-markdown": "^10.1.0",
"react-multi-carousel": "^2.8.6",
@@ -72,21 +72,23 @@
"remark-gfm": "^4.0.1",
"typescript": "^5.8.3",
"vite-plugin-svgr": "^4.3.0",
"wavesurfer.js": "^7.9.4",
"zustand": "5.0.3"
"wavesurfer.js": "^7.9.5",
"zustand": "5.0.5"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining-assign": "^7.25.9",
"@babel/plugin-proposal-optional-chaining-assign": "^7.27.1",
"@biomejs/biome": "^1.9.4",
"@tanstack/router-cli": "^1.117.1",
"@tanstack/router-devtools": "^1.117.1",
"@tanstack/router-vite-plugin": "^1.117.2",
"@tanstack/router-cli": "^1.120.5",
"@tanstack/router-devtools": "^1.120.6",
"@tanstack/router-vite-plugin": "^1.120.5",
"@tauri-apps/cli": "2.5.0",
"@types/lodash": "^4.17.16",
"@types/lodash": "^4.17.17",
"@vitejs/plugin-react": "^4.4.1",
"babel-plugin-react-compiler": "19.1.0-rc.2",
"eslint-plugin-react-hooks": "6.0.0-rc1",
"prop-types": "^15.8.1",
"sass": "^1.87.0",
"vite": "^6.3.3"
"sass": "^1.89.0",
"vite": "^6.3.5"
},
"license": "GPL-3.0-only"
}
+1487 -831
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -1,5 +1,5 @@
import { useBackdropStore } from "@/utils/store/backdrop";
import { AnimatePresence, motion } from "framer-motion";
import { AnimatePresence, motion } from "motion/react";
import React, { useLayoutEffect, useState } from "react";
export default function Backdrop() {
+2 -2
View File
@@ -1,5 +1,5 @@
import { AnimatePresence, motion } from "framer-motion";
import type { PanInfo } from "framer-motion";
import { AnimatePresence, motion } from "motion/react";
import type { PanInfo } from "motion/react";
import React, { useEffect, useState, useMemo, useCallback } from "react";
import type { MouseEvent, PointerEvent } from "react";
+1 -1
View File
@@ -1,6 +1,6 @@
import React from "react";
import { motion } from "framer-motion";
import { motion } from "motion/react";
import Button from "@mui/material/Button";
import Chip from "@mui/material/Chip";
@@ -1,6 +1,6 @@
import React, { useEffect, useMemo, useRef, useState } from "react";
import { motion } from "framer-motion";
import { motion } from "motion/react";
import Fab from "@mui/material/Fab";
import IconButton from "@mui/material/IconButton";
@@ -10,7 +10,7 @@ import Typography from "@mui/material/Typography";
import { setAudioRef, useAudioPlayback } from "@/utils/store/audioPlayback";
import useQueue from "@/utils/store/queue";
import { AnimatePresence } from "framer-motion";
import { AnimatePresence } from "motion/react";
import "./audioPlayer.scss";
import { getRuntimeMusic, secToTicks, ticksToSec } from "@/utils/date/time";
+1 -1
View File
@@ -18,7 +18,7 @@ import {
TextField,
Typography,
} from "@mui/material";
import { AnimatePresence, motion } from "framer-motion";
import { AnimatePresence, motion } from "motion/react";
import React, { useState, useMemo, useCallback } from "react";
import logo from "@/assets/logo.png";
+1 -1
View File
@@ -1,7 +1,7 @@
import React from "react";
import { Skeleton } from "@mui/material";
import { motion } from "framer-motion";
import { motion } from "motion/react";
const ItemSkeleton = () => {
return (
+2 -2
View File
@@ -43,8 +43,8 @@ const router = createRouter({
defaultPreload: "intent",
defaultPreloadStaleTime: 0,
defaultViewTransition: true,
// scrollRestoration: true,
// scrollRestorationBehavior: "smooth",
scrollRestoration: true,
scrollRestorationBehavior: "smooth",
});
// Register the router instance for type safety
+1 -1
View File
@@ -57,7 +57,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
<AudioPlayer />
<Outlet />
<ReactQueryDevtools />
<TanStackRouterDevtools />
{/* <TanStackRouterDevtools /> */}
</SnackbarProvider>
</ThemeProvider>
</DndProvider>
+1 -1
View File
@@ -14,7 +14,7 @@ import Tabs from "@mui/material/Tabs";
import Typography from "@mui/material/Typography";
import useParallax from "@/utils/hooks/useParallax";
import { AnimatePresence, motion, useScroll } from "framer-motion";
import { AnimatePresence, motion, useScroll } from "motion/react";
import {
BaseItemKind,
+1 -1
View File
@@ -7,7 +7,7 @@ import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import useParallax from "@/utils/hooks/useParallax";
import { motion, useScroll } from "framer-motion";
import { motion, useScroll } from "motion/react";
import {
BaseItemKind,
+1 -1
View File
@@ -12,7 +12,7 @@ import { green, red, yellow } from "@mui/material/colors";
import { Blurhash } from "react-blurhash";
import useParallax from "@/utils/hooks/useParallax";
import { motion, useScroll } from "framer-motion";
import { motion, useScroll } from "motion/react";
import {
BaseItemKind,
+81 -120
View File
@@ -1,6 +1,6 @@
import React, { useCallback, useMemo } from "react";
import { useQuery } from "@tanstack/react-query";
import { useSuspenseQuery } from "@tanstack/react-query";
import "./home.scss";
@@ -10,22 +10,22 @@ import Carousel from "@/components/carousel";
import { Card } from "@/components/card/card";
import CardScroller from "@/components/cardScroller/cardScroller";
import { LatestMediaSection } from "@/components/layouts/homeSection/latestMediaSection";
import { CardsSkeleton } from "@/components/skeleton/cards";
import { CarouselSkeleton } from "@/components/skeleton/carousel";
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api";
import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { useBackdropStore } from "@/utils/store/backdrop";
import CircularPageLoadingAnimation from "@/components/circularPageLoadingAnimation";
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
import { getLatestItemsQueryOptions } from "@/utils/queries/items";
import { useApiInContext } from "@/utils/store/api";
import { useCentralStore } from "@/utils/store/central";
import type { Api } from "@jellyfin/sdk";
import {
type BaseItemDto,
BaseItemKind,
@@ -36,58 +36,37 @@ import { ErrorBoundary } from "react-error-boundary";
export const Route = createFileRoute("/_api/home/")({
component: Home,
pendingComponent: () => <CircularPageLoadingAnimation />,
loader: ({ context: { api, user, queryClient } }) => {
if (!api || !user?.Id) return null;
queryClient.ensureQueryData(getLatestItemsQueryOptions(api, user?.Id));
},
});
function Home() {
const api = useApiInContext((s) => s.api);
const user = useCentralStore((s) => s.currentUser);
const libraries = useQuery({
const libraries = useSuspenseQuery({
queryKey: ["libraries"],
queryFn: async () => {
if (!api) return;
if (!api || !user?.Id) return null;
const libs = await getUserViewsApi(api).getUserViews({
userId: user?.Id,
userId: user.Id,
});
return libs.data;
},
enabled: !!user?.Id && !!api?.accessToken,
networkMode: "always",
});
const latestMedia = useQuery({
queryKey: ["home", "latestMedia"],
queryFn: async () => {
if (!api) return;
const media = await getUserLibraryApi(api).getLatestMedia({
userId: user?.Id,
fields: [
ItemFields.Overview,
ItemFields.ParentId,
ItemFields.SeasonUserData,
ItemFields.IsHd,
ItemFields.MediaStreams,
ItemFields.MediaSources,
],
includeItemTypes: [
BaseItemKind.Movie,
BaseItemKind.Series,
BaseItemKind.MusicAlbum,
],
enableUserData: true,
enableImages: true,
});
return media.data;
},
enabled: !!user?.Id,
});
const latestMedia = useSuspenseQuery(getLatestItemsQueryOptions(api, user?.Id));
const resumeItemsVideo = useQuery({
const resumeItemsVideo = useSuspenseQuery({
queryKey: ["home", "resume", "video"],
queryFn: async () => {
if (!api) return;
if (!api || !user?.Id) return null;
const resumeItems = await getItemsApi(api).getResumeItems({
userId: user?.Id,
userId: user.Id,
limit: 10,
mediaTypes: ["Video"],
enableUserData: true,
@@ -95,14 +74,12 @@ function Home() {
});
return resumeItems.data;
},
enabled: !!user?.Id,
refetchOnMount: true,
});
const resumeItemsAudio = useQuery({
const resumeItemsAudio = useSuspenseQuery({
queryKey: ["home", "resume", "audio"],
queryFn: async () => {
if (!api) return;
if (!api || !user?.Id) return null;
const resumeItems = await getItemsApi(api).getResumeItems({
userId: user?.Id,
limit: 10,
@@ -112,13 +89,12 @@ function Home() {
});
return resumeItems.data;
},
enabled: !!user?.Id,
});
const upNextItems = useQuery({
const upNextItems = useSuspenseQuery({
queryKey: ["home", "upNext"],
queryFn: async () => {
if (!api) return;
if (!api || !user?.Id) return null;
const upNext = await getTvShowsApi(api).getNextUp({
userId: user?.Id,
fields: [
@@ -131,8 +107,6 @@ function Home() {
});
return upNext.data;
},
enabled: !!user?.Id,
refetchOnMount: true,
});
const excludeTypes = ["boxsets", "playlists", "livetv", "channels"];
@@ -154,37 +128,39 @@ function Home() {
const setBackdrop = useBackdropStore((s) => s.setBackdrop);
const setBackdropForItem = useCallback(
(item: BaseItemDto, api: Api) => {
if (item?.ParentBackdropImageTags) {
setBackdrop(
getImageUrlsApi(api).getItemImageUrlById(item.Id ?? "", "Backdrop", {
tag: item.ParentBackdropImageTags[0],
}),
item.ParentBackdropImageTags[0] ?? item.Id,
);
} else {
setBackdrop(
getImageUrlsApi(api).getItemImageUrlById(item.Id ?? "", "Backdrop", {
tag: item.BackdropImageTags?.[0],
}),
item.BackdropImageTags?.[0] ?? item.Id,
);
}
},
[setBackdrop],
);
const handleOnChangeCarousel = useCallback(
(now: number) => {
if (api && latestMedia.isSuccess && (latestMedia.data?.length ?? 0) > 0) {
if (latestMedia.data?.[now]?.ParentBackdropImageTags) {
setBackdrop(
getImageUrlsApi(api).getItemImageUrlById(
latestMedia.data[now].Id ?? "",
"Backdrop",
{
tag: latestMedia.data[now].ParentBackdropImageTags[0],
},
),
latestMedia.data[now]?.ParentBackdropImageTags[0] ??
latestMedia.data[now].Id,
);
} else {
setBackdrop(
getImageUrlsApi(api).getItemImageUrlById(
latestMedia.data?.[now].Id ?? "",
"Backdrop",
{
tag: latestMedia.data?.[now].BackdropImageTags?.[0],
},
),
latestMedia.data?.[now]?.BackdropImageTags?.[0] ??
latestMedia.data?.[now].Id,
);
}
const currentItem = latestMedia.data?.[now];
if (!currentItem) return;
// Extract this logic to a separate function
setBackdropForItem(currentItem, api);
}
},
[latestMedia.data?.map((item) => item.Id).join("")],
// Only depend on what you need
[latestMedia.isSuccess, api, setBackdrop],
);
return (
@@ -196,15 +172,11 @@ function Home() {
}}
>
<ErrorBoundary FallbackComponent={ErrorNotice}>
{latestMedia.isPending ? (
<CarouselSkeleton />
) : (
latestMedia.data?.length && (
<Carousel
content={latestMedia.data}
onChange={handleOnChangeCarousel}
/>
)
{latestMedia.data?.length && (
<Carousel
content={latestMedia.data}
onChange={handleOnChangeCarousel}
/>
)}
</ErrorBoundary>
@@ -215,34 +187,29 @@ function Home() {
</div>
}
>
{libraries.isPending ? (
<CardsSkeleton />
) : (
<CardScroller displayCards={4} title="Libraries">
{libraries.status === "success" &&
libraries.data?.Items?.map((item) => {
return (
<Card
key={item.Id}
item={item}
cardTitle={item.Name}
imageType="Primary"
cardType="thumb"
disableOverlay
onClick={() => {
if (item.Id) {
navigate({
to: "/library/$id",
params: { id: item.Id },
});
}
}}
overrideIcon={item.CollectionType}
/>
);
})}
</CardScroller>
)}
<CardScroller displayCards={4} title="Libraries">
{libraries.data?.Items?.map((item) => {
return (
<Card
key={item.Id}
item={item}
cardTitle={item.Name}
imageType="Primary"
cardType="thumb"
disableOverlay
onClick={() => {
if (item.Id) {
navigate({
to: "/library/$id",
params: { id: item.Id },
});
}
}}
overrideIcon={item.CollectionType}
/>
);
})}
</CardScroller>
</ErrorBoundary>
<ErrorBoundary
fallback={
@@ -251,9 +218,7 @@ function Home() {
</div>
}
>
{upNextItems.isPending ? (
<CardsSkeleton />
) : upNextItems.isSuccess && !upNextItems.data?.TotalRecordCount ? (
{upNextItems.isSuccess && !upNextItems.data?.TotalRecordCount ? (
<></>
) : (
<CardScroller displayCards={4} title="Up Next">
@@ -307,10 +272,8 @@ function Home() {
</div>
}
>
{resumeItemsVideo.isPending ? (
<CardsSkeleton />
) : resumeItemsVideo.isSuccess &&
!resumeItemsVideo.data?.TotalRecordCount ? (
{resumeItemsVideo.isSuccess &&
!resumeItemsVideo.data?.TotalRecordCount ? (
<></>
) : (
<CardScroller displayCards={4} title="Continue Watching">
@@ -360,10 +323,8 @@ function Home() {
</div>
}
>
{resumeItemsAudio.isPending ? (
<CardsSkeleton />
) : resumeItemsAudio.isSuccess &&
!resumeItemsAudio.data?.TotalRecordCount ? (
{resumeItemsAudio.isSuccess &&
!resumeItemsAudio.data?.TotalRecordCount ? (
<></>
) : (
<CardScroller displayCards={4} title="Continue Listening">
+19 -29
View File
@@ -10,16 +10,15 @@ import { green, red, yellow } from "@mui/material/colors";
import { Blurhash } from "react-blurhash";
import useParallax from "@/utils/hooks/useParallax";
import { motion, useScroll } from "framer-motion";
import { motion, useScroll } from "motion/react";
import {
BaseItemKind,
MediaStreamType,
} from "@jellyfin/sdk/lib/generated-client";
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { useQuery } from "@tanstack/react-query";
import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
import heroBg from "@/assets/herobg.png";
import { Card } from "@/components/card/card";
@@ -61,11 +60,20 @@ import type MediaQualityInfo from "@/utils/types/mediaQualityInfo";
import IconLink from "@/components/iconLink";
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
import { getItemQueryOptions } from "@/utils/queries/items";
import { useCentralStore } from "@/utils/store/central";
import { Link, createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/_api/item/$id")({
component: ItemDetail,
pendingComponent: () => <ItemSkeleton />,
// pendingMs: 5000,
loader: async ({ context: { queryClient, api, user }, params }) => {
if (!api || !user?.Id) return null;
await queryClient.ensureQueryData(
getItemQueryOptions(params.id, api, user?.Id),
);
},
});
function ItemDetail() {
@@ -75,25 +83,14 @@ function ItemDetail() {
const user = useCentralStore((s) => s.currentUser);
const item = useQuery({
queryKey: ["item", id],
queryFn: async () => {
if (!api) return null;
const result = await getUserLibraryApi(api).getItem({
userId: user?.Id,
itemId: id,
});
return result.data;
},
enabled: !!user?.Id,
networkMode: "always",
refetchOnWindowFocus: true,
});
const item = useSuspenseQuery(getItemQueryOptions(id, api, user?.Id));
const similarItems = useQuery({
queryKey: ["item", id, "similarItem"],
queryFn: async () => {
if (!api) return null;
if (!item.isSuccess) return null;
if (!api || !user?.Id) return null;
if (!item.data?.Id) return null;
if (item.data?.Type === "Movie") {
return (
@@ -135,7 +132,6 @@ function ItemDetail() {
})
).data;
},
enabled: item.isSuccess,
networkMode: "always",
refetchOnWindowFocus: true,
});
@@ -321,11 +317,6 @@ function ItemDetail() {
});
const parallax = useParallax(scrollYProgress, 50);
if (item.isPending || similarItems.isPending) {
return <ItemSkeleton />;
}
if (item.isSuccess && item.data) {
return (
<motion.div
key={id}
@@ -877,7 +868,10 @@ function ItemDetail() {
<Link
className="item-detail-cast-card"
key={actor.Id}
to={`/person/${actor.Id}`}
to="/person/$id"
params={{
id: actor.Id ?? "",
}}
>
{actor.PrimaryImageTag ? (
<img
@@ -1073,10 +1067,6 @@ function ItemDetail() {
)}
</motion.div>
);
}
if (item.isError || similarItems.isError) {
return <ErrorNotice />;
}
}
export default ItemDetail;
+397 -453
View File
@@ -17,7 +17,7 @@ import IconButton from "@mui/material/IconButton";
import MenuItem from "@mui/material/MenuItem";
import TextField from "@mui/material/TextField";
import Typography from "@mui/material/Typography";
import { useQuery } from "@tanstack/react-query";
import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
import { Card } from "@/components/card/card";
import { EmptyNotice } from "@/components/notices/emptyNotice/emptyNotice";
@@ -49,6 +49,7 @@ import type { AxiosResponse } from "axios";
import "./library.scss";
import LibraryItemsSkeleton from "@/components/skeleton/libraryItems";
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
import { getLibraryQueryOptions } from "@/utils/queries/library";
import { useApiInContext } from "@/utils/store/api";
import { useCentralStore } from "@/utils/store/central";
import { createFileRoute } from "@tanstack/react-router";
@@ -59,6 +60,12 @@ type ViewObject = { title: string; value: BaseItemKind | "Artist" };
export const Route = createFileRoute("/_api/library/$id")({
component: Library,
loader: async ({ context: { queryClient, api, user }, params }) => {
if (!api || !user?.Id) return null;
await queryClient.ensureQueryData(
getLibraryQueryOptions(api, user.Id, params.id),
);
},
});
function Library() {
@@ -68,20 +75,7 @@ function Library() {
const user = useCentralStore((s) => s.currentUser);
const currentLib = useQuery({
queryKey: ["library", "currentLib", id],
queryFn: async () => {
if (!api) return null;
const result = await getUserLibraryApi(api).getItem({
userId: user?.Id,
itemId: id,
});
return result.data;
},
enabled: !!user?.Id,
networkMode: "always",
staleTime: 0,
});
const currentLib = useSuspenseQuery(getLibraryQueryOptions(api, user?.Id, id));
const genres = useQuery({
queryKey: ["library", "genreItem", id],
@@ -771,24 +765,6 @@ function Library() {
}
}, [backdropItems]);
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>
);
}
if (currentLib.isSuccess) {
return (
<main className="scrollY library padded-top">
<div
@@ -832,121 +808,386 @@ function Library() {
</div>
</div>
<div className="library-items">
{currentLib.isSuccess && (
<div
className={
scrollTrigger
? "library-items-header glass scrolling"
: "library-items-header"
}
// padding={2}
<div
className={
scrollTrigger
? "library-items-header glass scrolling"
: "library-items-header"
}
>
<Stack
divider={<Divider flexItem orientation="vertical" />}
direction="row"
alignItems="center"
justifyContent="center"
gap={1.2}
className="library-items-options"
>
<Stack
divider={<Divider flexItem orientation="vertical" />}
direction="row"
alignItems="center"
justifyContent="center"
gap={1.2}
className="library-items-options"
>
{!disableSort && sortBy && (
<div className="flex flex-row flex-center">
<IconButton
onClick={() => {
sessionStorage.setItem(
`library-${currentLib.data?.Id}-config_sort`,
JSON.stringify({
sortAscending: !sortAscending,
sortBy,
}),
);
setSortAscending((state: boolean) => !state);
{!disableSort && sortBy && (
<div className="flex flex-row flex-center">
<IconButton
onClick={() => {
sessionStorage.setItem(
`library-${currentLib.data?.Id}-config_sort`,
JSON.stringify({
sortAscending: !sortAscending,
sortBy,
}),
);
setSortAscending((state: boolean) => !state);
}}
>
<span
className="material-symbols-rounded"
style={{
transform: sortAscending
? "rotateX(0deg)"
: "rotateX(180deg)",
}}
>
<span
className="material-symbols-rounded"
style={{
transform: sortAscending
? "rotateX(0deg)"
: "rotateX(180deg)",
}}
>
sort
</span>
</IconButton>
<TextField
select
value={sortBy ?? "Name"}
size="small"
onChange={(e) => {
setSortBy(e.target.value);
console.info(e);
sessionStorage.setItem(
`library-${currentLib.data?.Id}-config_sort`,
JSON.stringify({
sortAscending,
sortBy: e.target.value,
}),
);
}}
>
{sortByOptions.map((item) => (
<MenuItem key={item.title} value={item.value}>
{item.title}
</MenuItem>
))}
</TextField>
</div>
)}
{availableViewTypes.length > 0 && (
sort
</span>
</IconButton>
<TextField
select
value={currentViewType}
value={sortBy ?? "Name"}
size="small"
onChange={(e) => {
setCurrentViewType(e.target.value as BaseItemKind);
setSortBy(e.target.value);
console.info(e);
sessionStorage.setItem(
`library-${currentLib.data?.Id}-config_currentViewType`,
e.target.value,
`library-${currentLib.data?.Id}-config_sort`,
JSON.stringify({
sortAscending,
sortBy: e.target.value,
}),
);
}}
>
{availableViewTypes.map((item) => (
<MenuItem key={item.value} value={item.value}>
{sortByOptions.map((item) => (
<MenuItem key={item.title} value={item.value}>
{item.title}
</MenuItem>
))}
</TextField>
)}
{!disableFilters && (
<div>
<Button
startIcon={
<span className="material-symbols-rounded">
filter_list
</span>
}
size="large"
//@ts-ignore
color="white"
onClick={handleFilterDropdown}
>
Filter
</Button>
<Menu
open={filterMenuOpen}
anchorEl={filterButtonAnchorEl}
onClose={() => setFilterButtonAnchorEl(null)}
slotProps={{
paper: {
style: {
width: "28em",
maxHeight: "32em",
},
</div>
)}
{availableViewTypes.length > 0 && (
<TextField
select
value={currentViewType}
size="small"
onChange={(e) => {
setCurrentViewType(e.target.value as BaseItemKind);
sessionStorage.setItem(
`library-${currentLib.data?.Id}-config_currentViewType`,
e.target.value,
);
}}
>
{availableViewTypes.map((item) => (
<MenuItem key={item.value} value={item.value}>
{item.title}
</MenuItem>
))}
</TextField>
)}
{!disableFilters && (
<div>
<Button
startIcon={
<span className="material-symbols-rounded">
filter_list
</span>
}
size="large"
//@ts-ignore
color="white"
onClick={handleFilterDropdown}
>
Filter
</Button>
<Menu
open={filterMenuOpen}
anchorEl={filterButtonAnchorEl}
onClose={() => setFilterButtonAnchorEl(null)}
slotProps={{
paper: {
style: {
width: "28em",
maxHeight: "32em",
},
}}
>
{currentViewType !== "Audio" && (
},
}}
>
{currentViewType !== "Audio" && (
<div>
<Typography
variant="h6"
fontWeight={600}
mx="0.4em"
mb={0.5}
>
Filters
</Typography>
<FormControl
style={{
background: "rgb(0 0 0 / 0.4)",
width: "100%",
padding: "0.4em 1em",
borderRadius: "6px",
}}
>
<FormControlLabel
control={
<Checkbox
checked={filters.isPlayed}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
isPlayed: e.target.checked,
}))
}
/>
}
label="Played"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.isUnPlayed}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
isUnPlayed: e.target.checked,
}))
}
/>
}
label="Unplayed"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.isResumable}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
isResumable: e.target.checked,
}))
}
/>
}
label="Resumable"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.isFavorite}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
isFavorite: e.target.checked,
}))
}
/>
}
label="Favorites"
/>
</FormControl>
</div>
)}
{currentViewType !== "Audio" && (
<div>
<Typography
variant="h6"
fontWeight={600}
mx="0.4em"
mb={0.5}
>
Features
</Typography>
<FormControl
style={{
background: "rgb(0 0 0 / 0.4)",
width: "100%",
padding: "0.4em 1em",
borderRadius: "6px",
}}
>
<FormControlLabel
control={
<Checkbox
checked={filters.hasSubtitles}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
hasSubtitles: e.target.checked,
}))
}
/>
}
label="Subtitles"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.hasTrailer}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
hasTrailer: e.target.checked,
}))
}
/>
}
label="Trailer"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.hasSpecialFeature}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
hasSpecialFeature: e.target.checked,
}))
}
/>
}
label="Special Features"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.hasThemeSong}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
hasThemeSong: e.target.checked,
}))
}
/>
}
label="Theme Song"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.hasThemeVideo}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
hasThemeVideo: e.target.checked,
}))
}
/>
}
label="Theme Video"
/>
</FormControl>
</div>
)}
{currentViewType !== "Audio" && (
<div>
<Typography
variant="h6"
fontWeight={600}
mx="0.4em"
mb={0.5}
>
Video Types
</Typography>
<FormControl
style={{
background: "rgb(0 0 0 / 0.4)",
width: "100%",
padding: "0.4em 1em",
borderRadius: "6px",
}}
>
<FormControlLabel
control={
<Checkbox
checked={videoTypesState.BluRay}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setVideoTypesState((s) => ({
...s,
BluRay: e.target.checked,
}))
}
/>
}
label="BluRay"
/>
<FormControlLabel
control={
<Checkbox
checked={videoTypesState.Dvd}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setVideoTypesState((s) => ({
...s,
Dvd: e.target.checked,
}))
}
/>
}
label="DVD"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.isHD}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) => {
setFilters((s) => ({
...s,
isHD: e.target.checked,
}));
}}
/>
}
label="HD"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.is4K}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFilters((s) => ({
...s,
is4K: e.target.checked,
}))
}
/>
}
label="4k"
/>
<FormControlLabel
control={<Checkbox checked={false} />}
label="SD"
disabled
/>
<FormControlLabel
control={
<Checkbox
value={filters.is3D}
onChange={(e) =>
setFilters((s) => ({
...s,
is3D: e.target.checked,
}))
}
/>
}
label="3D"
/>
</FormControl>
</div>
)}
{genres.isSuccess &&
(genres.data?.TotalRecordCount ?? 0) > 0 && (
<div>
<Typography
variant="h6"
@@ -954,7 +1195,7 @@ function Library() {
mx="0.4em"
mb={0.5}
>
Filters
Genres
</Typography>
<FormControl
style={{
@@ -964,325 +1205,32 @@ function Library() {
borderRadius: "6px",
}}
>
<FormControlLabel
control={
<Checkbox
checked={filters.isPlayed}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
isPlayed: e.target.checked,
}))
}
/>
}
label="Played"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.isUnPlayed}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
isUnPlayed: e.target.checked,
}))
}
/>
}
label="Unplayed"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.isResumable}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
isResumable: e.target.checked,
}))
}
/>
}
label="Resumable"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.isFavorite}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
isFavorite: e.target.checked,
}))
}
/>
}
label="Favorites"
/>
{genres.data?.Items?.map(
(genre) =>
genre.Id && (
<FormControlLabel
key={genre.Id}
control={
<Checkbox
checked={genreFilter.includes(genre.Id)}
onChange={(e) =>
handleGenreFilter(e, genre)
}
/>
}
label={genre.Name}
/>
),
)}
</FormControl>
</div>
)}
{currentViewType !== "Audio" && (
<div>
<Typography
variant="h6"
fontWeight={600}
mx="0.4em"
mb={0.5}
>
Features
</Typography>
<FormControl
style={{
background: "rgb(0 0 0 / 0.4)",
width: "100%",
padding: "0.4em 1em",
borderRadius: "6px",
}}
>
<FormControlLabel
control={
<Checkbox
checked={filters.hasSubtitles}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
hasSubtitles: e.target.checked,
}))
}
/>
}
label="Subtitles"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.hasTrailer}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
hasTrailer: e.target.checked,
}))
}
/>
}
label="Trailer"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.hasSpecialFeature}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
hasSpecialFeature: e.target.checked,
}))
}
/>
}
label="Special Features"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.hasThemeSong}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
hasThemeSong: e.target.checked,
}))
}
/>
}
label="Theme Song"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.hasThemeVideo}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
hasThemeVideo: e.target.checked,
}))
}
/>
}
label="Theme Video"
/>
</FormControl>
</div>
)}
{currentViewType !== "Audio" && (
<div>
<Typography
variant="h6"
fontWeight={600}
mx="0.4em"
mb={0.5}
>
Video Types
</Typography>
<FormControl
style={{
background: "rgb(0 0 0 / 0.4)",
width: "100%",
padding: "0.4em 1em",
borderRadius: "6px",
}}
>
<FormControlLabel
control={
<Checkbox
checked={videoTypesState.BluRay}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setVideoTypesState((s) => ({
...s,
BluRay: e.target.checked,
}))
}
/>
}
label="BluRay"
/>
<FormControlLabel
control={
<Checkbox
checked={videoTypesState.Dvd}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setVideoTypesState((s) => ({
...s,
Dvd: e.target.checked,
}))
}
/>
}
label="DVD"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.isHD}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) => {
setFilters((s) => ({
...s,
isHD: e.target.checked,
}));
}}
/>
}
label="HD"
/>
<FormControlLabel
control={
<Checkbox
checked={filters.is4K}
onChange={(
e: ChangeEvent<HTMLInputElement>,
) =>
setFilters((s) => ({
...s,
is4K: e.target.checked,
}))
}
/>
}
label="4k"
/>
<FormControlLabel
control={<Checkbox checked={false} />}
label="SD"
disabled
/>
<FormControlLabel
control={
<Checkbox
value={filters.is3D}
onChange={(e) =>
setFilters((s) => ({
...s,
is3D: e.target.checked,
}))
}
/>
}
label="3D"
/>
</FormControl>
</div>
)}
{genres.isSuccess &&
(genres.data?.TotalRecordCount ?? 0) > 0 && (
<div>
<Typography
variant="h6"
fontWeight={600}
mx="0.4em"
mb={0.5}
>
Genres
</Typography>
<FormControl
style={{
background: "rgb(0 0 0 / 0.4)",
width: "100%",
padding: "0.4em 1em",
borderRadius: "6px",
}}
>
{genres.data?.Items?.map(
(genre) =>
genre.Id && (
<FormControlLabel
key={genre.Id}
control={
<Checkbox
checked={genreFilter.includes(
genre.Id,
)}
onChange={(e) =>
handleGenreFilter(e, genre)
}
/>
}
label={genre.Name}
/>
),
)}
</FormControl>
</div>
)}
</Menu>
</div>
)}
</Stack>
</div>
)}
</Menu>
</div>
)}
</Stack>
</div>
{items.isPending ? (
<LibraryItemsSkeleton />
) : items.data?.TotalRecordCount === 0 ? (
@@ -1378,8 +1326,4 @@ function Library() {
{items.isError && <ErrorNotice />}
</main>
);
}
if (currentLib.isError) {
return <ErrorNotice error={currentLib.error} />;
}
}
+8
View File
@@ -45,6 +45,9 @@
grid-template-columns: repeat(var(--number-of-cols), minmax(0, 1fr));
justify-items: center;
align-items: start;
> * {
max-width: 11em;
}
}
&-items {
height: fit-content;
@@ -85,6 +88,11 @@
grid-template-columns: repeat(auto-fit, minmax(10em, 1fr)) ;
gap: 1.6em;
padding: 1em 4.4em;
align-content: center;
justify-items: center;
> .card {
max-width: 11em;
}
}
}
&-filter {
+1 -1
View File
@@ -12,7 +12,7 @@ import Tab from "@mui/material/Tab";
import Tabs from "@mui/material/Tabs";
import Typography from "@mui/material/Typography";
import { AnimatePresence, motion } from "framer-motion";
import { AnimatePresence, motion } from "motion/react";
import { BaseItemKind, LocationType } from "@jellyfin/sdk/lib/generated-client";
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
+1 -1
View File
@@ -34,7 +34,7 @@ import "./videoPlayer.scss";
import { endsAt } from "@/utils/date/time";
import { PlayMethod, RepeatMode } from "@jellyfin/sdk/lib/generated-client";
import { AnimatePresence, motion } from "framer-motion";
import { AnimatePresence, motion } from "motion/react";
import { useBackdropStore } from "@/utils/store/backdrop";
+1 -1
View File
@@ -3,7 +3,7 @@ import { usePhotosPlayback } from "@/utils/store/photosPlayback";
import { createFileRoute } from "@tanstack/react-router";
import React, { type MouseEvent, useCallback, useMemo, useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { AnimatePresence, motion } from "motion/react";
//@ts-ignore
import brokenImage from "/assetsStatic/broken-image.png?url";
+1 -1
View File
@@ -11,7 +11,7 @@ import Typography from "@mui/material/Typography";
import { green, red, yellow } from "@mui/material/colors";
import useParallax from "@/utils/hooks/useParallax";
import { AnimatePresence, motion, useScroll } from "framer-motion";
import { AnimatePresence, motion, useScroll } from "motion/react";
import { Blurhash } from "react-blurhash";
-11
View File
@@ -86,17 +86,6 @@ body {
opacity: 0.35;
}
/**
* Page transitions
*/
:root{
view-transition-name: fadeingPage;
}
::view-transition-group(fadeingPage) {
animation-duration: .3s;
}
.fadeIn {
animation: 0.5s fadeInPage forwards;
}
+1 -1
View File
@@ -1,4 +1,4 @@
import { type MotionValue, useTransform } from "framer-motion";
import { type MotionValue, useTransform } from "motion/react";
export default function useParallax(
value: MotionValue<number>,
+68
View File
@@ -0,0 +1,68 @@
import type { Api } from "@jellyfin/sdk";
import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client";
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { queryOptions } from "@tanstack/react-query";
/**
* @param id itemId
* @param api api instance
* @param userId user's id
* @returns query options for the item
* @description This function returns the query options for the item. It uses the getUserLibraryApi to get the item data.
*/
export const getItemQueryOptions = (
id: string,
api: Api | null | undefined,
userId: string | null | undefined,
) =>
queryOptions({
queryKey: ["item", id],
queryFn: async () => {
if (!api || !userId) {
throw Error("API or User ID is not defined");
}
const result = await getUserLibraryApi(api).getItem({
userId: userId,
itemId: id,
});
return result.data;
},
});
/**
* @param api api instance
* @param userId user's id
* @returns query options for the latest items
* @description This function returns the query options for the latest items. It uses the getUserLibraryApi to get the latest items data.
*/
export const getLatestItemsQueryOptions = (
api: Api | null | undefined,
userId: string | null | undefined,
) =>
queryOptions({
queryKey: ["home", "latestMedia"],
queryFn: async () => {
if (!api || !userId) {
throw Error("API or User ID is not defined");
}
const media = await getUserLibraryApi(api).getLatestMedia({
userId: userId,
fields: [
ItemFields.Overview,
ItemFields.ParentId,
ItemFields.SeasonUserData,
ItemFields.IsHd,
ItemFields.MediaStreams,
ItemFields.MediaSources,
],
includeItemTypes: [
BaseItemKind.Movie,
BaseItemKind.Series,
BaseItemKind.MusicAlbum,
],
enableUserData: true,
enableImages: true,
});
return media.data;
},
});
+26
View File
@@ -0,0 +1,26 @@
import type { Api } from "@jellyfin/sdk";
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { queryOptions } from "@tanstack/react-query";
/**
* @param api Api instance
* @param userId user's id
* @param id library id
* @returns query options for the current library
*/
export const getLibraryQueryOptions = (
api: Api | null | undefined,
userId: string | null | undefined,
id: string,
) =>
queryOptions({
queryKey: ["library", "currentLib", id],
queryFn: async () => {
if (!api || !userId) throw Error("API or User ID is not defined");
const result = await getUserLibraryApi(api).getItem({
userId: userId,
itemId: id,
});
return result.data;
},
});
+5 -2
View File
@@ -14,8 +14,11 @@ const plugins = [react({
["@babel/plugin-proposal-optional-chaining-assign",
{
version: "2023-07"
}]
]
}],
["babel-plugin-react-compiler", {
compilationMode: "annotation",
}],
],
}
}), svgr(), TanStackRouterVite()];
export default defineConfig({