diff --git a/src/components/appBar/appBar.tsx b/src/components/appBar/appBar.tsx index 12b5d95..521c75c 100644 --- a/src/components/appBar/appBar.tsx +++ b/src/components/appBar/appBar.tsx @@ -203,30 +203,23 @@ export const AppBar = () => { - { - setSettingsDialogOpen(true); - setSettingsTabValue(1); - }} + - settings - Settings - + /> { - setSettingsDialogOpen(true); - setSettingsTabValue(2); - }} style={{ borderRadius: "100px", gap: "0.85em", }} + disabled > dns Change Server diff --git a/src/components/carousel/carousel.scss b/src/components/carousel/carousel.scss index 7d39f6f..42280bc 100644 --- a/src/components/carousel/carousel.scss +++ b/src/components/carousel/carousel.scss @@ -89,6 +89,15 @@ border-radius: 8px; object-fit: cover; box-shadow: 0 2px 8px rgba(0,0,0,0.2); + + &.placeholder { + display: flex; + align-items: center; + justify-content: center; + background: rgb(100 100 100 / 0.1); + color: rgb(200 200 200 / 0.7); + font-size: 2rem; + } } & > div { diff --git a/src/components/carousel/index.tsx b/src/components/carousel/index.tsx index b24da91..b1effe6 100644 --- a/src/components/carousel/index.tsx +++ b/src/components/carousel/index.tsx @@ -113,14 +113,16 @@ const Carousel = ({ > ))} diff --git a/src/components/carousel/tickers.tsx b/src/components/carousel/tickers.tsx index 52d6fb8..b99213c 100644 --- a/src/components/carousel/tickers.tsx +++ b/src/components/carousel/tickers.tsx @@ -1,13 +1,16 @@ +import type { BaseItemKind } from "@jellyfin/sdk/lib/generated-client"; import { Typography } from "@mui/material"; import React from "react"; +import { getTypeIcon } from "../utils/iconsCollection"; type CarouselTickersProps = { - imageUrl?: string; + imageUrl?: string | undefined | null; itemName: string; itemYear: string; onTickerClick: (index: number) => void; index: number; isActive: boolean; + itemType: BaseItemKind; }; const CarouselTickers = React.memo( @@ -18,6 +21,7 @@ const CarouselTickers = React.memo( onTickerClick, index, isActive, + itemType, }: CarouselTickersProps) => { const handleClick = React.useCallback(() => { onTickerClick(index); @@ -28,12 +32,18 @@ const CarouselTickers = React.memo( className={`carousel-ticker${isActive ? " active" : ""}`} onClick={handleClick} > - {itemName} + {imageUrl ? ( + {itemName} + ) : ( +
+ {" "} + {getTypeIcon(itemType)} +
+ )}
{itemName} diff --git a/src/components/userAvatarMenu/index.tsx b/src/components/userAvatarMenu/index.tsx index f2a6103..443eccc 100644 --- a/src/components/userAvatarMenu/index.tsx +++ b/src/components/userAvatarMenu/index.tsx @@ -17,10 +17,6 @@ import React, { import { delUser } from "@/utils/storage/user"; import { useApiInContext } from "@/utils/store/api"; import { useCentralStore } from "@/utils/store/central"; -import { - setSettingsDialogOpen, - setSettingsTabValue, -} from "@/utils/store/settings"; export const UserAvatarMenu = () => { const api = useApiInContext((s) => s.api); @@ -105,18 +101,6 @@ export const UserAvatarMenu = () => { Logout - { - setSettingsDialogOpen(true); - setSettingsTabValue(1); - handleMenuClose(); - }} - > - - settings - - Settings - { navigate({ to: "/settings/preferences" }); diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index aacf35d..752dfd0 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -36,6 +36,7 @@ import { Route as ApiEpisodeIdRouteImport } from './routes/_api/episode/$id' import { Route as ApiBoxsetIdRouteImport } from './routes/_api/boxset/$id' import { Route as ApiArtistIdRouteImport } from './routes/_api/artist/$id' import { Route as ApiAlbumIdRouteImport } from './routes/_api/album/$id' +import { Route as ApiSettingsChangeServerIndexRouteImport } from './routes/_api/settings/changeServer/index' import { Route as ApiLoginUserIdUserNameRouteImport } from './routes/_api/login/$userId.$userName' const ApiRoute = ApiRouteImport.update({ @@ -172,6 +173,12 @@ const ApiAlbumIdRoute = ApiAlbumIdRouteImport.update({ path: '/album/$id', getParentRoute: () => ApiRoute, } as any) +const ApiSettingsChangeServerIndexRoute = + ApiSettingsChangeServerIndexRouteImport.update({ + id: '/changeServer/', + path: '/changeServer/', + getParentRoute: () => ApiSettingsRoute, + } as any) const ApiLoginUserIdUserNameRoute = ApiLoginUserIdUserNameRouteImport.update({ id: '/$userId/$userName', path: '/$userId/$userName', @@ -206,6 +213,7 @@ export interface FileRoutesByFullPath { '/player/': typeof ApiPlayerIndexRoute '/search/': typeof ApiSearchIndexRoute '/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute + '/settings/changeServer/': typeof ApiSettingsChangeServerIndexRoute } export interface FileRoutesByTo { '/': typeof IndexRoute @@ -235,6 +243,7 @@ export interface FileRoutesByTo { '/player': typeof ApiPlayerIndexRoute '/search': typeof ApiSearchIndexRoute '/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute + '/settings/changeServer': typeof ApiSettingsChangeServerIndexRoute } export interface FileRoutesById { __root__: typeof rootRouteImport @@ -266,6 +275,7 @@ export interface FileRoutesById { '/_api/player/': typeof ApiPlayerIndexRoute '/_api/search/': typeof ApiSearchIndexRoute '/_api/login/$userId/$userName': typeof ApiLoginUserIdUserNameRoute + '/_api/settings/changeServer/': typeof ApiSettingsChangeServerIndexRoute } export interface FileRouteTypes { fileRoutesByFullPath: FileRoutesByFullPath @@ -297,6 +307,7 @@ export interface FileRouteTypes { | '/player/' | '/search/' | '/login/$userId/$userName' + | '/settings/changeServer/' fileRoutesByTo: FileRoutesByTo to: | '/' @@ -326,6 +337,7 @@ export interface FileRouteTypes { | '/player' | '/search' | '/login/$userId/$userName' + | '/settings/changeServer' id: | '__root__' | '/' @@ -356,6 +368,7 @@ export interface FileRouteTypes { | '/_api/player/' | '/_api/search/' | '/_api/login/$userId/$userName' + | '/_api/settings/changeServer/' fileRoutesById: FileRoutesById } export interface RootRouteChildren { @@ -558,6 +571,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ApiAlbumIdRouteImport parentRoute: typeof ApiRoute } + '/_api/settings/changeServer/': { + id: '/_api/settings/changeServer/' + path: '/changeServer' + fullPath: '/settings/changeServer/' + preLoaderRoute: typeof ApiSettingsChangeServerIndexRouteImport + parentRoute: typeof ApiSettingsRoute + } '/_api/login/$userId/$userName': { id: '/_api/login/$userId/$userName' path: '/$userId/$userName' @@ -587,11 +607,13 @@ const ApiLoginRouteWithChildren = ApiLoginRoute._addFileChildren( interface ApiSettingsRouteChildren { ApiSettingsAboutRoute: typeof ApiSettingsAboutRoute ApiSettingsPreferencesRoute: typeof ApiSettingsPreferencesRoute + ApiSettingsChangeServerIndexRoute: typeof ApiSettingsChangeServerIndexRoute } const ApiSettingsRouteChildren: ApiSettingsRouteChildren = { ApiSettingsAboutRoute: ApiSettingsAboutRoute, ApiSettingsPreferencesRoute: ApiSettingsPreferencesRoute, + ApiSettingsChangeServerIndexRoute: ApiSettingsChangeServerIndexRoute, } const ApiSettingsRouteWithChildren = ApiSettingsRoute._addFileChildren( diff --git a/src/routes/_api/home/index.tsx b/src/routes/_api/home/index.tsx index afcdd50..5661bf7 100644 --- a/src/routes/_api/home/index.tsx +++ b/src/routes/_api/home/index.tsx @@ -3,10 +3,12 @@ import React, { useCallback, useMemo } from "react"; import "./home.scss"; +import type { Api } from "@jellyfin/sdk"; import { type BaseItemDto, BaseItemKind, ItemFields, + type UserDto, } from "@jellyfin/sdk/lib/generated-client"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api"; @@ -40,10 +42,17 @@ function Home() { const api = useApiInContext((s) => s.api); const user = useCentralStore((s) => s.currentUser); + if (!api || !user?.Id) { + return ; + } + + return ; +} + +function HomeContent({ api, user }: { api: Api; user: UserDto }) { const libraries = useSuspenseQuery({ queryKey: ["libraries"], queryFn: async () => { - if (!api || !user?.Id) return null; const libs = await getUserViewsApi(api).getUserViews({ userId: user.Id, }); @@ -52,12 +61,13 @@ function Home() { networkMode: "always", }); - const latestMedia = useSuspenseQuery(getLatestItemsQueryOptions(api, user?.Id)); + const latestMedia = useSuspenseQuery( + getLatestItemsQueryOptions(api, user.Id), + ); const resumeItemsVideo = useSuspenseQuery({ queryKey: ["home", "resume", "video"], queryFn: async () => { - if (!api || !user?.Id) return null; const resumeItems = await getItemsApi(api).getResumeItems({ userId: user.Id, limit: 10, @@ -72,9 +82,8 @@ function Home() { const resumeItemsAudio = useSuspenseQuery({ queryKey: ["home", "resume", "audio"], queryFn: async () => { - if (!api || !user?.Id) return null; const resumeItems = await getItemsApi(api).getResumeItems({ - userId: user?.Id, + userId: user.Id, limit: 10, mediaTypes: ["Audio"], enableUserData: true, @@ -87,9 +96,8 @@ function Home() { const upNextItems = useSuspenseQuery({ queryKey: ["home", "upNext"], queryFn: async () => { - if (!api || !user?.Id) return null; const upNext = await getTvShowsApi(api).getNextUp({ - userId: user?.Id, + userId: user.Id, fields: [ ItemFields.PrimaryImageAspectRatio, ItemFields.MediaStreams, diff --git a/src/routes/_api/login/$userId.$userName.tsx b/src/routes/_api/login/$userId.$userName.tsx index c66fcde..0241b9c 100644 --- a/src/routes/_api/login/$userId.$userName.tsx +++ b/src/routes/_api/login/$userId.$userName.tsx @@ -12,9 +12,6 @@ import { useSnackbar } from "notistack"; import { AvatarImage } from "@/components/avatar/avatar.jsx"; import "./login.scss"; -import { saveUser } from "@/utils/storage/user"; -import { useApiInContext } from "@/utils/store/api"; -import { useBackdropStore } from "@/utils/store/backdrop.js"; import { useMutation } from "@tanstack/react-query"; import { createFileRoute, @@ -27,6 +24,9 @@ import React, { useEffect, useState, } from "react"; +import { saveUser } from "@/utils/storage/user"; +import { useApiInContext } from "@/utils/store/api"; +import { useBackdropStore } from "@/utils/store/backdrop.js"; export const Route = createFileRoute("/_api/login/$userId/$userName")({ component: LoginUser, @@ -102,7 +102,13 @@ function LoginUser() { } createApi(api.basePath, authenticate.data?.AccessToken); - if (rememberMe) await saveUser(userName, authenticate.data.AccessToken); + if (authenticate.data.SessionInfo?.UserId && rememberMe) { + await saveUser( + userName, + authenticate.data.AccessToken, + authenticate.data.SessionInfo.UserId, + ); + } router.invalidate().finally(() => { navigate({ to: "/home", replace: true }); diff --git a/src/routes/_api/settings.tsx b/src/routes/_api/settings.tsx index 09a98b7..90b2318 100644 --- a/src/routes/_api/settings.tsx +++ b/src/routes/_api/settings.tsx @@ -63,6 +63,12 @@ function SettingsRoute() { primary="Preferences" className="settings-sidebar-list-item" /> + s.createApi); + const { enqueueSnackbar } = useSnackbar(); + const [addServerDialogOpen, setAddServerDialogOpen] = useState(false); + + const serversQuery = useQuery({ + queryKey: ["servers"], + queryFn: async () => { + return await getAllServers(); + }, + }); + + const activeServerQuery = useQuery({ + queryKey: ["activeServer"], + queryFn: async () => { + return await getDefaultServer(); + }, + }); + + const handleConnect = async (serverId: string) => { + try { + // Clear current user when switching servers to force login/user fetch + await delUser(); + await setDefaultServer(serverId); + + const servers = await getAllServers(); + const server = servers.find((s) => s.id === serverId); + + if (server) { + createApi(server.address); + } + + // Reload the page to reset API context and states + window.location.href = "/"; + } catch (error) { + console.error("Failed to switch server", error); + enqueueSnackbar("Failed to switch server", { variant: "error" }); + } + }; + + const handleDelete = async (serverId: string) => { + try { + await delServer(serverId); + queryClient.invalidateQueries({ queryKey: ["servers"] }); + enqueueSnackbar("Server removed", { variant: "success" }); + } catch (error) { + console.error("Failed to delete server", error); + enqueueSnackbar("Failed to delete server", { variant: "error" }); + } + }; + + if (serversQuery.isLoading || activeServerQuery.isLoading) { + return ; + } + + return ( +
+
+ Servers +
+ + + {serversQuery.data?.map((server) => { + const isActive = activeServerQuery.data === server.id; + const spalshUrl = + new URL(server.address).pathname.length > 1 + ? `${new URL(server.address).origin}${`${new URL(server.address).pathname}/`}Branding/Splashscreen?fillWidth=400&fillHeight=100` + : `${server.address}Branding/Splashscreen?fillWidth=400&fillHeight=100`; + + return ( + + + {/* Standard BG Section / Cover Area */} +
+ {server.systemInfo?.ServerName +
+ + {isActive && ( + + )} + + +
+
+ + dns + +
+
+ + + {server.systemInfo?.ServerName || "Unknown Server"} + + + {server.address} + +
+ + + + + {!isActive ? ( + + ) : ( + + )} + +
+
+ ); + })} + + {/* Add Server Card */} + + setAddServerDialogOpen(true)} + elevation={0} + sx={{ + height: "100%", + minHeight: "280px", + display: "flex", + flexDirection: "column", + alignItems: "center", + justifyContent: "center", + position: "relative", + borderRadius: "24px", + cursor: "pointer", + background: "rgba(255, 255, 255, 0.02)", + border: "2px dashed rgba(255, 255, 255, 0.1)", + transition: "all 0.2s ease-in-out", + "&:hover": { + background: "rgba(255, 255, 255, 0.05)", + borderColor: "rgba(255, 255, 255, 0.3)", + transform: "translateY(-4px)", + "& .add-icon": { + transform: "scale(1.1) rotate(90deg)", + color: "var(--mui-palette-primary-main)", + }, + }, + }} + > +
+ + add + +
+ + Add Server + + + Connect to a new Jellyfin server + +
+
+
+ + { + await queryClient.invalidateQueries({ queryKey: ["servers"] }); + }} + /> +
+ ); +} diff --git a/src/utils/queries/items.ts b/src/utils/queries/items.ts index 12f6e0d..74bfca0 100644 --- a/src/utils/queries/items.ts +++ b/src/utils/queries/items.ts @@ -18,8 +18,11 @@ export const getItemQueryOptions = ( queryOptions({ queryKey: ["item", id], queryFn: async () => { - if (!api || !userId) { - throw Error("API or User ID is not defined"); + if (!api) { + throw Error("API is not defined"); + } + if (!userId) { + throw Error("User ID is not defined"); } const result = await getUserLibraryApi(api).getItem({ userId: userId, @@ -42,8 +45,11 @@ export const getLatestItemsQueryOptions = ( queryOptions({ queryKey: ["home", "latestMedia"], queryFn: async () => { - if (!api || !userId) { - throw Error("API or User ID is not defined"); + if (!api) { + throw Error("API is not defined"); + } + if (!userId) { + throw Error("User ID is not defined"); } const media = await getUserLibraryApi(api).getLatestMedia({ userId: userId, diff --git a/src/utils/storage/user.ts b/src/utils/storage/user.ts index cacdf29..7b4a800 100644 --- a/src/utils/storage/user.ts +++ b/src/utils/storage/user.ts @@ -1,21 +1,27 @@ import { load } from "@tauri-apps/plugin-store"; export interface UserStore { - user: { - Name: string; - AccessToken: string; - }; -} + user: { + Name: string; + AccessToken: string; + Id: string; + }; + } const user = await load(".user.dat", { autoSave: true }); /** * Set User details to .user.dat */ -const saveUser = async (userName: string, accessToken: string) => { +const saveUser = async ( + userName: string, + accessToken: string, + userId: string, +) => { user.set("user", { Name: userName, AccessToken: accessToken, + Id: userId, }); await user.save(); diff --git a/src/utils/store/central.tsx b/src/utils/store/central.tsx index b3ad7f0..12d321b 100644 --- a/src/utils/store/central.tsx +++ b/src/utils/store/central.tsx @@ -1,17 +1,21 @@ import type { Api } from "@jellyfin/sdk"; import type { UserDto } from "@jellyfin/sdk/lib/generated-client"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; -import React, { type ReactNode } from "react"; -import { createContext, useContext, useState } from "react"; -import { type StoreApi, createStore } from "zustand"; +import React, { + createContext, + type ReactNode, + useContext, + useState, +} from "react"; +import { createStore, type StoreApi } from "zustand"; import { shallow } from "zustand/shallow"; import { useStoreWithEqualityFn } from "zustand/traditional"; import { version } from "../../../package.json"; import { - type ServerInfo, getAllServers, getDefaultServer, getServer, + type ServerInfo, } from "../storage/servers"; import { getUser } from "../storage/user"; @@ -22,6 +26,7 @@ type CentralStore = { userOnDisk: () => Promise<{ Name: string; AccessToken: string; + Id: string; } | null>; clientVersion: string; currentUser: null | UserDto;