diff --git a/src/components/loginShell/index.tsx b/src/components/loginShell/index.tsx new file mode 100644 index 0000000..c2b40d6 --- /dev/null +++ b/src/components/loginShell/index.tsx @@ -0,0 +1,88 @@ +import { getBrandingApi } from "@jellyfin/sdk/lib/utils/api/branding-api"; +import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api"; +import { useQuery } from "@tanstack/react-query"; +import { Link } from "@tanstack/react-router"; +import React, { type ReactNode, useEffect } from "react"; +import { useApiInContext } from "@/utils/store/api"; +import { useBackdropStore } from "@/utils/store/backdrop"; + +import "./loginShell.scss"; + +type LoginShellProps = { + title: ReactNode; + subtitle?: ReactNode; + /** Max width of the content column. */ + width?: "narrow" | "wide"; + children: ReactNode; + footer?: ReactNode; +}; + +/** Shared full-screen layout for the sign-in pages. */ +const LoginShell = ({ + title, + subtitle, + width = "narrow", + children, + footer, +}: LoginShellProps) => { + const api = useApiInContext((s) => s.api); + + const serverInfo = useQuery({ + queryKey: ["login", "serverInfo"], + queryFn: async () => + api ? (await getSystemApi(api).getPublicSystemInfo()).data : null, + enabled: Boolean(api), + staleTime: 5 * 60_000, + }); + const branding = useQuery({ + queryKey: ["login", "branding"], + queryFn: async () => + api ? (await getBrandingApi(api).getBrandingOptions()).data : null, + enabled: Boolean(api), + staleTime: 5 * 60_000, + }); + + const setBackdrop = useBackdropStore((s) => s.setBackdrop); + useEffect(() => { + setBackdrop(""); + }, [setBackdrop]); + + const serverName = serverInfo.data?.ServerName; + const serverHost = api?.basePath.replace(/^https?:\/\//, ""); + + return ( +
{subtitle}
} ++ Couldn't load profiles from this server. Use "Other user" to sign in + with your username. +
+ )} + + ); } diff --git a/src/routes/_api/login/login.scss b/src/routes/_api/login/login.scss deleted file mode 100644 index 43468aa..0000000 --- a/src/routes/_api/login/login.scss +++ /dev/null @@ -1,90 +0,0 @@ - -.user { - &-list { - &-container { - display: flex; - flex-flow: row wrap; - gap: 1em; - justify-content: center; - align-items: center; - height: 30em; - overflow-y: auto; - overflow-x: hidden; - scroll-snap-type: y mandatory; - margin: 2em 0; - } - } - &-card { - width: fit-content; - scroll-snap-align: start; - text-decoration: none !important; - color: white !important; - &-image{ - width: 100%; - height: 100%; - object-fit: cover; - &-container{ - aspect-ratio: 1; - width: 8em; - overflow: hidden; - border-radius: 100%; - } - } - } - &Icon { - font-size: 5em; - display: flex; - justify-content: center; - align-items: center; - background: $clr-accent-dark; - } -} - -.buttons { - display: flex; - gap: 1em; - width: 100%; - >* { - flex: 1 1 0 !important; - } -} - -.login { - // width: 50em; - height: 100vh; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - - &-container{ - width: 100vw; - height: 100vh; - margin: auto; - padding-top: 4em; - padding-bottom: 4em; - } - - &-form { - width: 24em; - 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; - } - } - } -} \ No newline at end of file diff --git a/src/routes/_api/login/manual.tsx b/src/routes/_api/login/manual.tsx index 527c04e..b1e65f7 100644 --- a/src/routes/_api/login/manual.tsx +++ b/src/routes/_api/login/manual.tsx @@ -1,31 +1,20 @@ -import { getBrandingApi } from "@jellyfin/sdk/lib/utils/api/branding-api"; -import LoadingButton from "@mui/lab/LoadingButton"; -import { Paper, TextField, Typography } from "@mui/material"; import Button from "@mui/material/Button"; import Checkbox from "@mui/material/Checkbox"; import FormControlLabel from "@mui/material/FormControlLabel"; import IconButton from "@mui/material/IconButton"; import InputAdornment from "@mui/material/InputAdornment"; -import { useMutation, useQuery } from "@tanstack/react-query"; -import { useSnackbar } from "notistack"; -import React, { - type ChangeEvent, - type FormEvent, - useEffect, - useState, -} from "react"; -import { saveUser } from "@/utils/storage/user.js"; -import { useApiInContext } from "@/utils/store/api.js"; -import "./login.scss"; - -import { blue } from "@mui/material/colors"; +import TextField from "@mui/material/TextField"; +import { useMutation } from "@tanstack/react-query"; import { createFileRoute, + Link, useNavigate, useRouter, } from "@tanstack/react-router"; -import { useShallow } from "zustand/shallow"; -import { useBackdropStore } from "@/utils/store/backdrop.js"; +import React, { type FormEvent, useState } from "react"; +import LoginShell from "@/components/loginShell"; +import { saveUser } from "@/utils/storage/user"; +import { useApiInContext } from "@/utils/store/api"; export const Route = createFileRoute("/_api/login/manual")({ component: UserLoginManual, @@ -35,284 +24,142 @@ export const Route = createFileRoute("/_api/login/manual")({ }); function UserLoginManual() { - const [rememberMe, setRememberMe] = useState(true); - // console.log(Route.useRouteContext()); const api = useApiInContext((s) => s.api); const createApi = useApiInContext((s) => s.createApi); const router = useRouter(); + const navigate = useNavigate(); const searchParams = Route.useSearch(); - const server = useQuery({ - queryKey: ["login", "manual", "serverInfo"], - queryFn: async () => - api ? (await getBrandingApi(api).getBrandingOptions()).data : null, - }); - - const navigate = useNavigate(); - const { enqueueSnackbar } = useSnackbar(); - const [username, setUsername] = useState(""); - const [password, setPassword] = useState<{ - password: string | undefined; - showpass: boolean; - }>({ - showpass: false, - password: "", - }); + const [password, setPassword] = useState(""); + const [showPassword, setShowPassword] = useState(false); + const [rememberMe, setRememberMe] = useState(true); + const [error, setError] = useState