diff --git a/src/components/settings/index.tsx b/src/components/settings/index.tsx index 67e3aaa..a25c12c 100644 --- a/src/components/settings/index.tsx +++ b/src/components/settings/index.tsx @@ -68,6 +68,7 @@ const Settings = () => { const systemInfo = useQuery({ queryKey: ["about", "systemInfo"], queryFn: async () => { + if (!api) return null; const result = await getSystemApi(api).getSystemInfo(); return result.data; }, @@ -106,7 +107,7 @@ const Settings = () => { const handleServerChange = useMutation({ mutationFn: async (server: RecommendedServerInfo) => { await delUser(); - await setDefaultServer(server.id); + await setDefaultServer(server.systemInfo?.Id ?? ""); await defaultServer.refetch(); createApi(server.address, undefined); queryClient.removeQueries(); @@ -126,15 +127,15 @@ const Settings = () => { const handleDelete = useMutation({ mutationKey: ["server-delete"], mutationFn: async (server: RecommendedServerInfo) => { - await delServer(server.id); + await delServer(server.systemInfo?.Id ?? ""); - if (server.id === defaultServer.data) { + if (server.systemInfo?.Id === defaultServer.data) { await delUser(); await serversOnDisk.refetch(); - if (serversOnDisk.data.length > 0) { + if (serversOnDisk.data?.length) { setDefaultServer(serversOnDisk.data[0].id); - createApi(serversOnDisk.data[0].address, null); + createApi(serversOnDisk.data[0].address, undefined); } else { // TODO: Reset api in context // useApi.setState(useApi.getInitialState()); @@ -158,7 +159,7 @@ const Settings = () => { }, onSuccess: async (bestServer) => { if (bestServer) { - await setServer(bestServer.systemInfo.Id, bestServer); + await setServer(bestServer.systemInfo?.Id ?? "", bestServer); setAddServerDialog(false); enqueueSnackbar( "Client added successfully. You might need to refresh client list.", @@ -620,6 +621,7 @@ const Settings = () => { > Close + {/* @ts-ignore */} rootRoute, } as any) -const ApiSearchRoute = ApiSearchImport.update({ - id: '/search', - path: '/search', - getParentRoute: () => ApiRoute, -} as any) - const ApiLoginRoute = ApiLoginImport.update({ id: '/login', path: '/login', @@ -70,9 +63,9 @@ const ApiLoginRoute = ApiLoginImport.update({ } as any) const ApiSearchIndexRoute = ApiSearchIndexImport.update({ - id: '/', - path: '/', - getParentRoute: () => ApiSearchRoute, + id: '/search/', + path: '/search/', + getParentRoute: () => ApiRoute, } as any) const ApiPlayerIndexRoute = ApiPlayerIndexImport.update({ @@ -220,13 +213,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ApiLoginImport parentRoute: typeof ApiImport } - '/_api/search': { - id: '/_api/search' - path: '/search' - fullPath: '/search' - preLoaderRoute: typeof ApiSearchImport - parentRoute: typeof ApiImport - } '/error/$code': { id: '/error/$code' path: '/error/$code' @@ -369,10 +355,10 @@ declare module '@tanstack/react-router' { } '/_api/search/': { id: '/_api/search/' - path: '/' - fullPath: '/search/' + path: '/search' + fullPath: '/search' preLoaderRoute: typeof ApiSearchIndexImport - parentRoute: typeof ApiSearchImport + parentRoute: typeof ApiImport } '/_api/login/$userId/$userName': { id: '/_api/login/$userId/$userName' @@ -402,21 +388,8 @@ const ApiLoginRouteWithChildren = ApiLoginRoute._addFileChildren( ApiLoginRouteChildren, ) -interface ApiSearchRouteChildren { - ApiSearchIndexRoute: typeof ApiSearchIndexRoute -} - -const ApiSearchRouteChildren: ApiSearchRouteChildren = { - ApiSearchIndexRoute: ApiSearchIndexRoute, -} - -const ApiSearchRouteWithChildren = ApiSearchRoute._addFileChildren( - ApiSearchRouteChildren, -) - interface ApiRouteChildren { ApiLoginRoute: typeof ApiLoginRouteWithChildren - ApiSearchRoute: typeof ApiSearchRouteWithChildren ApiAlbumIdRoute: typeof ApiAlbumIdRoute ApiArtistIdRoute: typeof ApiArtistIdRoute ApiBoxsetIdRoute: typeof ApiBoxsetIdRoute @@ -431,11 +404,11 @@ interface ApiRouteChildren { ApiFavoriteIndexRoute: typeof ApiFavoriteIndexRoute ApiHomeIndexRoute: typeof ApiHomeIndexRoute ApiPlayerIndexRoute: typeof ApiPlayerIndexRoute + ApiSearchIndexRoute: typeof ApiSearchIndexRoute } const ApiRouteChildren: ApiRouteChildren = { ApiLoginRoute: ApiLoginRouteWithChildren, - ApiSearchRoute: ApiSearchRouteWithChildren, ApiAlbumIdRoute: ApiAlbumIdRoute, ApiArtistIdRoute: ApiArtistIdRoute, ApiBoxsetIdRoute: ApiBoxsetIdRoute, @@ -450,6 +423,7 @@ const ApiRouteChildren: ApiRouteChildren = { ApiFavoriteIndexRoute: ApiFavoriteIndexRoute, ApiHomeIndexRoute: ApiHomeIndexRoute, ApiPlayerIndexRoute: ApiPlayerIndexRoute, + ApiSearchIndexRoute: ApiSearchIndexRoute, } const ApiRouteWithChildren = ApiRoute._addFileChildren(ApiRouteChildren) @@ -458,7 +432,6 @@ export interface FileRoutesByFullPath { '/': typeof IndexRoute '': typeof ApiRouteWithChildren '/login': typeof ApiLoginRouteWithChildren - '/search': typeof ApiSearchRouteWithChildren '/error/$code': typeof ErrorCodeRoute '/album/$id': typeof ApiAlbumIdRoute '/artist/$id': typeof ApiArtistIdRoute @@ -479,7 +452,7 @@ export interface FileRoutesByFullPath { '/favorite': typeof ApiFavoriteIndexRoute '/home': typeof ApiHomeIndexRoute '/player': typeof ApiPlayerIndexRoute - '/search/': typeof ApiSearchIndexRoute + '/search': typeof ApiSearchIndexRoute '/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute } @@ -516,7 +489,6 @@ export interface FileRoutesById { '/': typeof IndexRoute '/_api': typeof ApiRouteWithChildren '/_api/login': typeof ApiLoginRouteWithChildren - '/_api/search': typeof ApiSearchRouteWithChildren '/error/$code': typeof ErrorCodeRoute '/_api/album/$id': typeof ApiAlbumIdRoute '/_api/artist/$id': typeof ApiArtistIdRoute @@ -547,7 +519,6 @@ export interface FileRouteTypes { | '/' | '' | '/login' - | '/search' | '/error/$code' | '/album/$id' | '/artist/$id' @@ -568,7 +539,7 @@ export interface FileRouteTypes { | '/favorite' | '/home' | '/player' - | '/search/' + | '/search' | '/login/$userId/$userName' fileRoutesByTo: FileRoutesByTo to: @@ -602,7 +573,6 @@ export interface FileRouteTypes { | '/' | '/_api' | '/_api/login' - | '/_api/search' | '/error/$code' | '/_api/album/$id' | '/_api/artist/$id' @@ -671,7 +641,6 @@ export const routeTree = rootRoute "filePath": "_api.tsx", "children": [ "/_api/login", - "/_api/search", "/_api/album/$id", "/_api/artist/$id", "/_api/boxset/$id", @@ -685,7 +654,8 @@ export const routeTree = rootRoute "/_api/series/$id", "/_api/favorite/", "/_api/home/", - "/_api/player/" + "/_api/player/", + "/_api/search/" ] }, "/_api/login": { @@ -697,13 +667,6 @@ export const routeTree = rootRoute "/_api/login/$userId/$userName" ] }, - "/_api/search": { - "filePath": "_api/search.tsx", - "parent": "/_api", - "children": [ - "/_api/search/" - ] - }, "/error/$code": { "filePath": "error/$code.tsx" }, @@ -782,7 +745,7 @@ export const routeTree = rootRoute }, "/_api/search/": { "filePath": "_api/search/index.tsx", - "parent": "/_api/search" + "parent": "/_api" }, "/_api/login/$userId/$userName": { "filePath": "_api/login/$userId.$userName.tsx", diff --git a/src/routes/_api/item/$id.tsx b/src/routes/_api/item/$id.tsx index 9a4ce96..3db91d4 100644 --- a/src/routes/_api/item/$id.tsx +++ b/src/routes/_api/item/$id.tsx @@ -152,7 +152,9 @@ function ItemDetail() { return false; }); setSelectedVideoTrack( - result?.find((track) => track.IsDefault)?.Index ?? result?.[0].Index ?? 0, + result?.find((track) => track.IsDefault)?.Index ?? + result?.[0]?.Index ?? + 0, ); return result ?? []; }, [item.data?.Id]); @@ -164,7 +166,9 @@ function ItemDetail() { return false; }); setSelectedAudioTrack( - result?.find((track) => track.IsDefault)?.Index ?? result?.[0].Index ?? 0, + result?.find((track) => track.IsDefault)?.Index ?? + result?.[0]?.Index ?? + 0, ); return result ?? []; }, [item.data?.Id]); @@ -672,6 +676,7 @@ function ItemDetail() { ): { query: string } => { - return { - query: search?.query as string, - }; - }, -}); \ No newline at end of file diff --git a/src/routes/_api/search/index.tsx b/src/routes/_api/search/index.tsx index 147675c..a92683f 100644 --- a/src/routes/_api/search/index.tsx +++ b/src/routes/_api/search/index.tsx @@ -1,7 +1,5 @@ import React, { useEffect, useState } from "react"; -import CircularProgress from "@mui/material/CircularProgress"; -import InputAdornment from "@mui/material/InputAdornment"; import TextField from "@mui/material/TextField"; import { useBackdropStore } from "@/utils/store/backdrop"; @@ -9,12 +7,8 @@ import { useBackdropStore } from "@/utils/store/backdrop"; import { useQuery } from "@tanstack/react-query"; import { EmptyNotice } from "@/components/notices/emptyNotice/emptyNotice"; -import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; - -import useDebounce from "@/utils/hooks/useDebounce"; import { Card } from "@/components/card/card"; -import { EpisodeCard } from "@/components/card/episodeCard"; import CardScroller from "@/components/cardScroller/cardScroller"; import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; @@ -22,7 +16,7 @@ import { getPersonsApi } from "@jellyfin/sdk/lib/utils/api/persons-api"; import { getSearchApi } from "@jellyfin/sdk/lib/utils/api/search-api"; import "./search.scss"; import { useCentralStore } from "@/utils/store/central"; -import { Dialog, Fab } from "@mui/material"; +import { Fab } from "@mui/material"; import { Outlet, createFileRoute, useNavigate } from "@tanstack/react-router"; export const Route = createFileRoute("/_api/search/")({ @@ -48,6 +42,7 @@ function SearchPage() { const movies = useQuery({ queryKey: ["search", "items", "Movie", query], queryFn: async () => { + if (!api) return null; const result = await getItemsApi(api).getItems({ userId: user?.Id, searchTerm: query, @@ -62,6 +57,7 @@ function SearchPage() { const series = useQuery({ queryKey: ["search", "items", "Series", query], queryFn: async () => { + if (!api) return null; const result = await getItemsApi(api).getItems({ userId: user?.Id, searchTerm: query, @@ -76,6 +72,7 @@ function SearchPage() { const musicAlbum = useQuery({ queryKey: ["search", "items", "MusicAlbum", query], queryFn: async () => { + if (!api) return null; const result = await getItemsApi(api).getItems({ userId: user?.Id, searchTerm: query, @@ -90,6 +87,7 @@ function SearchPage() { const audio = useQuery({ queryKey: ["search", "items", "Audio", query], queryFn: async () => { + if (!api) return null; const result = await getItemsApi(api).getItems({ userId: user?.Id, searchTerm: query, @@ -104,6 +102,7 @@ function SearchPage() { const book = useQuery({ queryKey: ["search", "items", "Book", query], queryFn: async () => { + if (!api) return null; const result = await getItemsApi(api).getItems({ userId: user?.Id, searchTerm: query, @@ -118,6 +117,7 @@ function SearchPage() { const musicArtists = useQuery({ queryKey: ["search", "items", "MusicArtists", query], queryFn: async () => { + if (!api) return null; const result = await getItemsApi(api).getItems({ userId: user?.Id, searchTerm: query, @@ -132,6 +132,7 @@ function SearchPage() { const person = useQuery({ queryKey: ["search", "items", "Person", query], queryFn: async () => { + if (!api) return null; const result = await getPersonsApi(api).getPersons({ userId: user?.Id, searchTerm: query, @@ -144,6 +145,7 @@ function SearchPage() { const episodes = useQuery({ queryKey: ["search", "items", "Episodes", query], queryFn: async () => { + if (!api) return null; const result = await getSearchApi(api).getSearchHints({ userId: user?.Id, searchTerm: query, @@ -161,6 +163,7 @@ function SearchPage() { // Removing app's backdrop setBackdrop("", ""); }, []); + return (
- {movies.isSuccess && movies.data.Items.length > 0 && ( - - {movies.data.Items.map((item) => ( + {movies.isSuccess && Boolean(movies.data?.Items?.length) && ( + + {movies.data?.Items?.map((item) => ( ))} )} - {series.isSuccess && series.data.Items.length > 0 && ( - - {series.data.Items.map((item, index) => ( + {series.isSuccess && Boolean(series.data?.Items?.length) && ( + + {series.data?.Items?.map((item) => ( ))} )} - {episodes.isSuccess && episodes.data.TotalRecordCount > 0 && ( + {episodes.isSuccess && Boolean(episodes.data?.TotalRecordCount) && ( - {episodes.data.SearchHints?.map((episode) => { + {episodes.data?.SearchHints?.map((episode) => { return ( )} - {audio.isSuccess && audio.data.Items?.length > 0 && ( - - {audio.data.Items?.map((item, index) => ( + {audio.isSuccess && Boolean(audio.data?.Items?.length) && ( + + {audio.data?.Items?.map((item) => ( )} - {musicAlbum.isSuccess && musicAlbum.data.Items?.length > 0 && ( - - {musicAlbum.data.Items?.map((item, index) => ( + {musicAlbum.isSuccess && Boolean(musicAlbum.data?.Items?.length) && ( + + {musicAlbum.data?.Items?.map((item) => ( )} - {book.isSuccess && book.data.Items?.length > 0 && ( - - {book.data.Items?.map((item, index) => ( + {book.isSuccess && Boolean(book.data?.Items?.length) && ( + + {book.data?.Items?.map((item) => ( )} - {musicArtists.isSuccess && musicArtists.data.Items?.length > 0 && ( - - {musicArtists.data.Items?.map((item) => ( - - ))} - - )} - {person.isSuccess && person.data.Items?.length > 0 && ( - - {person.data.Items?.map((item) => ( + {musicArtists.isSuccess && + Boolean(musicArtists.data?.Items?.length) && ( + + {musicArtists.data?.Items?.map((item) => ( + + ))} + + )} + {person.isSuccess && Boolean(person.data?.Items?.length) && ( + + {person.data?.Items?.map((item) => ( { const result = sessionStorage.getItem(`season-${item.data?.Id}`); - return result ?? seasons.data?.Items?.[0].IndexNumber ?? 0; + return result ?? 0; }); const currentSeasonItem = useQuery({