Add change server option #202

This commit is contained in:
Prayag Prajapati committed 2023-10-27 17:07:32 +05:30
1 parent cdd1a0a85b
commit 09bcee155c
8 files changed
+270 -34

No files matched your search

+31 -29
View File
@@ -19,8 +19,6 @@ import { relaunch } from "@tauri-apps/api/process";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
// Theming
import CssBaseline from "@mui/material/CssBaseline";
import { theme } from "./theme";
@@ -97,6 +95,7 @@ import PlaylistTitlePage from "./routes/playlist/index.jsx";
import { createApi, useApi } from "./utils/store/api.js";
import { useQuery } from "@tanstack/react-query";
import { CircularProgress } from "@mui/material";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
const anim = {
initial: {
@@ -141,26 +140,28 @@ const LogicalRoute = () => {
);
return res;
};
if (
!defaultServer.isPending &&
!server.isPending &&
!userSaved.isPending
) {
if (defaultServer.data) {
if (userSaved.data) {
authenticateUser();
navigate("/home");
// return <Navigate replace to={} />;
useEffect(() => {
if (
!defaultServer.isPending &&
!server.isPending &&
!userSaved.isPending
) {
if (defaultServer.data) {
if (userSaved.data) {
authenticateUser();
navigate("/home");
// return <Navigate replace to={} />;
} else {
createApi(server.data.address);
navigate("/login/index");
// return <Navigate replace to={`/login/index`} />;
}
} else {
createApi(server.data.address);
navigate("/login/index");
// return <Navigate replace to={`/login/index`} />;
navigate("/setup/server");
// return <Navigate replace to={`/setup/server`} />;
}
} else {
navigate("/setup/server");
// return <Navigate replace to={`/setup/server`} />;
}
}
}, []);
return (
<div
style={{
@@ -188,15 +189,17 @@ const LoginRoute = () => {
enabled: Boolean(api),
});
if (usersList.isSuccess) {
if (usersList.data.length > 0) {
navigate("/login/users");
// <Navigate replace to="/login/users" />;
} else {
navigate("/login/manual");
// <Navigate replace to="/login/manual" />;
useEffect(() => {
if (usersList.isSuccess) {
if (usersList.data.length > 0) {
navigate("/login/users");
// <Navigate replace to="/login/users" />;
} else {
navigate("/login/manual");
// <Navigate replace to="/login/manual" />;
}
}
}
}, []);
return (
<div
style={{
@@ -286,7 +289,6 @@ function App() {
useEffect(() => {
window.scrollTo(0, 0);
console.log(location);
}, [location.key]);
const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]);
@@ -543,7 +545,7 @@ function App() {
</Route>
</Routes>
</div>
<ReactQueryDevtools position="top-right" />
<ReactQueryDevtools />
</ThemeProvider>
</SnackbarProvider>
);
+1
View File
@@ -90,6 +90,7 @@ export const AppBar = () => {
if (
location.pathname.includes("login") ||
location.pathname.includes("setup") ||
location.pathname.includes("server") ||
location.pathname.includes("player") ||
location.pathname === "/"
) {
@@ -1,5 +1,5 @@
/** @format */
import React from "react";
import { useQuery } from "@tanstack/react-query";
import { CardScroller } from "../../cardScroller/cardScroller";
import { Card } from "../../card/card";
@@ -47,7 +47,7 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
displayCards={8}
title={"Latest " + latestMediaLib[1]}
>
{data.data.map((item, index) => {
{data.data.map((item) => {
return (
<Card
key={item.Id}
@@ -64,7 +64,7 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
: item.Type == BaseItemKind.Series
? `${item.ProductionYear} - ${
!!item.EndDate
item.EndDate
? new Date(
item.EndDate,
).toLocaleString(
+1
View File
@@ -94,6 +94,7 @@ export const SideMenu = () => {
if (
location.pathname.includes("login") ||
location.pathname.includes("setup") ||
location.pathname.includes("server") ||
location.pathname.includes("player") ||
location.pathname === "/"
) {
+11 -1
View File
@@ -514,10 +514,20 @@ export const UserLoginManual = () => {
loading={loading}
loadingPosition="end"
size="large"
sx={{ width: "100%" }}
sx={{ width: "100%", mb: 1 }}
>
Login
</LoadingButton>
<Button
color="secondary"
variant="contained"
className="userEventButton"
size="large"
sx={{ width: "100%" }}
onClick={() => navigate("/servers/list")}
>
Change Server
</Button>
</Grid>
<Grid sx={{ width: "100%" }}>
<Typography variant="subtitle2">
+168 -1
View File
@@ -1,6 +1,173 @@
/** @format */
import React, { useState } from "react";
import Typography from "@mui/material/Typography";
import Paper from "@mui/material/Paper";
import IconButton from "@mui/material/IconButton";
import Chip from "@mui/material/Chip";
import Divider from "@mui/material/Divider";
import { green, red } from "@mui/material/colors";
import "./serverList.module.scss";
import { useMutation, useQuery } from "@tanstack/react-query";
import {
getAllServer,
getDefaultServer,
setDefaultServer,
} from "../../../utils/storage/servers";
import { AppBarBackOnly } from "../../../components/appBar/backOnly";
import { useNavigate } from "react-router-dom";
import { useSnackbar } from "notistack";
const ServerList = () => {
return <></>;
const navigate = useNavigate();
const [serverState, setServerState] = useState(null);
const { enqueueSnackbar } = useSnackbar();
const servers = useQuery({
queryKey: ["servers-list"],
queryFn: async () => await getAllServer(),
});
const defaultServer = useQuery({
queryKey: ["default-server"],
queryFn: async () => await getDefaultServer(),
});
const handleServerChange = useMutation({
mutationFn: () => {
setDefaultServer(serverState);
},
onSuccess: () => {
defaultServer.refetch();
enqueueSnackbar("Successfully changed server!", {
variant: "success",
});
navigate("/");
},
onError: () => {
enqueueSnackbar("Error changing the server", {
variant: "error",
});
},
});
return (
<div className="server-list">
<AppBarBackOnly />
<div
style={{
display: "flex",
justifyContent: "space-between",
width: "40vw",
alignItems: "center",
marginBottom: "2em",
}}
>
<Typography variant="h3" fontWeight={200}>
Servers
</Typography>
<IconButton
style={{
fontSize: "1.64em",
}}
onClick={() => navigate("/setup/server")}
>
<span className="material-symbols-rounded">add</span>
</IconButton>
</div>
<Paper className="server-list-container">
{servers.isSuccess &&
servers.data.map((server, index) => (
<div key={index} className="server-list-item">
<span className="material-symbols-rounded server-list-item-icon">
dns
</span>
<div className="server-list-item-info">
<Typography
variant="h6"
fontWeight={400}
sx={{
display: "flex",
alignItems: "center",
}}
>
{server[1].systemInfo.ServerName}
{server[0] ==
defaultServer.data && (
<Chip
label={
<Typography
variant="caption"
fontWeight={
600
}
fontFamily="JetBrains Mono Variable"
>
Current
</Typography>
}
color="info"
sx={{
ml: 2,
width: "5.4em",
}}
size="medium"
/>
)}
</Typography>
<Typography
variant="subtitle1"
style={{
opacity: 0.7,
}}
fontWeight={300}
>
{server[1].address}
</Typography>
<Typography
variant="subtitle2"
style={{
opacity: 0.5,
}}
fontWeight={300}
>
Version:{" "}
{server[1].systemInfo.Version}
</Typography>
</div>
<div className="server-list-item-buttons">
<IconButton
style={{
fontSize: "1.64em",
}}
onClick={() => {
setServerState(server[0]);
handleServerChange.mutate();
}}
disabled={
handleServerChange.isPending
}
>
<span className="material-symbols-rounded">
start
</span>
</IconButton>
<IconButton
style={{
fontSize: "1.64em",
color: red[400],
}}
disabled={
handleServerChange.isPending
}
>
<span className="material-symbols-rounded">
delete_forever
</span>
</IconButton>
</div>
</div>
))}
</Paper>
</div>
);
};
export default ServerList;
@@ -0,0 +1,53 @@
/** @format */
.server-list {
position: absolute;
width: 100vw;
height: 100vh;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
&-container {
display: flex;
flex-direction: column;
width: 40vw;
padding: 1.2em;
border-radius: 20px !important;
}
&-item {
display: grid;
grid-template-columns: 3.4em 1fr auto;
justify-items: start;
align-items: center;
gap: 0.8em;
&-icon {
font-size: 3.4em !important;
}
&-info {
display: flex;
flex-direction: column;
// width: 100%;
}
&-buttons {
display: flex;
flex-direction: row;
gap: 0.5em;
width: 100%;
overflow: hidden;
}
border-bottom: 1.2px solid rgb(255 255 255 / 0.1);
$spacing: 0.75em;
padding-bottom: $spacing;
margin-bottom: $spacing;
&:last-child {
border: none;
margin: 0;
padding: 0;
}
}
}
+2
View File
@@ -37,6 +37,8 @@ export const getServer = async (serverId) => {
*/
export const getAllServer = async () => {
let server = await servers.entries();
// remove default server field from this result
server = server.filter((item) => item[0] != "defaultServer");
return server;
};