diff --git a/CHANGELOG.md b/CHANGELOG.md index b6e39c2..c21ebbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +- # 0.0.6-dev + > **Note** : This is an unstable release + - + - # v0.0.5-dev > **Note** : This is an unstable release - feat(web): Add new About page (#258) by @prayag17 diff --git a/index.html b/index.html index c96f610..501af4c 100644 --- a/index.html +++ b/index.html @@ -13,13 +13,15 @@ left: 0; bottom: 0; right: 0; - background: #222; + background: #fff; z-index: 100000; display: flex; align-items: center; justify-content: center; flex-direction: column; transition: opacity 0.25s ease-in-out; + opacity: 0; + animation: fadeIn linear 500ms forwards; } .app-loading.hidden { @@ -27,49 +29,28 @@ } .app-loading-logo { - width: 40vw; - opacity: 0; - animation: fadeIn linear 500ms forwards; + width: 5vw; } - .circular { - animation: rotate 1.2s linear infinite; - height: 50px; - left: 50%; + .app-loading-bar-container{ + height: 2px; + width: 16vw; position: absolute; - bottom: 20%; - width: 50px; + left: 50%; + bottom: 36vh; + transform: translateX(-50%); + overflow: hidden; } - .path { - stroke-dasharray: 1,200; - stroke-dashoffset: 0; - animation: - dash 800ms ease-in-out infinite, - color 6s ease-in-out infinite - ; - stroke-linecap: round; - stroke: #fff; + + .app-loading-bar{ + width: 100%; + height: 100%; + background: #101010; + transform: scaleX(0); + animation: loading 1s ease-in-out infinite both; + transform-origin: left; } - @keyframes rotate { - 100% { - transform: rotate(360deg); - } - } - @keyframes dash { - 0% { - stroke-dasharray: 1,200; - stroke-dashoffset: 0; - } - 50% { - stroke-dasharray: 89,200; - stroke-dashoffset: -35; - } - 100% { - stroke-dasharray: 89,200; - stroke-dashoffset: -124; - } - } @keyframes fadeIn { 0%{ opacity: 0; @@ -78,15 +59,26 @@ opacity: 1; } } + @keyframes loading { + 0%{ + transform: translate(-100%); + } + 50%{ + transform: translate(0%); + } + 100%{ + transform: translate(100%); + } + }
- - - - + +
+
+
- -
- ); - } - - return ; -} -function AppReady() { - const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]); - const { enqueueSnackbar } = useSnackbar(); - - const [initialRoute] = useCentralStore((state) => [state.initialRoute]); - const [backdropUrl, backdropId] = useBackdropStore((state) => [ - state.backdropUrl, - state.backdropId, - ]); - const [playbackDataLoading] = usePlaybackDataLoadStore((state) => [ - state.isPending, - ]); - - const location = useLocation(); - const navigate = useNavigate(); - - - - const isQueryFetching = useIsFetching(); - const isMutating = useIsMutating(); - - useEffect(() => window.scrollTo(0, 0), [location.key]); - - const [videoPlaybackItem] = usePlaybackStore((state) => [state.item]); - - - - if (!initialRoute) { - return ( -
- -
- ); - } - - return ( - - - - - {/* Show Dialog if server not reachable */} - - -
- - - - } /> - - - Unable to reach server - - - - Unable to connect to the jellyfin server. - - - - - - - - } - /> - } /> - - } /> - } /> - } /> - } - /> - } /> - } /> - } /> - } /> - } - errorElement={
Error
} - /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } - key={videoPlaybackItem?.Id ?? "noplayback"} - /> -
-
-
- - - - - ); -} - -export default App; diff --git a/src/assets/icon-outline.svg b/src/assets/icon-outline.svg new file mode 100644 index 0000000..5492ea7 --- /dev/null +++ b/src/assets/icon-outline.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/assets/icon.png b/src/assets/icon.png index 5b9d040..c9475d3 100644 Binary files a/src/assets/icon.png and b/src/assets/icon.png differ diff --git a/src/assets/icon.svg b/src/assets/icon.svg index 152a8bc..dd1f4cd 100644 --- a/src/assets/icon.svg +++ b/src/assets/icon.svg @@ -1,11 +1,16 @@ - + + + + + + - + diff --git a/src/assets/logo.png b/src/assets/logo.png index e8493ac..efc7dd6 100644 Binary files a/src/assets/logo.png and b/src/assets/logo.png differ diff --git a/src/assets/logo.svg b/src/assets/logo.svg index 5bd5bb8..da959cd 100644 --- a/src/assets/logo.svg +++ b/src/assets/logo.svg @@ -1,12 +1,21 @@ - - + + - + + + + + + - + + + + + - + diff --git a/src/assets/logoBlack.png b/src/assets/logoBlack.png index 9893166..301f775 100644 Binary files a/src/assets/logoBlack.png and b/src/assets/logoBlack.png differ diff --git a/src/assets/logoBlack.svg b/src/assets/logoBlack.svg index d09b71b..679d241 100644 --- a/src/assets/logoBlack.svg +++ b/src/assets/logoBlack.svg @@ -1,12 +1,21 @@ - - + + - + + + + + + - + + + + + - + diff --git a/src/components/Slider/style.scss b/src/components/Slider/style.scss index d43ace8..20465a0 100644 --- a/src/components/Slider/style.scss +++ b/src/components/Slider/style.scss @@ -8,6 +8,9 @@ position: relative; overscroll-behavior-x: contain; margin: 0.5em 1em; + &::-webkit-scrollbar { + display: none; + } &-item { display: inline-block; diff --git a/src/components/appBar/appBar.tsx b/src/components/appBar/appBar.tsx index 28d285f..2bda322 100644 --- a/src/components/appBar/appBar.tsx +++ b/src/components/appBar/appBar.tsx @@ -1,39 +1,22 @@ -import type React from "react"; -import { useEffect, useRef, useState } from "react"; - -import { relaunch } from "@tauri-apps/api/process"; +import React, { type ReactNode } from "react"; +import { useEffect, useState } from "react"; import MuiAppBar from "@mui/material/AppBar"; import Avatar from "@mui/material/Avatar"; -import Button from "@mui/material/Button"; -import Grow from "@mui/material/Grow"; 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 Paper from "@mui/material/Paper"; -import Popper from "@mui/material/Popper"; -import Toolbar from "@mui/material/Toolbar"; -import Typography from "@mui/material/Typography"; import useScrollTrigger from "@mui/material/useScrollTrigger"; -import { red } from "@mui/material/colors"; - -import { - Link, - useLocation, - useNavigate, - useRouteContext, -} from "@tanstack/react-router"; +import { Link, useLocation, useNavigate } from "@tanstack/react-router"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api"; import { useQuery, useQueryClient } from "@tanstack/react-query"; -import { delServer } from "@/utils/storage/servers"; import { delUser } from "@/utils/storage/user"; -import { useDrawerStore } from "@/utils/store/drawer"; import "./appBar.scss"; import { EventEmitter as event } from "@/eventEmitter"; @@ -41,7 +24,7 @@ import { EventEmitter as event } from "@/eventEmitter"; import { getTypeIcon } from "../utils/iconsCollection"; import { useApiInContext } from "@/utils/store/api"; -import useSettingsStore, { +import { setSettingsDialogOpen, setSettingsTabValue, } from "@/utils/store/settings"; @@ -56,7 +39,7 @@ import { import BackButton from "../buttons/backButton"; interface ListItemLinkProps { - icon?: React.ReactElement; + icon?: ReactNode; primary: string; to: string; } @@ -141,7 +124,7 @@ export const AppBar = () => { event.emit("create-jellyfin-api", api.basePath); queryClient.clear(); setAnchorEl(null); - navigate("/login/index"); + navigate({ to: "/login" }); }; useEffect(() => { @@ -157,7 +140,6 @@ export const AppBar = () => { } else { setDisplay(true); } - }, [location]); const [showDrawer, setShowDrawer] = useState(false); @@ -186,7 +168,7 @@ export const AppBar = () => {
menu
- navigate({ to: "/home/" })}> + navigate({ to: "/home" })}>
{ {user.isSuccess && (user.data.PrimaryImageTag === undefined ? ( - + account_circle @@ -218,7 +203,7 @@ export const AppBar = () => { account_circle diff --git a/src/components/layouts/library/genreView/index.jsx b/src/components/layouts/library/genreView/index.jsx index b2a8775..6346dd4 100644 --- a/src/components/layouts/library/genreView/index.jsx +++ b/src/components/layouts/library/genreView/index.jsx @@ -1,3 +1,4 @@ +import { useApiInContext } from "@/utils/store/api"; import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; import Typography from "@mui/material/Typography"; @@ -8,7 +9,7 @@ import { Card } from "../../../card/card"; import { CardScroller } from "../../../cardScroller/cardScroller"; const GenreView = ({ libraryId, genreId, genreName, userId }) => { - const api = useRouteContext({ from: "/" }).api; + const api = useApiInContext((s) => s.api); const items = useQuery({ queryKey: ["library", "genreItem", genreId], diff --git a/src/components/nProgress/index.tsx b/src/components/nProgress/index.tsx index 65d0511..7d5e51e 100644 --- a/src/components/nProgress/index.tsx +++ b/src/components/nProgress/index.tsx @@ -9,29 +9,30 @@ const NProgress: React.FC<{ isAnimating: boolean | number }> = ({ isAnimating, }); - return ( -
- -
- ); + > + +
+ ); + } }; export default NProgress; diff --git a/src/components/notices/emptyNotice/emptyNotice.jsx b/src/components/notices/emptyNotice/emptyNotice.jsx index 82f3cf7..98d4544 100644 --- a/src/components/notices/emptyNotice/emptyNotice.jsx +++ b/src/components/notices/emptyNotice/emptyNotice.jsx @@ -14,7 +14,9 @@ export const EmptyNotice = ({ extraMsg }) => { justifyContent: "center", alignItems: "center", flexFlow: "column", - // opacity: 0.2, + position: "absolute", + top: 0, + left: 0, }} >
{ const updateInfo = useQuery({ queryKey: ["about", "updater"], - queryFn: async () => await checkUpdate(), + queryFn: async () => await check(), enabled: open, }); @@ -119,7 +119,7 @@ const Settings = () => { }, onSuccess: async () => { setSettingsDialogOpen(false); - navigate({ to: "/login/index" }); + navigate({ to: "/login" }); }, onError: (error) => { console.error(error); @@ -438,7 +438,7 @@ const Settings = () => { className="material-symbols-rounded" style={{ "--wght": 500 }} > - {updateInfo.data?.shouldUpdate + {updateInfo.data?.available ? "new_release" : "new_releases"} @@ -448,9 +448,7 @@ const Settings = () => { {applicationVersion} } - color={ - updateInfo.data?.shouldUpdate ? "error" : "success" - } + color={updateInfo.data?.available ? "error" : "success"} size="small" style={{ width: "fit-content !important", @@ -464,7 +462,7 @@ const Settings = () => { {updateInfo.isFetching ? ( "Checking for new updates..." - ) : updateInfo.data?.shouldUpdate ? ( + ) : updateInfo.data?.available ? ( @@ -493,12 +491,12 @@ const Settings = () => { }} loading={updateInfo.isFetching || updating} variant="contained" - disabled={!updateInfo.data?.shouldUpdate} + disabled={!updateInfo.data?.available} loadingPosition="start" onClick={async () => { - if (updateInfo.data?.shouldUpdate) { + if (updateInfo.data?.available) { setUpdating(true); - await installUpdate(); + await updateInfo.data?.downloadAndInstall(); enqueueSnackbar( "Update has been installed! You need to relaunch JellyPlayer.", { @@ -511,7 +509,7 @@ const Settings = () => { > {updateInfo.isFetching ? "Checking for Update..." - : updateInfo.data?.shouldUpdate + : updateInfo.data?.available ? "Update" : "No Update Found"} diff --git a/src/components/skeleton/libraryItems.tsx b/src/components/skeleton/libraryItems.tsx new file mode 100644 index 0000000..a529784 --- /dev/null +++ b/src/components/skeleton/libraryItems.tsx @@ -0,0 +1,37 @@ +import { Skeleton } from "@mui/material"; +import React from "react"; + +const LibraryItemsSkeleton = () => { + return ( +
+ {Array.from(new Array(18)).map((item, index) => ( + + ))} +
+ ); +}; + +export default LibraryItemsSkeleton; \ No newline at end of file diff --git a/src/index.css b/src/index.css deleted file mode 100644 index e69de29..0000000 diff --git a/src/main.tsx b/src/main.tsx index 1aab6ff..455b9e9 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,16 +1,30 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -import { RouterProvider, createRouter } from "@tanstack/react-router"; +import { + RouterProvider, + createRouteMask, + createRouter, +} from "@tanstack/react-router"; import React, { Suspense } from "react"; import ReactDOM from "react-dom/client"; // Import the generated route tree import { routeTree } from "./routeTree.gen"; +//TODO: Need help implementing modal routes in TanStack Router +// const SearchMask = createRouteMask({ +// routeTree, +// from: "/searchModal, +// to: "/search", +// params: true, +// }); + // Create a new router instance const router = createRouter({ routeTree, context: { api: undefined!, createApi: undefined!, + user: undefined, + jellyfinSDK: undefined!, }, defaultPreload: "intent", }); @@ -36,8 +50,14 @@ export const queryClient = new QueryClient({ }); function ProviderWrapper() { - const [api, createApi] = useApiInContext((s) => [s.api, s.createApi]); - return ; + const [api, createApi, jellyfinSDK] = useApiInContext((s) => [ + s.api, + s.createApi, + s.jellyfin, + ]); + return ( + + ); } ReactDOM.createRoot(document.getElementById("root")!).render( diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index 3adf802..f586875 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -13,6 +13,7 @@ import { Route as rootRoute } from './routes/__root' import { Route as ApiImport } from './routes/_api' import { Route as IndexImport } from './routes/index' +import { Route as ErrorCodeImport } from './routes/error/$code' import { Route as ApiSearchIndexImport } from './routes/_api/search/index' import { Route as ApiPlayerIndexImport } from './routes/_api/player/index' import { Route as ApiLoginIndexImport } from './routes/_api/login/index' @@ -46,6 +47,11 @@ const IndexRoute = IndexImport.update({ getParentRoute: () => rootRoute, } as any) +const ErrorCodeRoute = ErrorCodeImport.update({ + path: '/error/$code', + getParentRoute: () => rootRoute, +} as any) + const ApiSearchIndexRoute = ApiSearchIndexImport.update({ path: '/search/', getParentRoute: () => ApiRoute, @@ -164,6 +170,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ApiImport parentRoute: typeof rootRoute } + '/error/$code': { + id: '/error/$code' + path: '/error/$code' + fullPath: '/error/$code' + preLoaderRoute: typeof ErrorCodeImport + parentRoute: typeof rootRoute + } '/_api/album/$id': { id: '/_api/album/$id' path: '/album/$id' @@ -330,6 +343,7 @@ export const routeTree = rootRoute.addChildren({ ApiSearchIndexRoute, ApiLoginUserIdUserNameRoute, }), + ErrorCodeRoute, SetupServerAddRoute, SetupServerErrorRoute, SetupServerListRoute, @@ -345,6 +359,7 @@ export const routeTree = rootRoute.addChildren({ "children": [ "/", "/_api", + "/error/$code", "/setup/server/add", "/setup/server/error", "/setup/server/list" @@ -375,6 +390,9 @@ export const routeTree = rootRoute.addChildren({ "/_api/login/$userId/$userName" ] }, + "/error/$code": { + "filePath": "error/$code.tsx" + }, "/_api/album/$id": { "filePath": "_api/album/$id.tsx", "parent": "/_api" diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 8823c0c..2a7b941 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -27,12 +27,8 @@ import { useRouterState, } from "@tanstack/react-router"; import { TanStackRouterDevtools } from "@tanstack/router-devtools"; -import { relaunch } from "@tauri-apps/api/process"; -import { - type UpdateManifest, - checkUpdate, - installUpdate, -} from "@tauri-apps/api/updater"; +import { relaunch } from "@tauri-apps/plugin-process"; +import { type Update, check } from "@tauri-apps/plugin-updater"; import { AnimatePresence, motion } from "framer-motion"; import { SnackbarProvider, useSnackbar } from "notistack"; import React, { Suspense, useEffect, useLayoutEffect, useState } from "react"; @@ -47,7 +43,8 @@ import "@fontsource-variable/jetbrains-mono"; import "@fontsource-variable/noto-sans"; import "material-symbols/rounded.scss"; -import type { Api } from "@jellyfin/sdk"; +import type { Api, Jellyfin } from "@jellyfin/sdk"; +import type { UserDto } from "@jellyfin/sdk/lib/generated-client"; import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; type ApiContext = { @@ -56,6 +53,8 @@ type ApiContext = { serverAddress: string | undefined, accessToken: string | undefined, ) => void; + user: UserDto | null | undefined; + jellyfinSDK: Jellyfin; }; export const Route = createRootRouteWithContext()({ @@ -68,21 +67,17 @@ export const Route = createRootRouteWithContext()({ const routeIsLoading = useRouterState().isLoading; const [updateDialog, setUpdateDialog] = useState(false); const [updateDialogButton, setUpdateDialogButton] = useState(false); - const [updateInfo, setUpdateInfo] = useState( - undefined, - ); + const [updateInfo, setUpdateInfo] = useState(undefined); useLayoutEffect(() => { async function checkForUpdates() { try { - const { shouldUpdate, manifest } = await checkUpdate(); + const update = await check(); - if (shouldUpdate) { - setUpdateInfo(manifest); + if (update?.available) { + setUpdateInfo(update); setUpdateDialog(true); - console.log( - `Update found : ${manifest?.version}, ${manifest?.date}`, - ); + console.log(`Update found : ${update.version}, ${update.date}`); } } catch (error) { console.error(error); @@ -110,6 +105,11 @@ export const Route = createRootRouteWithContext()({ @@ -216,7 +216,7 @@ export const Route = createRootRouteWithContext()({ loadingIndicator="Updating..." onClick={async () => { setUpdateDialogButton(true); - await installUpdate(); + await updateInfo.downloadAndInstall(); enqueueSnackbar( "Update has been installed! You need to relaunch JellyPlayer.", { diff --git a/src/routes/_api.tsx b/src/routes/_api.tsx index 2a24952..a8f368b 100644 --- a/src/routes/_api.tsx +++ b/src/routes/_api.tsx @@ -1,26 +1,65 @@ import { getDefaultServer, getServer } from "@/utils/storage/servers"; import { getUser } from "@/utils/storage/user"; +import { axiosClient } from "@/utils/store/api"; +import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; -import { createFileRoute, redirect } from "@tanstack/react-router"; +import { Outlet, createFileRoute, redirect } from "@tanstack/react-router"; +import React from "react"; export const Route = createFileRoute("/_api")({ - beforeLoad: async ({ context }) => { - console.log(context.api); + beforeLoad: async ({ context, location }) => { + // console.log(context.api); if (!context.api) { const currentServerId = await getDefaultServer(); if (currentServerId) { const currentServer = await getServer(currentServerId); + const apiTemp = context.jellyfinSDK.createApi( + currentServer?.address, + null, + axiosClient, + ); + try { + await getSystemApi(apiTemp).getPingSystem(); + } catch (error) { + console.error(error); + throw redirect({ + to: "/error/$code", + params: { + code: "101", + }, + }); + } const userOnDisk = await getUser(); if (userOnDisk) { + if (location.pathname !== "/login/manual") { + const apiTemp = context.jellyfinSDK.createApi( + currentServer?.address, + userOnDisk.AccessToken, + axiosClient, + ); + try { + await getUserApi(apiTemp).getCurrentUser(); + } catch (error) { + console.error(error); + throw redirect({ + to: "/login/manual", + search: { + redirect: location.href, + }, + }); + } + } context.createApi(currentServer?.address, userOnDisk.AccessToken); } else { context.createApi(currentServer?.address, undefined); // Creates Api } } } else if (context.api) { - if (context.api.accessToken) { + if (context.api.accessToken && location.pathname !== "/login/manual") { try { - await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate + return { + user: await getUserApi(context.api).getCurrentUser(), + }; // Verify user is able to authenticate } catch (error) { console.error(error); throw redirect({ diff --git a/src/routes/_api/home/home.scss b/src/routes/_api/home/home.scss index 5f37fde..7e8f5f4 100644 --- a/src/routes/_api/home/home.scss +++ b/src/routes/_api/home/home.scss @@ -58,7 +58,7 @@ right: 0; bottom: 0; background-blend-mode: overlay; - height: 9%; + height: 90vh; .material-symbols-rounded { position: absolute; font-size: 15em !important; diff --git a/src/routes/_api/home/index.tsx b/src/routes/_api/home/index.tsx index 0309f9b..4e0f4da 100644 --- a/src/routes/_api/home/index.tsx +++ b/src/routes/_api/home/index.tsx @@ -19,7 +19,7 @@ import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-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 { Outlet, createFileRoute, useNavigate } from "@tanstack/react-router"; import { setBackdrop } from "@/utils/store/backdrop"; @@ -182,13 +182,28 @@ function Home() { if (latestMedia.isSuccess && latestMedia.data.length > 0) { if (latestMedia.data[now]?.ParentBackdropImageTags) { setBackdrop( - `${api.basePath}/Items/${latestMedia.data[now].ParentBackdropItemId}/Images/Backdrop`, - latestMedia.data[now].Id, + api.getItemImageUrl( + latestMedia.data[now].Id, + "Backdrop", + { + tag: latestMedia.data[now] + .ParentBackdropImageTags[0], + }, + ), + latestMedia.data[now]?.ParentBackdropImageTags[0] ?? + latestMedia.data[now].Id, ); } else { setBackdrop( - `${api.basePath}/Items/${latestMedia.data[now].Id}/Images/Backdrop`, - latestMedia.data[now].Id, + api.getItemImageUrl( + latestMedia.data[now].Id, + "Backdrop", + { + tag: latestMedia.data[now].BackdropImageTags[0], + }, + ), + latestMedia.data[now]?.BackdropImageTags[0] ?? + latestMedia.data[now].Id, ); } } diff --git a/src/routes/_api/item/$id.tsx b/src/routes/_api/item/$id.tsx index 992710f..1110d58 100644 --- a/src/routes/_api/item/$id.tsx +++ b/src/routes/_api/item/$id.tsx @@ -209,7 +209,7 @@ function ItemDetail() { api?.getItemImageUrl(item.data.Id, "Backdrop", { tag: item.data.BackdropImageTags[0], }), - item.data.Id, + item.data.BackdropImageTags[0], ); } else { setBackdrop("", ""); diff --git a/src/routes/_api/library/$id.tsx b/src/routes/_api/library/$id.tsx index 9a12300..dd0e9ad 100644 --- a/src/routes/_api/library/$id.tsx +++ b/src/routes/_api/library/$id.tsx @@ -1,5 +1,12 @@ -import { motion } from "framer-motion"; -import React, { useState, useEffect, useLayoutEffect } from "react"; +import React, { + useState, + useEffect, + useLayoutEffect, + type ChangeEvent, + useMemo, + useCallback, + type MouseEvent, +} from "react"; import { useQuery } from "@tanstack/react-query"; @@ -16,9 +23,7 @@ import FormControlLabel from "@mui/material/FormControlLabel"; import Grow from "@mui/material/Grow"; import IconButton from "@mui/material/IconButton"; import MenuItem from "@mui/material/MenuItem"; -import Pagination from "@mui/material/Pagination"; import Popper from "@mui/material/Popper"; -import Stack from "@mui/material/Stack"; import TextField from "@mui/material/TextField"; import Typography from "@mui/material/Typography"; @@ -36,21 +41,37 @@ import { EmptyNotice } from "@/components/notices/emptyNotice/emptyNotice"; import GenreView from "@/components/layouts/library/genreView"; import MusicTrack from "@/components/musicTrack"; import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice"; -import { setBackdrop, useBackdropStore } from "@/utils/store/backdrop"; +import { setBackdrop } from "@/utils/store/backdrop"; import { + type BaseItemDto, type BaseItemDtoQueryResult, BaseItemKind, - ItemFields, + CollectionType, + ItemFilter, + ItemSortBy, SortOrder, + VideoType, } from "@jellyfin/sdk/lib/generated-client"; import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; -import { useScrollTrigger } from "@mui/material"; +import { + FormControl, + Menu, + MenuList, + Stack, + useScrollTrigger, +} from "@mui/material"; import { useWindowVirtualizer } from "@tanstack/react-virtual"; import type { AxiosResponse } from "axios"; import "./library.scss"; +import LibraryItemsSkeleton from "@/components/skeleton/libraryItems"; import { createFileRoute } from "@tanstack/react-router"; +type SortByObject = { title: string; value: ItemSortBy }; +type ViewObject = { title: string; value: BaseItemKind }; +// type allowedFilters = ["movies", "tvshows", "music", "books"]; +type allowedFilters = Partial[]; + const useWindowWidth = () => { const [width, setWidth] = React.useState(window.innerWidth); @@ -88,28 +109,12 @@ function LibraryView() { networkMode: "always", }); - const [sortAscending, setSortAscending] = useState(true); - const [sortBy, setSortBy] = useState(""); - - /** - * @typedef {{title: string, value: string}} SortObject - */ - - /** - * @type {[SortObject[], Function]} - */ - const [sortByData, setSortByData] = useState([]); - - const handleSortBy = (e) => { - setSortBy(e.target.value); - }; - const currentLib = useQuery({ queryKey: ["libraryView", "currentLib", id], queryFn: async () => { const result = await getUserLibraryApi(api).getItem({ - userId: user.data.Id, - itemId: [id], + userId: user.data?.Id, + itemId: id, }); return result.data; }, @@ -118,127 +123,223 @@ function LibraryView() { staleTime: 0, }); - const [isPlayed, setIsPlayed] = useState(false); - const [isUnPlayed, setIsUnPlayed] = useState(false); - const [isResumable, setIsResumable] = useState(false); - const [isFavorite, setisFavorite] = useState(false); - const [isLiked, setIsLiked] = useState(false); - const [isUnliked, setIsUnliked] = useState(false); - - const [hasSubtitles, setHasSubtitles] = useState(false); - const [hasTrailer, setHasTrailer] = useState(false); - const [hasSpecialFeature, setHasSpecialFeature] = useState(false); - const [hasThemeSong, setHasThemeSong] = useState(false); - const [hasThemeVideo, setHasThemeVideo] = useState(false); - - const [isBluRay, setIsBluRay] = useState(false); - const [isDVD, setIsDVD] = useState(false); - const [isHD, setIsHD] = useState(false); - const [is4K, setIs4K] = useState(false); - const [is3D, setIs3D] = useState(false); - - const [currentViewType, setCurrentViewType] = useState(""); - - /** - * @type {[SortObject[], Function]} - */ - const [viewType, setViewType] = useState([]); - - useLayoutEffect(() => { - if (currentLib.isError) { - console.error(currentLib.error); - } - if (currentLib.isSuccess) { - setViewType(null); - if (currentLib.data.CollectionType === "movies") { - setCurrentViewType(BaseItemKind.Movie); - setViewType([ - { title: "Movies", value: BaseItemKind.Movie }, - { title: "Genres", value: BaseItemKind.Genre }, - { title: "Studios", value: BaseItemKind.Studio }, - ]); - } else if (currentLib.data.CollectionType === "music") { - setCurrentViewType(BaseItemKind.MusicAlbum); - setViewType([ - { title: "Albums", value: BaseItemKind.MusicAlbum }, - { title: "Songs", value: BaseItemKind.Audio }, - { title: "Artists", value: BaseItemKind.MusicArtist }, - { title: "Genres", value: BaseItemKind.MusicGenre }, - ]); - } else if (currentLib.data.CollectionType === "tvshows") { - setCurrentViewType(BaseItemKind.Series); - setViewType([ - { title: "Series", value: BaseItemKind.Series }, - { title: "Genres", value: BaseItemKind.Genre }, - { title: "Networks", value: BaseItemKind.Studio }, - ]); - } else if (currentLib.data.CollectionType === "playlists") { - setCurrentViewType(BaseItemKind.PlaylistsFolder); - setViewType([ + const [currentViewType, setCurrentViewType] = useState( + undefined!, + ); + const availableViewTypes: ViewObject[] = useMemo(() => { + let result: ViewObject[] = undefined!; + switch (currentLib.data?.CollectionType) { + case CollectionType.Movies: + result = [ { - title: "Playlists", - value: BaseItemKind.PlaylistsFolder, + title: "Movies", + value: BaseItemKind.Movie, }, - ]); - } else { - // currentViewType cant be "" or null or undefined since it is converted to Boolean to enable fetchItems query - setCurrentViewType("none"); - setViewType([]); - } - if (currentLib.data.CollectionType === "movies") { - setSortBy("SortName"); - setSortByData([ - { title: "Name", value: "SortName" }, - { title: "Critic Rating", value: "CriticRating" }, - { title: "Rating", value: "CommunityRating" }, - { title: "Date Added", value: "DateCreated" }, - { title: "Play Count", value: "PlayCount" }, - { title: "Release Date", value: "PremiereDate" }, - { title: "Runtime", value: "Runtime" }, - { title: "Random", value: "Random" }, - ]); - } else if (currentLib.data.CollectionType === "tvshows") { - setSortBy("SortName"); - setSortByData([ - { title: "Name", value: "SortName" }, - { title: "Critic Rating", value: "CriticRating" }, - { title: "Rating", value: "CommunityRating" }, - { title: "Date Added", value: "DateCreated" }, - { title: "Date Played", value: "DatePlayed" }, - { title: "Release Date", value: "PremiereDate" }, - { title: "Random", value: "Random" }, - ]); - } else if (currentLib.data.CollectionType === "music") { - setSortBy("Name"); - setSortByData([ - { title: "Name", value: "Name" }, - { title: "Album Artist", value: "AlbumArtist" }, - { title: "Critic Rating", value: "CriticRating" }, - { title: "Rating", value: "CommunityRating" }, - { title: "Release Date", value: "PremiereDate" }, - { title: "Date Added", value: "DateCreated" }, - { title: "Play Count", value: "PlayCount" }, - { title: "Runtime", value: "Runtime" }, - { title: "Random", value: "Random" }, - ]); - } else { - setSortBy("SortName"); - setSortByData([ - { title: "Name", value: "SortName" }, - { title: "Critic Rating", value: "CriticRating" }, - { title: "Rating", value: "CommunityRating" }, - { title: "Release Date", value: "PremiereDate" }, - { title: "Date Added", value: "DateCreated" }, - { title: "Play Count", value: "PlayCount" }, - { title: "Runtime", value: "Runtime" }, - { title: "Random", value: "Random" }, - ]); - } + { + title: "Trailers", + value: BaseItemKind.Trailer, + }, + { + title: "Collections", + value: BaseItemKind.CollectionFolder, + }, + { + title: "Genres", + value: BaseItemKind.Genre, + }, + ]; + break; + case CollectionType.Tvshows: + result = [ + { title: "Shows", value: BaseItemKind.Series }, + { title: "Genre", value: BaseItemKind.Genre }, + { title: "TV Networks", value: BaseItemKind.Studio }, + ]; + break; + case CollectionType.Boxsets: + result = [{ title: "Collection", value: BaseItemKind.BoxSet }]; + break; + default: + result = []; } - }, [currentLib.isSuccess]); - const [filterArray, setFilterArray] = useState([]); + setCurrentViewType(result?.[0]?.value); + return result; + }, [currentLib.data?.CollectionType]); - const [videoTypes, setVideoTypes] = useState([]); + const [videoTypesState, setVideoTypesState] = useState< + Record + >({ + VideoFile: undefined, + Iso: undefined, + BluRay: undefined, + Dvd: undefined, + }); + + const [sortBy, setSortBy] = useState("Name"); + const [sortAscending, setSortAscending] = useState(true); + const disableSort = useMemo(() => { + switch (currentViewType) { + case BaseItemKind.Genre: + return true; + default: + return false; + } + }, [currentViewType]); + const sortByOptions: SortByObject[] = useMemo(() => { + let result: SortByObject[] = undefined!; + switch (currentLib.data?.CollectionType) { + case CollectionType.Movies: + result = [ + { + title: "Name", + value: ItemSortBy.SortName, + }, + { + title: "Random", + value: ItemSortBy.Random, + }, + { + title: "IMDb Rating", + value: ItemSortBy.CommunityRating, + }, + { + title: "Critics Rating", + value: ItemSortBy.CriticRating, + }, + { + title: "Date Added", + value: ItemSortBy.DateCreated, + }, + { + title: "Date Played", + value: ItemSortBy.DatePlayed, + }, + { + title: "Parental Rating", + value: ItemSortBy.OfficialRating, + }, + { + title: "Play Count", + value: ItemSortBy.PlayCount, + }, + { + title: "Premiere Date", + value: ItemSortBy.PremiereDate, + }, + { + title: "Runtime", + value: ItemSortBy.Runtime, + }, + ]; + break; + case CollectionType.Tvshows: + result = [ + { + title: "Name", + value: ItemSortBy.SortName, + }, + { + title: "Random", + value: ItemSortBy.Random, + }, + { + title: "IMDb Rating", + value: ItemSortBy.CommunityRating, + }, + { + title: "Date Show Added", + value: ItemSortBy.DateCreated, + }, + { + title: "Date Episode Added", + value: ItemSortBy.DateLastContentAdded, + }, + { + title: "Date Played", + value: ItemSortBy.DatePlayed, + }, + { + title: "Parental Rating", + value: ItemSortBy.OfficialRating, + }, + { + title: "Premiere Date", + value: ItemSortBy.PremiereDate, + }, + ]; + break; + case CollectionType.Boxsets: + result = [ + { + title: "Name", + value: ItemSortBy.SortName, + }, + { + title: "Random", + value: ItemSortBy.Random, + }, + { + title: "IMDb Rating", + value: ItemSortBy.CommunityRating, + }, + { + title: "Critics Rating", + value: ItemSortBy.CriticRating, + }, + { + title: "Date Added", + value: ItemSortBy.DateCreated, + }, + { + title: "Date Played", + value: ItemSortBy.DatePlayed, + }, + { + title: "Parental Rating", + value: ItemSortBy.OfficialRating, + }, + { + title: "Play Count", + value: ItemSortBy.PlayCount, + }, + { + title: "Premiere Date", + value: ItemSortBy.PremiereDate, + }, + { + title: "Runtime", + value: ItemSortBy.Runtime, + }, + ]; + break; + default: + result = []; + break; + } + setSortBy(result?.[0]?.value); + return result; + }, [currentLib.data?.CollectionType]); + useLayoutEffect(() => {}, [sortByOptions]); + + const [filters, setFilters] = useState>({ + isPlayed: false, + isUnPlayed: false, + isResumable: false, + isFavorite: false, + isLiked: false, + isUnliked: false, + hasSubtitles: false, + hasTrailer: false, + hasSpecialFeature: false, + hasThemeSong: false, + hasThemeVideo: false, + isBluRay: false, + isDVD: false, + isHD: undefined, + isSD: false, + is4K: false, + is3D: false, + }); const items = useQuery({ queryKey: [ @@ -249,71 +350,105 @@ function LibraryView() { currentViewType: currentViewType, sortAscending: sortAscending, sortBy: sortBy, - playbackFilters: filterArray, - extraFilters: { - hasSubtitles: hasSubtitles, - hasTrailer: hasTrailer, - hasSpecialFeature: hasSpecialFeature, - hasThemeSong: hasThemeSong, - hasThemeVideo: hasThemeVideo, - }, - qualityFilters: { - isBluRay: isBluRay, - isDVD: isDVD, - isHD: isHD, - is4K: is4K, - is3D: is3D, - }, + filters, + videoTypesState, }, ], queryFn: async () => { let result: AxiosResponse; if (currentViewType === "MusicArtist") { result = await getArtistsApi(api).getAlbumArtists({ - userId: user.data.Id, + userId: user.data?.Id, parentId: id, }); } else if (currentViewType === "Person") { result = await getPersonsApi(api).getPersons({ - userId: user.data.Id, + userId: user.data?.Id, personTypes: ["Actor"], }); } else if (currentViewType === "Genre") { result = await getGenresApi(api).getGenres({ - userId: user.data.Id, + userId: user.data?.Id, parentId: id, }); } else if (currentViewType === "MusicGenre") { result = await getMusicGenresApi(api).getMusicGenres({ - userId: user.data.Id, + userId: user.data?.Id, parentId: id, }); } else if (currentViewType === "Studio") { result = await getStudiosApi(api).getStudios({ - userId: user.data.Id, + userId: user.data?.Id, parentId: id, }); - } else { + } 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.data.Id, - parentId: currentLib.data.Id, + userId: user.data?.Id, + parentId: currentLib.data?.Id, recursive: - currentLib.data.CollectionType === "boxsets" ? undefined : true, + currentLib.data?.CollectionType === "boxsets" ? undefined : true, + // includeItemTypes: [currentViewType], + sortOrder: [ + sortAscending ? SortOrder.Ascending : SortOrder.Descending, + ], + sortBy: [sortBy], + 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, + }); + } 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); + + result = await getItemsApi(api).getItems({ + userId: user.data?.Id, + parentId: currentLib.data?.Id, + recursive: + currentLib.data?.CollectionType === "boxsets" ? undefined : true, includeItemTypes: [currentViewType], sortOrder: [ sortAscending ? SortOrder.Ascending : SortOrder.Descending, ], - sortBy: sortBy, - filters: filterArray, - hasSubtitles: hasSubtitles ? true : undefined, - hasTrailer: hasTrailer ? true : undefined, - hasSpecialFeature: hasSpecialFeature ? true : undefined, - hasThemeSong: hasThemeSong ? true : undefined, - hasThemeVideo: hasThemeVideo ? true : undefined, + sortBy: [sortBy], + 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: isHD || undefined, - is4K: is4K || undefined, - is3D: is3D || undefined, + isHd: filters.isSD ? true : filters.isHD || undefined, + is4K: filters.is4K || undefined, + is3D: filters.is3D || undefined, enableUserData: true, }); } @@ -325,20 +460,29 @@ function 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 cardSize = useMemo( + () => + 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, + [items.dataUpdatedAt], + ); // This sets the approx height of each card in libraryView to estimate no of virtual rows to render const windowWidth = useWindowWidth(); - const itemsPerRow = Math.max(1, Math.floor(windowWidth / 200)); - - const count = Math.ceil( - Number.parseInt(items.data?.TotalRecordCount) / itemsPerRow, + const itemsPerRow = useMemo( + () => Math.max(1, Math.floor(windowWidth / 200)), + [windowWidth], + ); + const count = useMemo( + () => + (items.data?.TotalRecordCount ?? 1) > itemsPerRow + ? Math.ceil((items.data?.TotalRecordCount ?? 1) / itemsPerRow) + : 1, + [itemsPerRow, items.dataUpdatedAt], ); const virtualizer = useWindowVirtualizer({ count, @@ -353,49 +497,66 @@ function LibraryView() { "MusicGenre", "Studio", ]; - const allowedFilterViews = ["movies", "tvshows", "music", "books"]; + const allowedFilterViews: allowedFilters = [ + CollectionType.Movies, + CollectionType.Tvshows, + CollectionType.Music, + CollectionType.Books, + ]; const onlyStatusFilterViews = ["books", "music"]; - const [filterButtonAnchorEl, setFilterButtonAnchorEl] = useState(null); - const [filterMenuOpen, setFilterMenuOpen] = useState(false); + const [filterButtonAnchorEl, setFilterButtonAnchorEl] = + useState(null); + const filterMenuOpen = useMemo( + () => Boolean(filterButtonAnchorEl), + [filterButtonAnchorEl], + ); + const handleFilterDropdown = useCallback( + (e: MouseEvent) => { + setFilterButtonAnchorEl(e.currentTarget); + }, + [currentViewType, filterButtonAnchorEl], + ); const scrollTrigger = useScrollTrigger({ disableHysteresis: true, threshold: 20, }); - const [backdropItems, setBackdropItems] = useState([]); + 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, + (item) => item.BackdropImageTags?.length, ); - const backdropItem = backdropItemsTemp[0]; + const backdropItem = backdropItemsTemp?.[0]; // enqueueSnackbar("Running"); setBackdrop( - api?.getItemImageUrl(backdropItem?.Id, "Backdrop", { - tag: backdropItem?.BackdropImageTags[0], + api?.getItemImageUrl(backdropItem?.Id ?? "", "Backdrop", { + tag: backdropItem?.BackdropImageTags?.[0], }), - backdropItem?.BackdropImageTags[0] ?? "none", + backdropItem?.BackdropImageTags?.[0] ?? "none", ); setBackdropItems(backdropItemsTemp); } }, [items.isSuccess]); useEffect(() => { - if (backdropItems.length > 0) { + if (backdropItems?.length) { 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], + api?.getItemImageUrl(backdropItem.Id ?? "", "Backdrop", { + tag: backdropItem.BackdropImageTags?.[0], }), - backdropItem.BackdropImageTags[0] ?? "none", + backdropItem.BackdropImageTags?.[0] ?? "none", ); - }, 10000); // Update backdrop every 10s + }, 14000); // Update backdrop every 14s return () => clearInterval(intervalId); } }, [backdropItems]); @@ -461,617 +622,318 @@ function LibraryView() {
-
-
- {disabledSortViews.includes(currentViewType) ? ( - <> - ) : ( - <> - setSortAscending(!sortAscending)}> - + } + direction="row" + alignItems="center" + justifyContent="center" + gap={1.2} + className="library-items-options" + > + {!disableSort && ( +
+ setSortAscending((state) => !state)} > - sort - - - + + sort + + + ) => + setSortBy(e.target.value) + } + > + {sortByOptions.map((item) => ( + + {item.title} + + ))} + +
+ )} + {availableViewTypes.length > 0 && ( - {sortByData.map((option) => ( - - {option.title} - - ))} - - - )} - - {viewType.length > 0 && ( - <> - - { - setCurrentViewType(e.target.value); - }} size="small" + onChange={(e: ChangeEvent) => + setCurrentViewType(e.target.value) + } > - {viewType.map((option) => ( - - {option.title} + {availableViewTypes.map((item) => ( + + {item.title} ))} - - )} - - {currentLib.isSuccess && - allowedFilterViews.includes(currentLib.data.CollectionType) && ( - <> - - + setFilterButtonAnchorEl(null)} + slotProps={{ + paper: { + style: { + width: "28em", + maxHeight: "32em", + }, + }, + }} + > + Filters - - - )} - - {({ TransitionProps }) => ( - -
- - - expand_more - - } - > - Filters - - - { - setIsPlayed(e.target.checked); - if (e.target.checked) { - setFilterArray((state) => [ - ...state, - "isPlayed", - ]); - } else { - setFilterArray( - filterArray.filter( - (val) => val !== "isPlayed", - ), - ); - } - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setIsUnPlayed(e.target.checked); - if (e.target.checked) { - setFilterArray((state) => [ - ...state, - "IsUnplayed", - ]); - } else { - setFilterArray( - filterArray.filter( - (val) => val !== "IsUnplayed", - ), - ); - } - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setIsResumable(e.target.checked); - if (e.target.checked) { - setFilterArray((state) => [ - ...state, - "isResumable", - ]); - } else { - setFilterArray( - filterArray.filter( - (val) => val !== "isResumable", - ), - ); - } - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setisFavorite(e.target.checked); - if (e.target.checked) { - setFilterArray((state) => [ - ...state, - "isFavorite", - ]); - } else { - setFilterArray( - filterArray.filter( - (val) => val !== "isFavorite", - ), - ); - } - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setIsLiked(e.target.checked); - if (e.target.checked) { - setFilterArray((state) => [ - ...state, - "isLiked", - ]); - } else { - setFilterArray( - filterArray.filter( - (val) => val !== "isLiked", - ), - ); - } - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setIsUnliked(e.target.checked); - if (e.target.checked) { - setFilterArray((state) => [ - ...state, - "isUnliked", - ]); - } else { - setFilterArray( - filterArray.filter( - (val) => val !== "isUnliked", - ), - ); - } - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - - - {currentLib.data.CollectionType === "movies" && ( - - - expand_more - - } - > - Quality - - - { - setIsBluRay(e.target.checked); - if (e.target.checked) { - setVideoTypes((state) => [ - ...state, - "BluRay", - ]); - } else { - setVideoTypes( - filterArray.filter( - (val) => val !== "BluRay", - ), - ); - } - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setIsDVD(e.target.checked); - if (e.target.checked) { - setVideoTypes((state) => [ - ...state, - "Dvd", - ]); - } else { - setVideoTypes( - filterArray.filter( - (val) => val !== "Dvd", - ), - ); - } - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setIsHD(e.target.checked); - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setIs4K(e.target.checked); - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setIs3D(e.target.checked); - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - - - )} - {!onlyStatusFilterViews.includes( - currentLib.data.CollectionType, - ) && ( - - - expand_more - - } - > - - Features - - - - { - setHasSubtitles(e.target.checked); - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setHasTrailer(e.target.checked); - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setHasSpecialFeature(e.target.checked); - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setHasThemeSong(e.target.checked); - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - { - setHasThemeVideo(e.target.checked); - }} - /> - } - labelPlacement="start" - componentsProps={{ - typography: { - style: { - justifySelf: "start", - }, - }, - }} - /> - - - )} -
-
- )} -
+
+ + } + label="Played" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + isPlayed: e.target.checked, + })) + } + /> + } + label="Unplayed" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + isUnPlayed: e.target.checked, + })) + } + /> + } + label="Resumable" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + isResumable: e.target.checked, + })) + } + /> + } + label="Favorites" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + isFavorite: e.target.checked, + })) + } + /> + + + Features + + + } + label="Subtitles" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + hasSubtitles: e.target.checked, + })) + } + /> + } + label="Trailer" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + hasTrailer: e.target.checked, + })) + } + /> + + } + label="Special Features" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + hasSpecialFeature: e.target.checked, + })) + } + /> + } + label="Theme Song" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + hasThemeSong: e.target.checked, + })) + } + /> + } + label="Theme Video" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + hasThemeVideo: e.target.checked, + })) + } + /> + + + Video Types + + + } + label="BluRay" + onChange={(e: ChangeEvent) => + setVideoTypesState((s) => ({ + ...s, + BluRay: e.target.checked, + })) + } + /> + } + label="DVD" + onChange={(e: ChangeEvent) => + setVideoTypesState((s) => ({ + ...s, + Dvd: e.target.checked, + })) + } + /> + } + label="HD" + onChange={(e: ChangeEvent) => { + setFilters((s) => ({ + ...s, + isHD: e.target.checked, + })); + }} + /> + } + label="4k" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + is4K: e.target.checked, + })) + } + /> + } + label="SD" + disabled + /> + } + label="3D" + onChange={(e: ChangeEvent) => + setFilters((s) => ({ + ...s, + is3D: e.target.checked, + })) + } + /> + +
+ +
-
+ )} {items.isPending ? ( - - - - ) : items.data.TotalRecordCount === 0 ? ( - + + ) : items.data?.TotalRecordCount === 0 ? ( + ) : currentViewType === BaseItemKind.Genre ? ( - items.data.Items.map((item) => { + items.data?.Items?.map((item) => { return ( ); }) @@ -1141,31 +1003,7 @@ function LibraryView() { ? "square" : "portrait" } - queryKey={[ - "libraryView", - "currentLibItems", - id, - { - currentViewType: currentViewType, - sortAscending: sortAscending, - sortBy: sortBy, - playbackFilters: filterArray, - extraFilters: { - hasSubtitles: hasSubtitles, - hasTrailer: hasTrailer, - hasSpecialFeature: hasSpecialFeature, - hasThemeSong: hasThemeSong, - hasThemeVideo: hasThemeVideo, - }, - qualityFilters: { - isBluRay: isBluRay, - isDVD: isDVD, - isHD: isHD, - is4K: is4K, - is3D: is3D, - }, - }, - ]} + // queryKey={items} userId={user.data.Id} imageBlurhash={ !!item.ImageBlurHashes?.Primary && @@ -1194,103 +1032,6 @@ function LibraryView() {
); })} - {/* {items.data?.Items?.map((item) => { - return ( - - - - ); - })} */} ) : (
))} @@ -1345,3 +1085,4 @@ function LibraryView() { } export default LibraryView; + \ No newline at end of file diff --git a/src/routes/_api/login/manual.tsx b/src/routes/_api/login/manual.tsx index 8576d44..f3a0fd9 100644 --- a/src/routes/_api/login/manual.tsx +++ b/src/routes/_api/login/manual.tsx @@ -30,7 +30,7 @@ import InputLabel from "@mui/material/InputLabel"; import { useSnackbar } from "notistack"; import { AppBarBackOnly } from "@/components/appBar/backOnly.jsx"; -import { useApiInContext } from "@/utils/store/api.js"; +import { axiosClient, useApiInContext } from "@/utils/store/api.js"; import { getBrandingApi } from "@jellyfin/sdk/lib/utils/api/branding-api"; import { getQuickConnectApi } from "@jellyfin/sdk/lib/utils/api/quick-connect-api"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; @@ -69,6 +69,15 @@ function UserLoginManual() { }, }); + const ssoProviders = useQuery({ + queryKey: ["login", "manual", "ssoProviders"], + queryFn: async () => { + return axiosClient.get( + `${api.basePath}/sso/SAML/Get?api_key=${api.accessToken}`, + ); + }, + }); + const navigate = useNavigate(); const { enqueueSnackbar } = useSnackbar(); @@ -210,7 +219,7 @@ function UserLoginManual() { enqueueSnackbar(`Logged in as ${auth.data.User.Name}!`, { variant: "success", }); - navigate("/home"); + navigate({ to: "/home" }); }, 1000); setLoading(false); @@ -303,7 +312,7 @@ function UserLoginManual() { className="userEventButton" // size="large" style={{ flex: 1 }} - onClick={() => navigate("/servers/list")} + onClick={() => navigate({ to: "/setup/server/list" })} > Change Server diff --git a/src/routes/_api/player/index.tsx b/src/routes/_api/player/index.tsx index 3c984bb..d3bee0b 100644 --- a/src/routes/_api/player/index.tsx +++ b/src/routes/_api/player/index.tsx @@ -1,4 +1,4 @@ -import { appWindow } from "@tauri-apps/api/window"; +import { WebviewWindow as appWindow } from "@tauri-apps/api/webviewWindow"; import React, { useLayoutEffect } from "react"; import Backdrop from "@mui/material/Backdrop"; @@ -188,7 +188,7 @@ function VideoPlayer() { }; const handleExitPlayer = async () => { - appWindow.setFullscreen(false); + appWindow.getCurrent().setFullscreen(false); if (subtitleRenderer) { subtitleRenderer.destroy(); } @@ -240,7 +240,7 @@ function VideoPlayer() { case "F": case "f": setAppFullscreen((state) => { - appWindow.setFullscreen(!state); + appWindow.getCurrent().setFullscreen(!state); return !state; }); break; @@ -546,7 +546,7 @@ function VideoPlayer() { { setAppFullscreen((state) => { - appWindow.setFullscreen(!state); + appWindow.getCurrent().setFullscreen(!state); return !state; }); }} diff --git a/src/routes/_api/search/index.jsx b/src/routes/_api/search/index.jsx index cc8ab4e..1f41115 100644 --- a/src/routes/_api/search/index.jsx +++ b/src/routes/_api/search/index.jsx @@ -21,7 +21,8 @@ import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; import { getPersonsApi } from "@jellyfin/sdk/lib/utils/api/persons-api"; import { getSearchApi } from "@jellyfin/sdk/lib/utils/api/search-api"; import "./search.scss"; -import { createFileRoute } from "@tanstack/react-router"; +import { Dialog } from "@mui/material"; +import { Outlet, createFileRoute } from "@tanstack/react-router"; export const Route = createFileRoute("/_api/search/")({ component: SearchPage, @@ -48,8 +49,8 @@ function SearchPage() { const movies = useQuery({ queryKey: ["search", "items", "Movie", searchParam], queryFn: async () => { - const result = await getItemsApi(api).getItemsByUserId({ - userId: user.data.Id, + const result = await getItemsApi(api).getItems({ + userId: user.data?.Id, searchTerm, includeItemTypes: [BaseItemKind.Movie], recursive: true, @@ -58,13 +59,12 @@ function SearchPage() { return result.data; }, enabled: user.isSuccess, - cacheTime: 0, }); const series = useQuery({ queryKey: ["search", "items", "Series", searchParam], queryFn: async () => { - const result = await getItemsApi(api).getItemsByUserId({ - userId: user.data.Id, + const result = await getItemsApi(api).getItems({ + userId: user.data?.Id, searchTerm, includeItemTypes: [BaseItemKind.Series], recursive: true, @@ -73,13 +73,12 @@ function SearchPage() { return result.data; }, enabled: user.isSuccess, - cacheTime: 0, }); const musicAlbum = useQuery({ queryKey: ["search", "items", "MusicAlbum", searchParam], queryFn: async () => { - const result = await getItemsApi(api).getItemsByUserId({ - userId: user.data.Id, + const result = await getItemsApi(api).getItems({ + userId: user.data?.Id, searchTerm, includeItemTypes: [BaseItemKind.MusicAlbum], recursive: true, @@ -88,13 +87,12 @@ function SearchPage() { return result.data; }, enabled: user.isSuccess, - cacheTime: 0, }); const audio = useQuery({ queryKey: ["search", "items", "Audio", searchParam], queryFn: async () => { - const result = await getItemsApi(api).getItemsByUserId({ - userId: user.data.Id, + const result = await getItemsApi(api).getItems({ + userId: user.data?.Id, searchTerm, includeItemTypes: [BaseItemKind.Audio], recursive: true, @@ -103,13 +101,12 @@ function SearchPage() { return result.data; }, enabled: user.isSuccess, - cacheTime: 0, }); const book = useQuery({ queryKey: ["search", "items", "Book", searchParam], queryFn: async () => { - const result = await getItemsApi(api).getItemsByUserId({ - userId: user.data.Id, + const result = await getItemsApi(api).getItems({ + userId: user.data?.Id, searchTerm, includeItemTypes: [BaseItemKind.Book], recursive: true, @@ -118,13 +115,12 @@ function SearchPage() { return result.data; }, enabled: user.isSuccess, - cacheTime: 0, }); const musicArtists = useQuery({ queryKey: ["search", "items", "MusicArtists", searchParam], queryFn: async () => { - const result = await getItemsApi(api).getItemsByUserId({ - userId: user.data.Id, + const result = await getItemsApi(api).getItems({ + userId: user.data?.Id, searchTerm, includeItemTypes: [BaseItemKind.MusicArtist], recursive: true, @@ -133,26 +129,24 @@ function SearchPage() { return result.data; }, enabled: user.isSuccess, - cacheTime: 0, }); const person = useQuery({ queryKey: ["search", "items", "Person", searchParam], queryFn: async () => { const result = await getPersonsApi(api).getPersons({ - userId: user.data.Id, + userId: user.data?.Id, searchTerm, limit: itemLimit, }); return result.data; }, enabled: user.isSuccess, - cacheTime: 0, }); const episodes = useQuery({ queryKey: ["search", "items", "Episodes", searchParam], queryFn: async () => { - const result = await getSearchApi(api).get({ - userId: user.data.Id, + const result = await getSearchApi(api).getSearchHints({ + userId: user.data?.Id, searchTerm, limit: itemLimit, includeItemTypes: ["Episode"], @@ -160,7 +154,6 @@ function SearchPage() { return result.data; }, enabled: user.isSuccess, - cacheTime: 0, }); const [setBackdrop] = useBackdropStore((state) => [state.setBackdrop]); @@ -433,7 +426,7 @@ function SearchPage() { musicAlbum.data.Items.length === 0 && book.data.Items.length === 0 && musicArtists.data.Items.length === 0 && - person.data.Items.length === 0 && + person.data.Items?.length === 0 && episodes.data.SearchHints?.length === 0 && (
)} +
); } diff --git a/src/routes/error/$code.tsx b/src/routes/error/$code.tsx new file mode 100644 index 0000000..ca3e025 --- /dev/null +++ b/src/routes/error/$code.tsx @@ -0,0 +1,52 @@ +import { Button, ButtonGroup, Typography } from "@mui/material"; +import { Link, createFileRoute } from "@tanstack/react-router"; +import { relaunch } from "@tauri-apps/plugin-process"; +import React from "react"; + +export const Route = createFileRoute("/error/$code")({ + component: ErrorRoute, +}); + +function ErrorRoute() { + const errorCode = Route.useParams({ select: (s) => s.code }); + switch (errorCode) { + case "101": + return ( +
+ + report + + + Error connecting server. + + + Check your internet connection or contact your server administrator + +
+ + +
+
+ ); + + default: + return
Error
; + } +} \ No newline at end of file diff --git a/src/routes/setup/server.error.tsx b/src/routes/setup/server.error.tsx index d121bad..9b4b10b 100644 --- a/src/routes/setup/server.error.tsx +++ b/src/routes/setup/server.error.tsx @@ -3,7 +3,7 @@ import React from "react"; import "./server.error.scss"; import { Button, ButtonGroup, Typography } from "@mui/material"; -import { relaunch } from "@tauri-apps/api/process"; +import { relaunch } from "@tauri-apps/plugin-process"; export const Route = createFileRoute("/setup/server/error")({ component: () => { diff --git a/src/routes/setup/server.list.tsx b/src/routes/setup/server.list.tsx index 7704392..48a3d06 100644 --- a/src/routes/setup/server.list.tsx +++ b/src/routes/setup/server.list.tsx @@ -54,7 +54,7 @@ function ServerList() { queryClient.removeQueries(); }, onSuccess: async () => { - navigate({ to: "/login/index" }); + navigate({ to: "/login" }); }, onError: (error) => { console.error(error); diff --git a/src/utils/misc/relaunch.ts b/src/utils/misc/relaunch.ts index 944fd6c..006da77 100644 --- a/src/utils/misc/relaunch.ts +++ b/src/utils/misc/relaunch.ts @@ -1,4 +1,4 @@ -import { relaunch } from "@tauri-apps/api/process"; +import { relaunch } from "@tauri-apps/plugin-process"; export const handleRelaunch = async (_event: unknown, reason?: string) => { if (reason && reason === "backdropClick") { diff --git a/src/utils/storage/servers.ts b/src/utils/storage/servers.ts index fe1c942..0aaafcc 100644 --- a/src/utils/storage/servers.ts +++ b/src/utils/storage/servers.ts @@ -1,5 +1,5 @@ import type { RecommendedServerInfo } from "@jellyfin/sdk"; -import { Store } from "tauri-plugin-store-api"; +import { Store } from "@tauri-apps/plugin-store"; export interface ServerInfo extends RecommendedServerInfo { id: string; diff --git a/src/utils/storage/user.ts b/src/utils/storage/user.ts index 902b884..c369344 100644 --- a/src/utils/storage/user.ts +++ b/src/utils/storage/user.ts @@ -1,4 +1,4 @@ -import { Store } from "tauri-plugin-store-api"; +import { Store } from "@tauri-apps/plugin-store"; export interface UserStore { user: { diff --git a/src/utils/store/api.tsx b/src/utils/store/api.tsx index fe7f98a..47a3e84 100644 --- a/src/utils/store/api.tsx +++ b/src/utils/store/api.tsx @@ -16,7 +16,7 @@ type ApiStore = { }; export const axiosClient = axios.create({ - adapter: axiosTauriApiAdapter, + // adapter: axiosTauriApiAdapter, headers: { "Access-Control-Allow-Origin": "*", },