refactor: change UI of login/list and fix Api not being defined in context
This commit is contained in:
13 files changed
+243
-171
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { CircularProgress, Typography } from "@mui/material";
|
||||
import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
|
||||
export const Route = createFileRoute("/_api/login")({
|
||||
beforeLoad: async ({ context, location }) => {
|
||||
@@ -7,13 +9,26 @@ export const Route = createFileRoute("/_api/login")({
|
||||
const api = context.api;
|
||||
if (!api) {
|
||||
console.info("Awaiting Api generation.");
|
||||
// throw redirect({ to: "/login/manual" });
|
||||
} else {
|
||||
const publicUsers = (await getUserApi(api).getPublicUsers()).data;
|
||||
if (publicUsers.length > 0) {
|
||||
throw redirect({ to: "/login/list" });
|
||||
}
|
||||
throw redirect({ to: "/login/manual" });
|
||||
}
|
||||
const publicUsers = (await getUserApi(api).getPublicUsers()).data;
|
||||
if (publicUsers.length > 0) {
|
||||
throw redirect({ to: "/login/list" });
|
||||
}
|
||||
throw redirect({ to: "/login/manual" });
|
||||
}
|
||||
},
|
||||
// component: () => {
|
||||
// const data = Route.useRouteContext();
|
||||
// console.log(data);
|
||||
// return (
|
||||
// <div style={{ height: "100vh" }} className="flex flex-column flex-center">
|
||||
// <CircularProgress size={86} thickness={2} />
|
||||
// <Typography mt={4} align="center">
|
||||
// Fetching users...
|
||||
// </Typography>
|
||||
// </div>
|
||||
// );
|
||||
// },
|
||||
});
|
||||
@@ -1,12 +1,10 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import React, { useLayoutEffect } from "react";
|
||||
|
||||
import { Grid, Typography } from "@mui/material";
|
||||
import { Chip, IconButton, Typography } from "@mui/material";
|
||||
import Button from "@mui/material/Button";
|
||||
import Container from "@mui/material/Container";
|
||||
|
||||
import { AppBarBackOnly } from "@/components/appBar/backOnly.jsx";
|
||||
import { Card } from "@/components/card/card.js";
|
||||
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
|
||||
@@ -15,13 +13,42 @@ import "./login.scss";
|
||||
|
||||
import QuickConnectButton from "@/components/buttons/quickConnectButton";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { setBackdrop } from "@/utils/store/backdrop.js";
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop.js";
|
||||
import type { UserDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { Link, createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
|
||||
import avatar from "../../../assets/icons/avatar.png";
|
||||
|
||||
export const Route = createFileRoute("/_api/login/list")({
|
||||
component: LoginPublicUsersList,
|
||||
});
|
||||
|
||||
const UserCard = ({ user }: { user: UserDto }) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
return (
|
||||
<Link
|
||||
to="/login/$userId/$userName"
|
||||
params={{ userId: user.Id ?? "", userName: user.Name ?? "" }}
|
||||
className="user-list-item user-card"
|
||||
>
|
||||
<div className="user-card-image-container">
|
||||
{user.PrimaryImageTag ? (
|
||||
<img
|
||||
className="user-card-image"
|
||||
alt={"user"}
|
||||
src={`${api.basePath}/Users/${user.Id}/Images/Primary?quality=80&tag=${user.PrimaryImageTag}`}
|
||||
/>
|
||||
) : (
|
||||
<img className="user-card-image" alt="user" src={avatar} />
|
||||
)}
|
||||
</div>
|
||||
<Typography mt={1} align="center">
|
||||
{user.Name}
|
||||
</Typography>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
function LoginPublicUsersList() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -30,18 +57,18 @@ function LoginPublicUsersList() {
|
||||
const handleChangeServer = () => {
|
||||
navigate({ to: "/setup/server/list" });
|
||||
};
|
||||
const handleManualLogin = () => {
|
||||
navigate({ to: "/login/manual" });
|
||||
};
|
||||
const users = useQuery({
|
||||
queryKey: ["login", "public-users"],
|
||||
queryFn: async () => {
|
||||
if (!api) return [];
|
||||
const result = await getUserApi(api).getPublicUsers();
|
||||
return result.data;
|
||||
},
|
||||
enabled: Boolean(api),
|
||||
});
|
||||
|
||||
const setBackdrop = useBackdropStore((state) => state.setBackdrop);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
setBackdrop("", "");
|
||||
}, []);
|
||||
@@ -49,66 +76,18 @@ function LoginPublicUsersList() {
|
||||
return (
|
||||
<>
|
||||
<AppBarBackOnly />
|
||||
<Container
|
||||
maxWidth="md"
|
||||
sx={{
|
||||
height: "100vh",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Typography variant="h3" mb={2}>
|
||||
<div className="login-container">
|
||||
<Typography variant="h4" align="center">
|
||||
Users
|
||||
</Typography>
|
||||
|
||||
<Grid
|
||||
container
|
||||
columns={{
|
||||
xs: 2,
|
||||
sm: 3,
|
||||
md: 4,
|
||||
}}
|
||||
wrap="nowrap"
|
||||
alignItems="center"
|
||||
overflow="auto"
|
||||
width="100%"
|
||||
mb={3}
|
||||
paddingBottom={2}
|
||||
className="roundedScrollbar"
|
||||
>
|
||||
{users.data.map((item, index) => {
|
||||
return (
|
||||
<Grid
|
||||
key={item.Id}
|
||||
flexShrink={0}
|
||||
flexGrow={1}
|
||||
xs={1}
|
||||
sm={1}
|
||||
md={1}
|
||||
>
|
||||
<Card
|
||||
cardTitle={item.Name}
|
||||
item={item}
|
||||
disableOverlay
|
||||
itemType="User"
|
||||
cardType="square"
|
||||
onClick={() =>
|
||||
navigate({
|
||||
to: "/login/$userId/$userName",
|
||||
params: { userId: item.Id, userName: item.Name },
|
||||
})
|
||||
}
|
||||
overrideIcon="User"
|
||||
imageType="Primary"
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
<div className="user-list-container roundedScrollbar">
|
||||
{users.data.map((item) => {
|
||||
return <UserCard user={item} key={item.Id} />;
|
||||
})}
|
||||
</Grid>
|
||||
</div>
|
||||
|
||||
<div className="buttons">
|
||||
{/* <div className="buttons">
|
||||
<Button
|
||||
color="secondary"
|
||||
variant="contained"
|
||||
@@ -118,20 +97,22 @@ function LoginPublicUsersList() {
|
||||
Change Server
|
||||
</Button>
|
||||
<QuickConnectButton />
|
||||
<Button
|
||||
variant="contained"
|
||||
className="userEventButton"
|
||||
onClick={handleManualLogin}
|
||||
size="small"
|
||||
>
|
||||
Manual Login
|
||||
</Button>
|
||||
</div>
|
||||
</Container>
|
||||
</div> */}
|
||||
<Chip
|
||||
style={{ marginLeft: "50%", transform: "translateX(-50%)" }}
|
||||
label={
|
||||
<Typography variant="body2" align="center">
|
||||
Don't see your user? Try using{" "}
|
||||
<Link to="/login/manual">Manual Login</Link> or{" "}
|
||||
<Link to="/setup/server/list">Changing Server</Link>
|
||||
</Typography>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
if (users.isError) {
|
||||
return <ErrorNotice error="" />;
|
||||
return <ErrorNotice />;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,35 @@
|
||||
|
||||
.user {
|
||||
&List {
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
width: min(60vw, 45em);
|
||||
&-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 {
|
||||
border-radius: $border-radius-default;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
flex: 1 1 0px;
|
||||
overflow: hidden;
|
||||
&-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;
|
||||
@@ -31,13 +50,21 @@
|
||||
}
|
||||
|
||||
.login {
|
||||
width: 100vw;
|
||||
// width: 50em;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
&-container{
|
||||
width: min(40em,80vw);
|
||||
height: 100vh;
|
||||
margin: auto;
|
||||
padding-top: 4em;
|
||||
padding-bottom: 4em;
|
||||
}
|
||||
|
||||
&-form {
|
||||
width: 28em;
|
||||
display: flex;
|
||||
|
||||
Reference in new issue
Block a user