diff --git a/src/components/appBar/appBar.tsx b/src/components/appBar/appBar.tsx index 2bda322..f634aa3 100644 --- a/src/components/appBar/appBar.tsx +++ b/src/components/appBar/appBar.tsx @@ -85,7 +85,7 @@ export const AppBar = () => { const usr = await getUserApi(api).getCurrentUser(); return usr.data; }, - enabled: display, + enabled: display && Boolean(api), throwOnError: true, }); const libraries = useQuery({ diff --git a/src/components/playback/audioPlayer/index.jsx b/src/components/playback/audioPlayer/index.jsx index 9417489..bc60b8c 100644 --- a/src/components/playback/audioPlayer/index.jsx +++ b/src/components/playback/audioPlayer/index.jsx @@ -63,7 +63,7 @@ const AudioPlayer = () => { return usr.data; }, networkMode: "always", - enabled: Boolean(display), + enabled: Boolean(display) && Boolean(api), }); const waveSurferRef = useRef(null); diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index f586875..4c48128 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -14,9 +14,9 @@ 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 ApiLoginImport } from './routes/_api/login' 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' import { Route as ApiHomeIndexImport } from './routes/_api/home/index' import { Route as ApiFavoriteIndexImport } from './routes/_api/favorite/index' import { Route as SetupServerListImport } from './routes/setup/server.list' @@ -52,6 +52,11 @@ const ErrorCodeRoute = ErrorCodeImport.update({ getParentRoute: () => rootRoute, } as any) +const ApiLoginRoute = ApiLoginImport.update({ + path: '/login', + getParentRoute: () => ApiRoute, +} as any) + const ApiSearchIndexRoute = ApiSearchIndexImport.update({ path: '/search/', getParentRoute: () => ApiRoute, @@ -62,11 +67,6 @@ const ApiPlayerIndexRoute = ApiPlayerIndexImport.update({ getParentRoute: () => ApiRoute, } as any) -const ApiLoginIndexRoute = ApiLoginIndexImport.update({ - path: '/login/', - getParentRoute: () => ApiRoute, -} as any) - const ApiHomeIndexRoute = ApiHomeIndexImport.update({ path: '/home/', getParentRoute: () => ApiRoute, @@ -108,13 +108,13 @@ const ApiPersonIdRoute = ApiPersonIdImport.update({ } as any) const ApiLoginManualRoute = ApiLoginManualImport.update({ - path: '/login/manual', - getParentRoute: () => ApiRoute, + path: '/manual', + getParentRoute: () => ApiLoginRoute, } as any) const ApiLoginListRoute = ApiLoginListImport.update({ - path: '/login/list', - getParentRoute: () => ApiRoute, + path: '/list', + getParentRoute: () => ApiLoginRoute, } as any) const ApiLibraryIdRoute = ApiLibraryIdImport.update({ @@ -148,8 +148,8 @@ const ApiAlbumIdRoute = ApiAlbumIdImport.update({ } as any) const ApiLoginUserIdUserNameRoute = ApiLoginUserIdUserNameImport.update({ - path: '/login/$userId/$userName', - getParentRoute: () => ApiRoute, + path: '/$userId/$userName', + getParentRoute: () => ApiLoginRoute, } as any) // Populate the FileRoutesByPath interface @@ -170,6 +170,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ApiImport parentRoute: typeof rootRoute } + '/_api/login': { + id: '/_api/login' + path: '/login' + fullPath: '/login' + preLoaderRoute: typeof ApiLoginImport + parentRoute: typeof ApiImport + } '/error/$code': { id: '/error/$code' path: '/error/$code' @@ -221,17 +228,17 @@ declare module '@tanstack/react-router' { } '/_api/login/list': { id: '/_api/login/list' - path: '/login/list' + path: '/list' fullPath: '/login/list' preLoaderRoute: typeof ApiLoginListImport - parentRoute: typeof ApiImport + parentRoute: typeof ApiLoginImport } '/_api/login/manual': { id: '/_api/login/manual' - path: '/login/manual' + path: '/manual' fullPath: '/login/manual' preLoaderRoute: typeof ApiLoginManualImport - parentRoute: typeof ApiImport + parentRoute: typeof ApiLoginImport } '/_api/person/$id': { id: '/_api/person/$id' @@ -289,13 +296,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ApiHomeIndexImport parentRoute: typeof ApiImport } - '/_api/login/': { - id: '/_api/login/' - path: '/login' - fullPath: '/login' - preLoaderRoute: typeof ApiLoginIndexImport - parentRoute: typeof ApiImport - } '/_api/player/': { id: '/_api/player/' path: '/player' @@ -312,10 +312,10 @@ declare module '@tanstack/react-router' { } '/_api/login/$userId/$userName': { id: '/_api/login/$userId/$userName' - path: '/login/$userId/$userName' + path: '/$userId/$userName' fullPath: '/login/$userId/$userName' preLoaderRoute: typeof ApiLoginUserIdUserNameImport - parentRoute: typeof ApiImport + parentRoute: typeof ApiLoginImport } } } @@ -325,23 +325,24 @@ declare module '@tanstack/react-router' { export const routeTree = rootRoute.addChildren({ IndexRoute, ApiRoute: ApiRoute.addChildren({ + ApiLoginRoute: ApiLoginRoute.addChildren({ + ApiLoginListRoute, + ApiLoginManualRoute, + ApiLoginUserIdUserNameRoute, + }), ApiAlbumIdRoute, ApiArtistIdRoute, ApiBoxsetIdRoute, ApiEpisodeIdRoute, ApiItemIdRoute, ApiLibraryIdRoute, - ApiLoginListRoute, - ApiLoginManualRoute, ApiPersonIdRoute, ApiPlaylistIdRoute, ApiSeriesIdRoute, ApiFavoriteIndexRoute, ApiHomeIndexRoute, - ApiLoginIndexRoute, ApiPlayerIndexRoute, ApiSearchIndexRoute, - ApiLoginUserIdUserNameRoute, }), ErrorCodeRoute, SetupServerAddRoute, @@ -371,22 +372,28 @@ export const routeTree = rootRoute.addChildren({ "/_api": { "filePath": "_api.tsx", "children": [ + "/_api/login", "/_api/album/$id", "/_api/artist/$id", "/_api/boxset/$id", "/_api/episode/$id", "/_api/item/$id", "/_api/library/$id", - "/_api/login/list", - "/_api/login/manual", "/_api/person/$id", "/_api/playlist/$id", "/_api/series/$id", "/_api/favorite/", "/_api/home/", - "/_api/login/", "/_api/player/", - "/_api/search/", + "/_api/search/" + ] + }, + "/_api/login": { + "filePath": "_api/login.tsx", + "parent": "/_api", + "children": [ + "/_api/login/list", + "/_api/login/manual", "/_api/login/$userId/$userName" ] }, @@ -419,11 +426,11 @@ export const routeTree = rootRoute.addChildren({ }, "/_api/login/list": { "filePath": "_api/login/list.tsx", - "parent": "/_api" + "parent": "/_api/login" }, "/_api/login/manual": { "filePath": "_api/login/manual.tsx", - "parent": "/_api" + "parent": "/_api/login" }, "/_api/person/$id": { "filePath": "_api/person/$id.tsx", @@ -454,10 +461,6 @@ export const routeTree = rootRoute.addChildren({ "filePath": "_api/home/index.tsx", "parent": "/_api" }, - "/_api/login/": { - "filePath": "_api/login/index.tsx", - "parent": "/_api" - }, "/_api/player/": { "filePath": "_api/player/index.tsx", "parent": "/_api" @@ -468,7 +471,7 @@ export const routeTree = rootRoute.addChildren({ }, "/_api/login/$userId/$userName": { "filePath": "_api/login/$userId.$userName.tsx", - "parent": "/_api" + "parent": "/_api/login" } } } diff --git a/src/routes/_api/login.tsx b/src/routes/_api/login.tsx new file mode 100644 index 0000000..e60c3bb --- /dev/null +++ b/src/routes/_api/login.tsx @@ -0,0 +1,16 @@ +import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; +import { createFileRoute, redirect } from "@tanstack/react-router"; + +export const Route = createFileRoute("/_api/login")({ + beforeLoad: async ({ context, location }) => { + if (location.pathname === "/login") { + const api = context.api; + console.log(api); + const publicUsers = (await getUserApi(api).getPublicUsers()).data; + if (publicUsers.length > 0) { + throw redirect({ to: "/login/list" }); + } + throw redirect({ to: "/login/manual" }); + } + }, +}); \ No newline at end of file diff --git a/src/routes/_api/login/$userId.$userName.tsx b/src/routes/_api/login/$userId.$userName.tsx index 7a4d1d1..fce7a13 100644 --- a/src/routes/_api/login/$userId.$userName.tsx +++ b/src/routes/_api/login/$userId.$userName.tsx @@ -84,7 +84,7 @@ function LoginUser() { await saveUser(userName, user.data.AccessToken); } setLoading(false); - navigate("/home"); + navigate({ to: "/home" }); }; useLayoutEffect(() => { diff --git a/src/routes/_api/login/index.tsx b/src/routes/_api/login/index.tsx deleted file mode 100644 index d7d8064..0000000 --- a/src/routes/_api/login/index.tsx +++ /dev/null @@ -1,91 +0,0 @@ -import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; -import { Typography } from "@mui/material"; -import CircularProgress from "@mui/material/CircularProgress"; -import { useQuery } from "@tanstack/react-query"; -import { useLocation, useNavigate } from "@tanstack/react-router"; -import React, { Suspense, useState } from "react"; - -import "./login.scss"; - -import { createFileRoute } from "@tanstack/react-router"; -import { AnimatePresence, motion } from "framer-motion"; -import Markdown from "react-markdown"; -import remarkGfm from "remark-gfm"; - -export const Route = createFileRoute("/_api/login/")({ - component: LoginRoute, -}); - -function LoginRoute() { - const location = useLocation(); - const navigate = useNavigate(); - const api = Route.useRouteContext().api; - const [status, setStatus] = useState("Fetching public users..."); - - const usersList = useQuery({ - queryKey: ["public-users"], - queryFn: async () => { - const result = await getUserApi(api).getPublicUsers(); - return result.data; - }, - enabled: Boolean(api), - }); - - if (location.pathname === "/login") { - console.log(api); - if (usersList.isSuccess && !usersList.isFetching) { - if (usersList.data.length > 0) { - setStatus("Public users found!"); - navigate({ to: "/login/list" }); - } else { - setStatus("No public users found"); - navigate({ to: "/login/manual" }); - } - } - } - - return ( - Loading /login}> -
- - - - - {status} - - - -
-
- ); -} diff --git a/src/routes/_api/login/list.tsx b/src/routes/_api/login/list.tsx index d120b56..4b11739 100644 --- a/src/routes/_api/login/list.tsx +++ b/src/routes/_api/login/list.tsx @@ -40,11 +40,6 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router"; export const Route = createFileRoute("/_api/login/list")({ component: LoginPublicUsersList, - loader: async ({context}) => { - const api = context.api; - const result = await getUserApi(api).getPublicUsers(); - return result.data; - }, }); function LoginPublicUsersList() { @@ -70,7 +65,14 @@ function LoginPublicUsersList() { const handleManualLogin = () => { // navigate("/login/manual"); }; - const users = Route.useLoaderData(); + const users = useQuery({ + queryKey: ["login", "public-users"], + queryFn: async () => { + const result = await getUserApi(api).getPublicUsers(); + return result.data; + }, + enabled: Boolean(api), + }); const handleQuickConnect = async () => { setQuickConnectLoading(0); @@ -218,7 +220,10 @@ function LoginPublicUsersList() { itemType="User" cardType="square" onClick={() => - navigate(`/login/withImg/${item.Name}/${item.Id}/`) + navigate({ + to: "/login/$userId/$userName", + params: { userId: item.Id, userName: item.Name }, + }) } overrideIcon="User" imageType="Primary" diff --git a/src/routes/setup/server.list.tsx b/src/routes/setup/server.list.tsx index 48a3d06..6ed757c 100644 --- a/src/routes/setup/server.list.tsx +++ b/src/routes/setup/server.list.tsx @@ -71,7 +71,7 @@ function ServerList() { await delUser(); await servers.refetch(); - if (servers.length > 0) { + if (servers.length > 1) { setDefaultServer(servers[0].id); createApi(servers[0].address, undefined); } else { @@ -109,7 +109,7 @@ function ServerList() { style={{ fontSize: "1.64em", }} - onClick={() => navigate({ to: "/setup/server" })} + onClick={() => navigate({ to: "/setup/server/add" })} >
add