refactor: implement new login logic and verify context.api status
This commit is contained in:
25 files changed
+589
-513
No files matched your search
Vendored
+4
-1
@@ -23,5 +23,8 @@
|
||||
"editor.defaultFormatter": "biomejs.biome"
|
||||
},
|
||||
"rust-analyzer.linkedProjects": ["./src-tauri/Cargo.toml"],
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"[scss]": {
|
||||
"editor.defaultFormatter": "vscode.css-language-features"
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<script src="http://localhost:8097"></script>
|
||||
<title>Jellyplayer</title>
|
||||
<style>
|
||||
.app-loading {
|
||||
|
||||
@@ -53,6 +53,7 @@ import {
|
||||
ListItemButton,
|
||||
ListItemText,
|
||||
} from "@mui/material";
|
||||
import BackButton from "../buttons/backButton";
|
||||
|
||||
interface ListItemLinkProps {
|
||||
icon?: React.ReactElement;
|
||||
@@ -103,24 +104,18 @@ export const AppBar = () => {
|
||||
return usr.data;
|
||||
},
|
||||
enabled: display,
|
||||
networkMode: "always",
|
||||
});
|
||||
const libraries = useQuery({
|
||||
queryKey: ["libraries"],
|
||||
queryFn: async () => {
|
||||
const libs = await getUserViewsApi(api).getUserViews({
|
||||
userId: user.data.Id,
|
||||
userId: user.data?.Id,
|
||||
});
|
||||
return libs.data;
|
||||
},
|
||||
enabled: !!user.data && !!api.accessToken,
|
||||
networkMode: "always",
|
||||
});
|
||||
useEffect(() => {
|
||||
if (user.isError) {
|
||||
console.error(user.error);
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
const trigger = useScrollTrigger({
|
||||
disableHysteresis: true,
|
||||
@@ -197,13 +192,8 @@ export const AppBar = () => {
|
||||
<IconButton onClick={() => setShowDrawer(true)}>
|
||||
<div className="material-symbols-rounded">menu</div>
|
||||
</IconButton>
|
||||
<IconButton
|
||||
disabled={!backButtonVisible}
|
||||
onClick={() => navigate(-1)}
|
||||
>
|
||||
<div className="material-symbols-rounded">arrow_back</div>
|
||||
</IconButton>
|
||||
<IconButton onClick={() => navigate("/home")}>
|
||||
<BackButton />
|
||||
<IconButton onClick={() => navigate({ to: "/home/" })}>
|
||||
<div
|
||||
className={
|
||||
location.pathname === "/home"
|
||||
|
||||
@@ -4,6 +4,7 @@ import React, { useEffect } from "react";
|
||||
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import { pink } from "@mui/material/colors";
|
||||
@@ -12,7 +13,7 @@ import { useRouteContext } from "@tanstack/react-router";
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const queryClient = useQueryClient();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
|
||||
@@ -8,12 +8,13 @@ import IconButton from "@mui/material/IconButton";
|
||||
import { green } from "@mui/material/colors";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
||||
import { useRouteContext } from "@tanstack/react-router";
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
@@ -34,6 +34,7 @@ import { playItem, usePlaybackDataLoadStore } from "@/utils/store/playback";
|
||||
import type PlayResult from "@//utils/types/playResult";
|
||||
import { getRuntimeCompact } from "@/utils/date/time";
|
||||
import playbackProfile from "@/utils/playback-profiles";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import type { SxProps } from "@mui/material";
|
||||
import type { AxiosResponse } from "axios";
|
||||
@@ -77,7 +78,7 @@ const PlayButton = ({
|
||||
playlistItemId = "",
|
||||
trackIndex,
|
||||
}: PlayButtonProps) => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const setPlaybackDataLoading = usePlaybackDataLoadStore(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { playItemFromQueue } from "@/utils/store/playback";
|
||||
import useQueue from "@/utils/store/queue";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
@@ -7,7 +8,7 @@ import { useRouteContext } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
|
||||
const PlayNextButton = () => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useRouteContext } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
|
||||
const PlayPreviousButton = () => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
|
||||
@@ -15,7 +15,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import "./queueButton.scss";
|
||||
import { useRouteContext } from "@tanstack/react-router";
|
||||
const QueueButton = () => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const [queueItems, currentItemIndex] = useQueue((state) => [
|
||||
state.tracks,
|
||||
state.currentItemIndex,
|
||||
|
||||
@@ -18,6 +18,7 @@ import PlayButton from "../buttons/playButton";
|
||||
import ErrorBoundary from "../errorBoundary";
|
||||
import { getTypeIcon } from "../utils/iconsCollection";
|
||||
import "./card.scss";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
|
||||
const cardImageAspectRatios = {
|
||||
thumb: 1.777,
|
||||
@@ -60,7 +61,7 @@ export const Card = ({
|
||||
disableOverlay: boolean;
|
||||
overrideIcon: any;
|
||||
}) => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const navigate = useNavigate();
|
||||
const defaultOnClick = () => {
|
||||
if (availableSpecialRoutes.includes(item.Type)) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate, useRouteContext } from "@tanstack/react-router";
|
||||
import { getTypeIcon } from "../utils/iconsCollection";
|
||||
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCarouselStore } from "@/utils/store/carousel";
|
||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
@@ -41,7 +42,7 @@ const availableSpecialRoutes = [
|
||||
* @returns {React.Component}
|
||||
*/
|
||||
const CarouselSlide = ({ item }) => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const user = useQuery({
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Card } from "../../card/card";
|
||||
import { CardScroller } from "../../cardScroller/cardScroller";
|
||||
import { CardsSkeleton } from "../../skeleton/cards";
|
||||
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
@@ -13,7 +14,7 @@ import { useRouteContext } from "@tanstack/react-router";
|
||||
* @description Latest Media Section
|
||||
*/
|
||||
export const LatestMediaSection = ({ latestMediaLib }) => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { LinearProgress } from "@mui/material";
|
||||
import { useNProgress } from "@tanem/react-nprogress";
|
||||
import React from "react";
|
||||
import type React from "react";
|
||||
|
||||
const NProgress: React.FC<{ isAnimating: boolean | number }> = ({
|
||||
isAnimating,
|
||||
@@ -19,7 +19,7 @@ const NProgress: React.FC<{ isAnimating: boolean | number }> = ({
|
||||
top: "0",
|
||||
left: "0",
|
||||
right: "0",
|
||||
zIndex: "10000",
|
||||
zIndex: "10001",
|
||||
}}
|
||||
>
|
||||
<LinearProgress
|
||||
|
||||
+2
-1
@@ -46,7 +46,8 @@ function ProviderWrapper() {
|
||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||
<React.StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<Suspense fallback={<h1>Fuck react</h1>}>
|
||||
{/* TODO: Create a proper loading fallback component */}
|
||||
<Suspense fallback={<h1>Loading in main.tsx</h1>}>
|
||||
<ApiProvider>
|
||||
<ProviderWrapper />
|
||||
</ApiProvider>
|
||||
|
||||
+81
-4
@@ -19,6 +19,7 @@ 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'
|
||||
import { Route as SetupServerErrorImport } from './routes/setup/server.error'
|
||||
import { Route as SetupServerAddImport } from './routes/setup/server.add'
|
||||
import { Route as ApiSeriesIdImport } from './routes/_api/series/$id'
|
||||
import { Route as ApiPlaylistIdImport } from './routes/_api/playlist/$id'
|
||||
@@ -75,6 +76,11 @@ const SetupServerListRoute = SetupServerListImport.update({
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
const SetupServerErrorRoute = SetupServerErrorImport.update({
|
||||
path: '/setup/server/error',
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
const SetupServerAddRoute = SetupServerAddImport.update({
|
||||
path: '/setup/server/add',
|
||||
getParentRoute: () => rootRoute,
|
||||
@@ -145,86 +151,156 @@ const ApiLoginUserIdUserNameRoute = ApiLoginUserIdUserNameImport.update({
|
||||
declare module '@tanstack/react-router' {
|
||||
interface FileRoutesByPath {
|
||||
'/': {
|
||||
id: '/'
|
||||
path: '/'
|
||||
fullPath: '/'
|
||||
preLoaderRoute: typeof IndexImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/_api': {
|
||||
id: '/_api'
|
||||
path: ''
|
||||
fullPath: ''
|
||||
preLoaderRoute: typeof ApiImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/_api/album/$id': {
|
||||
id: '/_api/album/$id'
|
||||
path: '/album/$id'
|
||||
fullPath: '/album/$id'
|
||||
preLoaderRoute: typeof ApiAlbumIdImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/artist/$id': {
|
||||
id: '/_api/artist/$id'
|
||||
path: '/artist/$id'
|
||||
fullPath: '/artist/$id'
|
||||
preLoaderRoute: typeof ApiArtistIdImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/boxset/$id': {
|
||||
id: '/_api/boxset/$id'
|
||||
path: '/boxset/$id'
|
||||
fullPath: '/boxset/$id'
|
||||
preLoaderRoute: typeof ApiBoxsetIdImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/episode/$id': {
|
||||
id: '/_api/episode/$id'
|
||||
path: '/episode/$id'
|
||||
fullPath: '/episode/$id'
|
||||
preLoaderRoute: typeof ApiEpisodeIdImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/item/$id': {
|
||||
id: '/_api/item/$id'
|
||||
path: '/item/$id'
|
||||
fullPath: '/item/$id'
|
||||
preLoaderRoute: typeof ApiItemIdImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/library/$id': {
|
||||
id: '/_api/library/$id'
|
||||
path: '/library/$id'
|
||||
fullPath: '/library/$id'
|
||||
preLoaderRoute: typeof ApiLibraryIdImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/login/list': {
|
||||
id: '/_api/login/list'
|
||||
path: '/login/list'
|
||||
fullPath: '/login/list'
|
||||
preLoaderRoute: typeof ApiLoginListImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/login/manual': {
|
||||
id: '/_api/login/manual'
|
||||
path: '/login/manual'
|
||||
fullPath: '/login/manual'
|
||||
preLoaderRoute: typeof ApiLoginManualImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/person/$id': {
|
||||
id: '/_api/person/$id'
|
||||
path: '/person/$id'
|
||||
fullPath: '/person/$id'
|
||||
preLoaderRoute: typeof ApiPersonIdImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/playlist/$id': {
|
||||
id: '/_api/playlist/$id'
|
||||
path: '/playlist/$id'
|
||||
fullPath: '/playlist/$id'
|
||||
preLoaderRoute: typeof ApiPlaylistIdImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/series/$id': {
|
||||
id: '/_api/series/$id'
|
||||
path: '/series/$id'
|
||||
fullPath: '/series/$id'
|
||||
preLoaderRoute: typeof ApiSeriesIdImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/setup/server/add': {
|
||||
id: '/setup/server/add'
|
||||
path: '/setup/server/add'
|
||||
fullPath: '/setup/server/add'
|
||||
preLoaderRoute: typeof SetupServerAddImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/setup/server/error': {
|
||||
id: '/setup/server/error'
|
||||
path: '/setup/server/error'
|
||||
fullPath: '/setup/server/error'
|
||||
preLoaderRoute: typeof SetupServerErrorImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/setup/server/list': {
|
||||
id: '/setup/server/list'
|
||||
path: '/setup/server/list'
|
||||
fullPath: '/setup/server/list'
|
||||
preLoaderRoute: typeof SetupServerListImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/_api/favorite/': {
|
||||
id: '/_api/favorite/'
|
||||
path: '/favorite/'
|
||||
fullPath: '/favorite/'
|
||||
preLoaderRoute: typeof ApiFavoriteIndexImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/home/': {
|
||||
id: '/_api/home/'
|
||||
path: '/home/'
|
||||
fullPath: '/home/'
|
||||
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/'
|
||||
fullPath: '/player/'
|
||||
preLoaderRoute: typeof ApiPlayerIndexImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/search/': {
|
||||
id: '/_api/search/'
|
||||
path: '/search/'
|
||||
fullPath: '/search/'
|
||||
preLoaderRoute: typeof ApiSearchIndexImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/login/$userId/$userName': {
|
||||
id: '/_api/login/$userId/$userName'
|
||||
path: '/login/$userId/$userName'
|
||||
fullPath: '/login/$userId/$userName'
|
||||
preLoaderRoute: typeof ApiLoginUserIdUserNameImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
@@ -233,9 +309,9 @@ declare module '@tanstack/react-router' {
|
||||
|
||||
// Create and export the route tree
|
||||
|
||||
export const routeTree = rootRoute.addChildren([
|
||||
export const routeTree = rootRoute.addChildren({
|
||||
IndexRoute,
|
||||
ApiRoute.addChildren([
|
||||
ApiRoute: ApiRoute.addChildren({
|
||||
ApiAlbumIdRoute,
|
||||
ApiArtistIdRoute,
|
||||
ApiBoxsetIdRoute,
|
||||
@@ -253,9 +329,10 @@ export const routeTree = rootRoute.addChildren([
|
||||
ApiPlayerIndexRoute,
|
||||
ApiSearchIndexRoute,
|
||||
ApiLoginUserIdUserNameRoute,
|
||||
]),
|
||||
}),
|
||||
SetupServerAddRoute,
|
||||
SetupServerErrorRoute,
|
||||
SetupServerListRoute,
|
||||
])
|
||||
})
|
||||
|
||||
/* prettier-ignore-end */
|
||||
+26
-2
@@ -8,6 +8,7 @@ import { LoadingButton } from "@mui/lab";
|
||||
import {
|
||||
Button,
|
||||
Chip,
|
||||
CircularProgress,
|
||||
CssBaseline,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
@@ -24,6 +25,7 @@ import {
|
||||
createRootRoute,
|
||||
createRootRouteWithContext,
|
||||
useNavigate,
|
||||
useRouterState,
|
||||
} from "@tanstack/react-router";
|
||||
import { TanStackRouterDevtools } from "@tanstack/router-devtools";
|
||||
import { relaunch } from "@tauri-apps/api/process";
|
||||
@@ -46,7 +48,6 @@ import "@fontsource-variable/jetbrains-mono";
|
||||
import "@fontsource-variable/noto-sans";
|
||||
|
||||
import "material-symbols/rounded.scss";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||
|
||||
@@ -65,6 +66,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
component: () => {
|
||||
const isQueryFetching = useIsFetching();
|
||||
const isMutating = useIsMutating();
|
||||
const routeIsLoading = useRouterState().isLoading;
|
||||
const [updateDialog, setUpdateDialog] = useState(false);
|
||||
const [updateDialogButton, setUpdateDialogButton] = useState(false);
|
||||
const [updateInfo, setUpdateInfo] = useState<UpdateManifest | undefined>(
|
||||
@@ -107,7 +109,29 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
<CssBaseline />
|
||||
<Settings />
|
||||
<EasterEgg />
|
||||
<NProgress isAnimating={isQueryFetching || isMutating} />
|
||||
<NProgress
|
||||
isAnimating={isQueryFetching || isMutating || routeIsLoading}
|
||||
/>
|
||||
|
||||
{routeIsLoading && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
style={{
|
||||
width: "100vw",
|
||||
height: "100vh",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
background: "rgb(0 0 0 / 0.35)",
|
||||
position: "fixed",
|
||||
zIndex: 10000,
|
||||
}}
|
||||
>
|
||||
<CircularProgress size={72} thickness={2} />
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
<Dialog
|
||||
open={updateDialog}
|
||||
fullWidth
|
||||
|
||||
+24
-1
@@ -4,7 +4,8 @@ import {
|
||||
getServer,
|
||||
} from "@/utils/storage/servers";
|
||||
import { getUser } from "@/utils/storage/user";
|
||||
import { axiosClient } from "@/utils/store/api";
|
||||
import { axiosClient, useApiInContext } 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 { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
@@ -12,6 +13,7 @@ import { Suspense } from "react";
|
||||
|
||||
export const Route = createFileRoute("/_api")({
|
||||
beforeLoad: async ({ context, location }) => {
|
||||
console.log(context.api);
|
||||
if (!context.api) {
|
||||
const currentServerId = await getDefaultServer();
|
||||
if (currentServerId) {
|
||||
@@ -23,6 +25,27 @@ export const Route = createFileRoute("/_api")({
|
||||
context.createApi(currentServer?.address, undefined); // Creates Api
|
||||
}
|
||||
}
|
||||
} else if (context.api) {
|
||||
try {
|
||||
await getSystemApi(context.api).getPingSystem(); // Verify server status
|
||||
} catch (error) {
|
||||
throw redirect({
|
||||
to: "/setup/server/error",
|
||||
search: {
|
||||
redirect: location.href,
|
||||
},
|
||||
});
|
||||
}
|
||||
try {
|
||||
await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate
|
||||
} catch (error) {
|
||||
throw redirect({
|
||||
to: "/login/manual",
|
||||
search: {
|
||||
redirect: location.href,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -25,6 +25,7 @@ import { setBackdrop, useBackdropStore } from "@/utils/store/backdrop";
|
||||
|
||||
import CarouselSlide from "@/components/carouselSlide";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
@@ -115,9 +115,8 @@ function ItemDetail() {
|
||||
queryKey: ["item", id],
|
||||
queryFn: async () => {
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
userId: user.data.Id,
|
||||
userId: user.data?.Id,
|
||||
itemId: id,
|
||||
fields: Object.values(ItemFields),
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
|
||||
@@ -29,3 +29,35 @@
|
||||
flex: 1 1 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.login {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
&-form {
|
||||
width: 28em;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: stretch;
|
||||
gap:1em;
|
||||
&-container{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap:2em;
|
||||
background: rgb(255 255 255 / 0.05);
|
||||
padding: 2em;
|
||||
border-radius: 20px;
|
||||
border: 1px solid rgb(255 255 255 / 0.1);
|
||||
&.padded-top {
|
||||
margin-top: 25vh;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+225
-251
@@ -1,5 +1,5 @@
|
||||
import { queryOptions, useQuery } from "@tanstack/react-query";
|
||||
import React, { useLayoutEffect, useState } from "react";
|
||||
import { queryOptions, useMutation, useQuery } from "@tanstack/react-query";
|
||||
import React, { type FormEvent, useLayoutEffect, useState } from "react";
|
||||
|
||||
import { saveUser } from "@/utils/storage/user.js";
|
||||
|
||||
@@ -9,9 +9,11 @@ import {
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogContentText,
|
||||
FilledInput,
|
||||
Grid,
|
||||
OutlinedInput,
|
||||
Paper,
|
||||
TextField,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
@@ -28,16 +30,21 @@ import InputLabel from "@mui/material/InputLabel";
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
import { AppBarBackOnly } from "@/components/appBar/backOnly.jsx";
|
||||
import { createApi, useApiInContext } from "@/utils/store/api.js";
|
||||
import { 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";
|
||||
import "./login.scss";
|
||||
|
||||
import { queryClient } from "@/main.js";
|
||||
import { setBackdrop } from "@/utils/store/backdrop.js";
|
||||
import { blue } from "@mui/material/colors";
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import {
|
||||
createFileRoute,
|
||||
useNavigate,
|
||||
useRouteContext,
|
||||
useRouter,
|
||||
useRouterState,
|
||||
} from "@tanstack/react-router";
|
||||
import { redirect } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createFileRoute("/_api/login/manual")({
|
||||
@@ -49,7 +56,11 @@ function UserLoginManual() {
|
||||
const [quickConnectLoading, setQuickConnectLoading] = useState(-1);
|
||||
const [quickConnectCode, setQuickConnectCode] = useState("");
|
||||
const [rememberMe, setRememberMe] = useState(true);
|
||||
const api = Route.useRouteContext().api;
|
||||
// console.log(Route.useRouteContext());
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const createApi = useApiInContext((s) => s.createApi);
|
||||
const router = useRouter();
|
||||
const searchParams = Route.useSearch();
|
||||
|
||||
const server = useQuery({
|
||||
queryKey: ["login", "manual", "serverInfo"],
|
||||
@@ -61,14 +72,14 @@ function UserLoginManual() {
|
||||
const navigate = useNavigate();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const [password, setPassword] = useState({
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState<{
|
||||
password: string | undefined;
|
||||
showpass: boolean;
|
||||
}>({
|
||||
showpass: false,
|
||||
password: "",
|
||||
});
|
||||
const [userName, setUserName] = useState("");
|
||||
|
||||
const handleUsername = (event) => {
|
||||
setUserName(event.target.value);
|
||||
};
|
||||
|
||||
const handlePassword = (prop) => (event) => {
|
||||
setPassword({
|
||||
@@ -84,33 +95,34 @@ function UserLoginManual() {
|
||||
});
|
||||
};
|
||||
|
||||
const authUser = async () => {
|
||||
const handleLoginFn = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
try {
|
||||
const auth = await api.authenticateUserByName(
|
||||
userName,
|
||||
const authenticate = await api.authenticateUserByName(
|
||||
username,
|
||||
password.password,
|
||||
);
|
||||
return auth;
|
||||
} catch (error) {
|
||||
enqueueSnackbar("Incorrect Username or Password!", {
|
||||
variant: "error",
|
||||
createApi(api.basePath, authenticate.data?.AccessToken);
|
||||
|
||||
if (rememberMe) await saveUser(username, authenticate.data.AccessToken);
|
||||
|
||||
router.invalidate().finally(() => {
|
||||
navigate({ to: searchParams.redirect || "/home", replace: true });
|
||||
});
|
||||
setLoading(false);
|
||||
console.error(error);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
enqueueSnackbar(
|
||||
"Unable to authenticate. Please check your username and password",
|
||||
{ variant: "error" },
|
||||
);
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
const handleLogin = async () => {
|
||||
setLoading(true);
|
||||
const user = await authUser();
|
||||
sessionStorage.setItem("accessToken", user.data.AccessToken);
|
||||
createApi(api.basePath, user.data.AccessToken);
|
||||
if (rememberMe === true) {
|
||||
await saveUser(userName, user.data.AccessToken);
|
||||
}
|
||||
setLoading(false);
|
||||
navigate("/home");
|
||||
};
|
||||
const handleLogin = useMutation({
|
||||
mutationKey: ["login", "authenticate"],
|
||||
mutationFn: handleLoginFn,
|
||||
});
|
||||
|
||||
const handleCheckRememberMe = (event) => {
|
||||
setRememberMe(event.target.checked);
|
||||
@@ -211,238 +223,200 @@ function UserLoginManual() {
|
||||
return (
|
||||
<>
|
||||
<AppBarBackOnly />
|
||||
<Container
|
||||
maxWidth="xs"
|
||||
sx={{
|
||||
height: "100vh",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Grid
|
||||
container
|
||||
spacing={2}
|
||||
direction="column"
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
sx={{
|
||||
transition: "opacity 200ms",
|
||||
width: "100%",
|
||||
}}
|
||||
<div className="login scrollY">
|
||||
<div
|
||||
className={`login-form-container ${
|
||||
server.data?.LoginDisclaimer && "padded-top"
|
||||
}`}
|
||||
>
|
||||
<Grid sx={{ marginBottom: "1em" }}>
|
||||
<Typography variant="h3" color="textPrimary">
|
||||
Login
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid sx={{ width: "100%", mb: 1 }}>
|
||||
<Typography variant="h3" color="textPrimary">
|
||||
Login
|
||||
</Typography>
|
||||
<form className="login-form" onSubmit={(e) => handleLogin.mutate(e)}>
|
||||
<TextField
|
||||
variant="outlined"
|
||||
label="Username"
|
||||
onChange={(e) => setUsername(e.currentTarget.value)}
|
||||
/>
|
||||
<FormControl sx={{ width: "100%" }} variant="outlined">
|
||||
<InputLabel htmlFor="user-name">Username:</InputLabel>
|
||||
<InputLabel htmlFor="user-password">Password:</InputLabel>
|
||||
<OutlinedInput
|
||||
fullWidth
|
||||
id="user-name"
|
||||
type="text"
|
||||
variant="outlined"
|
||||
label="Username:"
|
||||
onChange={handleUsername}
|
||||
id="user-password"
|
||||
type={password.showpass ? "text" : "password"}
|
||||
onChange={handlePassword("password")}
|
||||
label="Password:"
|
||||
endAdornment={
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
onClick={handleShowPassword}
|
||||
aria-label="toggle password visibility"
|
||||
>
|
||||
{password.showpass ? (
|
||||
<span className="material-symbols-rounded">
|
||||
visibility
|
||||
</span>
|
||||
) : (
|
||||
<span className="material-symbols-rounded">
|
||||
visibility_off
|
||||
</span>
|
||||
)}
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
</Grid>
|
||||
<Grid sx={{ width: "100%" }}>
|
||||
<FormGroup>
|
||||
<FormControl sx={{ width: "100%" }} variant="outlined">
|
||||
<InputLabel htmlFor="user-password">Password:</InputLabel>
|
||||
<OutlinedInput
|
||||
fullWidth
|
||||
id="user-password"
|
||||
type={password.showpass ? "text" : "password"}
|
||||
variant="outlined"
|
||||
onChange={handlePassword("password")}
|
||||
onKeyUp={(event) => {
|
||||
if (event.key === "Enter") {
|
||||
handleLogin();
|
||||
}
|
||||
}}
|
||||
label="Password:"
|
||||
endAdornment={
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
onClick={handleShowPassword}
|
||||
aria-label="toggle password visibility"
|
||||
>
|
||||
{password.showpass ? (
|
||||
<span className="material-symbols-rounded">
|
||||
visibility
|
||||
</span>
|
||||
) : (
|
||||
<span className="material-symbols-rounded">
|
||||
visibility_off
|
||||
</span>
|
||||
)}
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
}
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={rememberMe}
|
||||
onChange={handleCheckRememberMe}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={rememberMe}
|
||||
onChange={handleCheckRememberMe}
|
||||
/>
|
||||
}
|
||||
label="Remember me"
|
||||
/>
|
||||
</FormGroup>
|
||||
</Grid>
|
||||
<div
|
||||
className="flex flex-column"
|
||||
style={{ width: "100%", gap: "0.4em" }}
|
||||
>
|
||||
<LoadingButton
|
||||
variant="contained"
|
||||
endIcon={
|
||||
<span className="material-symbols-rounded">chevron_right</span>
|
||||
}
|
||||
onClick={handleLogin}
|
||||
loading={loading}
|
||||
loadingPosition="end"
|
||||
size="large"
|
||||
sx={{ width: "100%" }}
|
||||
>
|
||||
Login
|
||||
</LoadingButton>
|
||||
<LoadingButton
|
||||
onClick={handleQuickConnect}
|
||||
variant="contained"
|
||||
className="userEventButton"
|
||||
sx={{ width: "100%" }}
|
||||
loading={quickConnectLoading === 1}
|
||||
// size="large"
|
||||
>
|
||||
Quick Connect
|
||||
</LoadingButton>
|
||||
<Button
|
||||
color="secondary"
|
||||
variant="contained"
|
||||
className="userEventButton"
|
||||
// size="large"
|
||||
sx={{ width: "100%" }}
|
||||
onClick={() => navigate("/servers/list")}
|
||||
>
|
||||
Change Server
|
||||
</Button>
|
||||
</div>
|
||||
<Dialog open={Boolean(quickConnectCode)} fullWidth maxWidth="xs">
|
||||
<DialogContent
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="h5"
|
||||
mb={2}
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
Quick Connect Code:
|
||||
</Typography>
|
||||
<DialogContentText>
|
||||
Use this code in the Quick Connect tab in your server to login.
|
||||
</DialogContentText>
|
||||
<div
|
||||
className="flex flex-row"
|
||||
style={{ gap: "1em", alignItems: "center", marginTop: "1em" }}
|
||||
>
|
||||
<Tooltip title="Click to copy" arrow placement="top">
|
||||
<Typography
|
||||
variant="h3"
|
||||
color="textPrimary"
|
||||
textAlign="center"
|
||||
sx={{
|
||||
background: "rgb(255 255 255 / 0.1)",
|
||||
width: "fit-content",
|
||||
padding: "0.4em",
|
||||
borderRadius: "10px",
|
||||
cursor: "pointer",
|
||||
}}
|
||||
onClick={(e) => {
|
||||
navigator.clipboard.writeText(quickConnectCode);
|
||||
enqueueSnackbar("Quick Connect Code copied!", {
|
||||
variant: "info",
|
||||
key: "copiedText",
|
||||
});
|
||||
}}
|
||||
>
|
||||
{quickConnectCode}
|
||||
</Typography>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions
|
||||
label="Remember me"
|
||||
/>
|
||||
<div
|
||||
className="flex flex-row"
|
||||
sx={{
|
||||
padding: "0em 1em 1em 1em",
|
||||
justifyContent: "space-between",
|
||||
style={{ width: "100%", gap: "0.8em", flexWrap: "wrap" }}
|
||||
>
|
||||
<LoadingButton
|
||||
variant="contained"
|
||||
type="submit"
|
||||
loading={handleLogin.isPending}
|
||||
sx={{ width: "100%" }}
|
||||
>
|
||||
Login
|
||||
</LoadingButton>
|
||||
<LoadingButton
|
||||
onClick={handleQuickConnect}
|
||||
variant="contained"
|
||||
className="userEventButton"
|
||||
style={{ flex: 1 }}
|
||||
loading={quickConnectLoading === 1}
|
||||
// size="large"
|
||||
>
|
||||
Quick Connect
|
||||
</LoadingButton>
|
||||
<Button
|
||||
color="secondary"
|
||||
variant="contained"
|
||||
className="userEventButton"
|
||||
// size="large"
|
||||
style={{ flex: 1 }}
|
||||
onClick={() => navigate("/servers/list")}
|
||||
>
|
||||
Change Server
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{server.isSuccess && server.data.LoginDisclaimer && (
|
||||
<Paper
|
||||
elevation={5}
|
||||
style={{
|
||||
marginTop: "1em",
|
||||
padding: "1em",
|
||||
borderRadius: "15px",
|
||||
width: "32em",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="flex flex-row flex-align-center"
|
||||
style={{ gap: "0.5em", marginBottom: "0.5em" }}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
color: blue[700],
|
||||
"--fill": 1,
|
||||
}}
|
||||
>
|
||||
info
|
||||
</span>
|
||||
Notice
|
||||
</div>
|
||||
<Typography variant="subtitle2" style={{ opacity: 0.8 }}>
|
||||
{server.data.LoginDisclaimer}
|
||||
</Typography>
|
||||
</Paper>
|
||||
)}
|
||||
<Dialog open={Boolean(quickConnectCode)} fullWidth maxWidth="xs">
|
||||
<DialogContent
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="h5"
|
||||
mb={2}
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={rememberMe}
|
||||
onChange={handleCheckRememberMe}
|
||||
/>
|
||||
}
|
||||
label="Remember device"
|
||||
/>
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={() => {
|
||||
setQuickConnectCode("");
|
||||
setQuickConnectLoading(-1);
|
||||
}}
|
||||
>
|
||||
Close
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
<Grid sx={{ width: "100%" }}>
|
||||
{server.isSuccess && server.data.LoginDisclaimer && (
|
||||
<Paper
|
||||
elevation={5}
|
||||
style={{
|
||||
marginTop: "1em",
|
||||
padding: "1em",
|
||||
borderRadius: "15px",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="flex flex-row flex-align-center"
|
||||
style={{ gap: "0.5em", marginBottom: "0.5em" }}
|
||||
Quick Connect Code:
|
||||
</Typography>
|
||||
<DialogContentText>
|
||||
Use this code in the Quick Connect tab in your server to login.
|
||||
</DialogContentText>
|
||||
<div
|
||||
className="flex flex-row"
|
||||
style={{ gap: "1em", alignItems: "center", marginTop: "1em" }}
|
||||
>
|
||||
<Tooltip title="Click to copy" arrow placement="top">
|
||||
<Typography
|
||||
variant="h3"
|
||||
color="textPrimary"
|
||||
textAlign="center"
|
||||
sx={{
|
||||
background: "rgb(255 255 255 / 0.1)",
|
||||
width: "fit-content",
|
||||
padding: "0.4em",
|
||||
borderRadius: "10px",
|
||||
cursor: "pointer",
|
||||
}}
|
||||
onClick={(e) => {
|
||||
navigator.clipboard.writeText(quickConnectCode);
|
||||
enqueueSnackbar("Quick Connect Code copied!", {
|
||||
variant: "info",
|
||||
key: "copiedText",
|
||||
});
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
color: blue[700],
|
||||
"--fill": 1,
|
||||
}}
|
||||
>
|
||||
info
|
||||
</span>
|
||||
Notice
|
||||
</div>
|
||||
<Typography variant="subtitle2" style={{ opacity: 0.8 }}>
|
||||
{server.data.LoginDisclaimer}
|
||||
{quickConnectCode}
|
||||
</Typography>
|
||||
</Paper>
|
||||
)}
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Container>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions
|
||||
className="flex flex-row"
|
||||
sx={{
|
||||
padding: "0em 1em 1em 1em",
|
||||
justifyContent: "space-between",
|
||||
}}
|
||||
>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={rememberMe}
|
||||
onChange={handleCheckRememberMe}
|
||||
/>
|
||||
}
|
||||
label="Remember device"
|
||||
/>
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={() => {
|
||||
setQuickConnectCode("");
|
||||
setQuickConnectLoading(-1);
|
||||
}}
|
||||
>
|
||||
Close
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
+141
-143
@@ -59,7 +59,7 @@ import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
|
||||
import IconLink from "@/components/iconLink";
|
||||
import EpisodeSkeleton from "@/components/skeleton/episode";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import { Link } from "@tanstack/react-router";
|
||||
|
||||
function TabPanel(props) {
|
||||
@@ -963,155 +963,153 @@ function SeriesTitlePage() {
|
||||
) : (
|
||||
episodes.data.Items.map((episode, index) => {
|
||||
return (
|
||||
<>
|
||||
<motion.div
|
||||
key={episode.Id}
|
||||
onClick={() => navigate(`/episode/${episode.Id}`)}
|
||||
initial={{
|
||||
transform: "translateY(10px)",
|
||||
opacity: 0,
|
||||
}}
|
||||
whileInView={{
|
||||
opacity: 1,
|
||||
transform: "translateY(0px)",
|
||||
}}
|
||||
viewport={{
|
||||
once: true,
|
||||
}}
|
||||
transition={{
|
||||
duration: 0.2,
|
||||
ease: "backInOut",
|
||||
}}
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
className="item-detail-episode"
|
||||
<motion.div
|
||||
key={episode.Id}
|
||||
onClick={() => navigate(`/episode/${episode.Id}`)}
|
||||
initial={{
|
||||
transform: "translateY(10px)",
|
||||
opacity: 0,
|
||||
}}
|
||||
whileInView={{
|
||||
opacity: 1,
|
||||
transform: "translateY(0px)",
|
||||
}}
|
||||
viewport={{
|
||||
once: true,
|
||||
}}
|
||||
transition={{
|
||||
duration: 0.2,
|
||||
ease: "backInOut",
|
||||
}}
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
className="item-detail-episode"
|
||||
>
|
||||
<Typography variant="subtitle1" textAlign="center">
|
||||
{episode.IndexNumberEnd
|
||||
? `${episode.IndexNumber} / ${episode.IndexNumberEnd}`
|
||||
: episode.IndexNumber ?? 0}
|
||||
</Typography>
|
||||
<div
|
||||
className={
|
||||
episode.UserData?.Played
|
||||
? "item-detail-episode-image-container watched"
|
||||
: "item-detail-episode-image-container"
|
||||
}
|
||||
>
|
||||
<Typography variant="subtitle1" textAlign="center">
|
||||
{episode.IndexNumberEnd
|
||||
? `${episode.IndexNumber} / ${episode.IndexNumberEnd}`
|
||||
: episode.IndexNumber ?? 0}
|
||||
</Typography>
|
||||
<div
|
||||
className={
|
||||
episode.UserData?.Played
|
||||
? "item-detail-episode-image-container watched"
|
||||
: "item-detail-episode-image-container"
|
||||
}
|
||||
>
|
||||
<div className="item-detail-episode-image-overlay">
|
||||
<PlayButton
|
||||
item={episode}
|
||||
itemId={episode.Id}
|
||||
itemType="Episode"
|
||||
itemUserData={episode.UserData}
|
||||
userId={user.data.Id}
|
||||
currentAudioTrack={0}
|
||||
currentVideoTrack={0}
|
||||
currentSubTrack={0}
|
||||
size="medium"
|
||||
buttonProps={{
|
||||
color: "white",
|
||||
style: {
|
||||
color: "black ",
|
||||
},
|
||||
<div className="item-detail-episode-image-overlay">
|
||||
<PlayButton
|
||||
item={episode}
|
||||
itemId={episode.Id}
|
||||
itemType="Episode"
|
||||
itemUserData={episode.UserData}
|
||||
userId={user.data.Id}
|
||||
currentAudioTrack={0}
|
||||
currentVideoTrack={0}
|
||||
currentSubTrack={0}
|
||||
size="medium"
|
||||
buttonProps={{
|
||||
color: "white",
|
||||
style: {
|
||||
color: "black ",
|
||||
},
|
||||
}}
|
||||
iconOnly
|
||||
/>
|
||||
</div>
|
||||
<div className="item-detail-episode-image-icon-container">
|
||||
<span className="material-symbols-rounded item-detail-episode-image-icon">
|
||||
tv_gen
|
||||
</span>
|
||||
</div>
|
||||
<img
|
||||
alt={episode.Name}
|
||||
src={api.getItemImageUrl(episode.Id, "Primary", {
|
||||
tag: episode.ImageTags.Primary,
|
||||
fillHeight: 300,
|
||||
})}
|
||||
className="item-detail-episode-image"
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
}}
|
||||
/>
|
||||
{episode.UserData?.PlaybackPositionTicks > 0 && (
|
||||
<div className="card-progress-container">
|
||||
<div
|
||||
className="card-progress"
|
||||
style={{
|
||||
width: `${episode.UserData?.PlayedPercentage}%`,
|
||||
}}
|
||||
iconOnly
|
||||
/>
|
||||
</div>
|
||||
<div className="item-detail-episode-image-icon-container">
|
||||
<span className="material-symbols-rounded item-detail-episode-image-icon">
|
||||
tv_gen
|
||||
</span>
|
||||
</div>
|
||||
<img
|
||||
alt={episode.Name}
|
||||
src={api.getItemImageUrl(episode.Id, "Primary", {
|
||||
tag: episode.ImageTags.Primary,
|
||||
fillHeight: 300,
|
||||
})}
|
||||
className="item-detail-episode-image"
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
}}
|
||||
/>
|
||||
{episode.UserData?.PlaybackPositionTicks > 0 && (
|
||||
<div className="card-progress-container">
|
||||
<div
|
||||
className="card-progress"
|
||||
style={{
|
||||
width: `${episode.UserData?.PlayedPercentage}%`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="item-detail-episode-info">
|
||||
<Typography variant="subtitle1">
|
||||
{episode.Name}
|
||||
</Typography>
|
||||
<div
|
||||
className="flex flex-row flex-align-center"
|
||||
style={{
|
||||
gap: "0.5em",
|
||||
}}
|
||||
>
|
||||
{episode.PremiereDate && (
|
||||
<Chip
|
||||
variant="filled"
|
||||
label={getEpisodeDateString(
|
||||
new Date(episode.PremiereDate),
|
||||
)}
|
||||
size="small"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="item-detail-episode-info">
|
||||
<Typography variant="subtitle1">
|
||||
{episode.Name}
|
||||
</Typography>
|
||||
<div
|
||||
className="flex flex-row flex-align-center"
|
||||
style={{
|
||||
gap: "0.5em",
|
||||
}}
|
||||
>
|
||||
{episode.PremiereDate && (
|
||||
<Chip
|
||||
variant="filled"
|
||||
label={getEpisodeDateString(
|
||||
new Date(episode.PremiereDate),
|
||||
)}
|
||||
size="small"
|
||||
/>
|
||||
)}
|
||||
<Typography variant="caption">
|
||||
{getRuntimeCompact(episode.RunTimeTicks)}
|
||||
</Typography>
|
||||
</div>
|
||||
<Typography
|
||||
variant="caption"
|
||||
style={{
|
||||
display: "-webkit-box",
|
||||
textOverflow: "ellipsis",
|
||||
overflow: "hidden",
|
||||
WebkitLineClamp: 2,
|
||||
WebkitBoxOrient: "vertical",
|
||||
width: "100%",
|
||||
opacity: 0.7,
|
||||
}}
|
||||
>
|
||||
{episode.Overview}
|
||||
<Typography variant="caption">
|
||||
{getRuntimeCompact(episode.RunTimeTicks)}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-detail-episode-buttons">
|
||||
<LikeButton
|
||||
itemId={episode.Id}
|
||||
itemName={episode.Name}
|
||||
isFavorite={episode.UserData?.IsFavorite}
|
||||
queryKey={[
|
||||
"item",
|
||||
id,
|
||||
`season ${currentSeason + 1}`,
|
||||
"episodes",
|
||||
]}
|
||||
userId={user.data.Id}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemId={episode.Id}
|
||||
itemName={episode.Name}
|
||||
isPlayed={episode.UserData?.Played}
|
||||
queryKey={[
|
||||
"item",
|
||||
id,
|
||||
`season ${currentSeason + 1}`,
|
||||
"episodes",
|
||||
]}
|
||||
userId={user.data.Id}
|
||||
/>
|
||||
</div>
|
||||
</motion.div>
|
||||
</>
|
||||
<Typography
|
||||
variant="caption"
|
||||
style={{
|
||||
display: "-webkit-box",
|
||||
textOverflow: "ellipsis",
|
||||
overflow: "hidden",
|
||||
WebkitLineClamp: 2,
|
||||
WebkitBoxOrient: "vertical",
|
||||
width: "100%",
|
||||
opacity: 0.7,
|
||||
}}
|
||||
>
|
||||
{episode.Overview}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-detail-episode-buttons">
|
||||
<LikeButton
|
||||
itemId={episode.Id}
|
||||
itemName={episode.Name}
|
||||
isFavorite={episode.UserData?.IsFavorite}
|
||||
queryKey={[
|
||||
"item",
|
||||
id,
|
||||
`season ${currentSeason + 1}`,
|
||||
"episodes",
|
||||
]}
|
||||
userId={user.data.Id}
|
||||
/>
|
||||
<MarkPlayedButton
|
||||
itemId={episode.Id}
|
||||
itemName={episode.Name}
|
||||
isPlayed={episode.UserData?.Played}
|
||||
queryKey={[
|
||||
"item",
|
||||
id,
|
||||
`season ${currentSeason + 1}`,
|
||||
"episodes",
|
||||
]}
|
||||
userId={user.data.Id}
|
||||
/>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
})
|
||||
)}
|
||||
|
||||
+15
-67
@@ -15,7 +15,12 @@ import {
|
||||
CircularProgress,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { Outlet, createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import {
|
||||
Outlet,
|
||||
createFileRoute,
|
||||
redirect,
|
||||
useNavigate,
|
||||
} from "@tanstack/react-router";
|
||||
import axios from "axios";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import * as React from "react";
|
||||
@@ -29,79 +34,22 @@ type LoaderData = {
|
||||
};
|
||||
|
||||
export const Route = createFileRoute("/")({
|
||||
component: Index,
|
||||
errorComponent: (error) => {
|
||||
console.error(error.error);
|
||||
},
|
||||
beforeLoad: async ({ context, navigate }) => {
|
||||
const api = context.api;
|
||||
const serversOnDisk = await getAllServers();
|
||||
const currentServerId = await getDefaultServer();
|
||||
const currentServer = await getServer(currentServerId);
|
||||
const userOnDisk = await getUser();
|
||||
const createApi = context.createApi;
|
||||
|
||||
if (serversOnDisk.length > 0) {
|
||||
if (currentServer) {
|
||||
// setStatus(
|
||||
// `Server found!
|
||||
// Checking server status...`,
|
||||
// );
|
||||
// setIsError(false);
|
||||
const pingServer = async () => {
|
||||
const result = (
|
||||
await axios.get(`${currentServer.address}/System/Ping`)
|
||||
).data;
|
||||
return result === "Jellyfin Server";
|
||||
};
|
||||
pingServer()
|
||||
.then(async (isOnline) => {
|
||||
if (isOnline) {
|
||||
// setStatus("Server online!");
|
||||
// setIsError(false);
|
||||
|
||||
createApi(currentServer.address, undefined);
|
||||
|
||||
if (userOnDisk) {
|
||||
// setStatus(
|
||||
// `User found!
|
||||
// Trying to authenticate user...`,
|
||||
// );
|
||||
|
||||
createApi(currentServer.address, userOnDisk.AccessToken);
|
||||
|
||||
// const api = useApiInContext((s) => s.api);
|
||||
try {
|
||||
console.log();
|
||||
await getUserApi(api).getCurrentUser();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
// setStatus("Unable to authenticate.");
|
||||
// setIsError(true);
|
||||
// setIsAuthError(true);
|
||||
}
|
||||
} else {
|
||||
navigate({ to: "/login" });
|
||||
}
|
||||
} else {
|
||||
// setStatus("Unable to reach server");
|
||||
// setIsError(false);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
// setStatus("Unable to reach server");
|
||||
// setIsError(true);
|
||||
console.error(error);
|
||||
});
|
||||
} else {
|
||||
// setStatus("No server found.");
|
||||
// setIsError(false);
|
||||
navigate({ to: "/setup/server/list" });
|
||||
if (currentServerId) {
|
||||
context.createApi(currentServer?.address, undefined);
|
||||
if (userOnDisk) {
|
||||
context.createApi(currentServer?.address, userOnDisk.AccessToken);
|
||||
throw redirect({ to: "/home/" });
|
||||
}
|
||||
throw redirect({ to: "/login/" });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function Index() {
|
||||
return <h1>Loading...</h1>;
|
||||
}
|
||||
throw redirect({ to: "/setup/server/add" });
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
|
||||
export const Route = createFileRoute("/setup/server/error")({
|
||||
component: () => <div>Hello /setup/server/error!</div>,
|
||||
});
|
||||
+8
-16
@@ -1,5 +1,5 @@
|
||||
import { type Api, Jellyfin } from "@jellyfin/sdk";
|
||||
import React, { createContext, useContext, useRef } from "react";
|
||||
import React, { createContext, useContext, useRef, useState } from "react";
|
||||
import { type StoreApi, createStore, useStore } from "zustand";
|
||||
import { version as appVer } from "../../../package.json";
|
||||
|
||||
@@ -55,27 +55,19 @@ export const jellyfin = new Jellyfin({
|
||||
const ApiContext = createContext(null);
|
||||
|
||||
export const ApiProvider = ({ children }) => {
|
||||
const storeRef = useRef<StoreApi<ApiStore>>();
|
||||
|
||||
if (!storeRef.current) {
|
||||
storeRef.current = createStore<ApiStore>()((set) => ({
|
||||
const [store] = useState(() =>
|
||||
createStore<ApiStore>()((set) => ({
|
||||
api: undefined,
|
||||
deviceId: deviceId,
|
||||
jellyfin: jellyfin,
|
||||
createApi: async (serverAddress, accessToken?) => {
|
||||
createApi: (serverAddress, accessToken?) =>
|
||||
set((state) => ({
|
||||
...state,
|
||||
api: jellyfin.createApi(serverAddress, accessToken, axiosClient),
|
||||
}));
|
||||
await Promise.resolve();
|
||||
},
|
||||
}));
|
||||
}
|
||||
return (
|
||||
<ApiContext.Provider value={storeRef.current}>
|
||||
{children}
|
||||
</ApiContext.Provider>
|
||||
);
|
||||
})),
|
||||
})),
|
||||
)
|
||||
return <ApiContext.Provider value={store}>{children}</ApiContext.Provider>;
|
||||
};
|
||||
|
||||
export function useApiInContext<T>(selector?: (state: ApiStore) => T) {
|
||||
|
||||
Reference in new issue
Block a user