Add change server option #202
This commit is contained in:
8 files changed
+245
-9
No files matched your search
+6
-4
@@ -19,8 +19,6 @@ import { relaunch } from "@tauri-apps/api/process";
|
|||||||
|
|
||||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||||
|
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
|
||||||
|
|
||||||
// Theming
|
// Theming
|
||||||
import CssBaseline from "@mui/material/CssBaseline";
|
import CssBaseline from "@mui/material/CssBaseline";
|
||||||
import { theme } from "./theme";
|
import { theme } from "./theme";
|
||||||
@@ -97,6 +95,7 @@ import PlaylistTitlePage from "./routes/playlist/index.jsx";
|
|||||||
import { createApi, useApi } from "./utils/store/api.js";
|
import { createApi, useApi } from "./utils/store/api.js";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { CircularProgress } from "@mui/material";
|
import { CircularProgress } from "@mui/material";
|
||||||
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||||
|
|
||||||
const anim = {
|
const anim = {
|
||||||
initial: {
|
initial: {
|
||||||
@@ -141,6 +140,7 @@ const LogicalRoute = () => {
|
|||||||
);
|
);
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
!defaultServer.isPending &&
|
!defaultServer.isPending &&
|
||||||
!server.isPending &&
|
!server.isPending &&
|
||||||
@@ -161,6 +161,7 @@ const LogicalRoute = () => {
|
|||||||
// return <Navigate replace to={`/setup/server`} />;
|
// return <Navigate replace to={`/setup/server`} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, []);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -188,6 +189,7 @@ const LoginRoute = () => {
|
|||||||
enabled: Boolean(api),
|
enabled: Boolean(api),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
if (usersList.isSuccess) {
|
if (usersList.isSuccess) {
|
||||||
if (usersList.data.length > 0) {
|
if (usersList.data.length > 0) {
|
||||||
navigate("/login/users");
|
navigate("/login/users");
|
||||||
@@ -197,6 +199,7 @@ const LoginRoute = () => {
|
|||||||
// <Navigate replace to="/login/manual" />;
|
// <Navigate replace to="/login/manual" />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, []);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -286,7 +289,6 @@ function App() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
console.log(location);
|
|
||||||
}, [location.key]);
|
}, [location.key]);
|
||||||
|
|
||||||
const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]);
|
const [audioPlayerVisible] = useAudioPlayback((state) => [state.display]);
|
||||||
@@ -543,7 +545,7 @@ function App() {
|
|||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
<ReactQueryDevtools position="top-right" />
|
<ReactQueryDevtools />
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</SnackbarProvider>
|
</SnackbarProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ export const AppBar = () => {
|
|||||||
if (
|
if (
|
||||||
location.pathname.includes("login") ||
|
location.pathname.includes("login") ||
|
||||||
location.pathname.includes("setup") ||
|
location.pathname.includes("setup") ||
|
||||||
|
location.pathname.includes("server") ||
|
||||||
location.pathname.includes("player") ||
|
location.pathname.includes("player") ||
|
||||||
location.pathname === "/"
|
location.pathname === "/"
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/** @format */
|
/** @format */
|
||||||
|
import React from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { CardScroller } from "../../cardScroller/cardScroller";
|
import { CardScroller } from "../../cardScroller/cardScroller";
|
||||||
import { Card } from "../../card/card";
|
import { Card } from "../../card/card";
|
||||||
@@ -47,7 +47,7 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
|
|||||||
displayCards={8}
|
displayCards={8}
|
||||||
title={"Latest " + latestMediaLib[1]}
|
title={"Latest " + latestMediaLib[1]}
|
||||||
>
|
>
|
||||||
{data.data.map((item, index) => {
|
{data.data.map((item) => {
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={item.Id}
|
key={item.Id}
|
||||||
@@ -64,7 +64,7 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
|
|||||||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
||||||
: item.Type == BaseItemKind.Series
|
: item.Type == BaseItemKind.Series
|
||||||
? `${item.ProductionYear} - ${
|
? `${item.ProductionYear} - ${
|
||||||
!!item.EndDate
|
item.EndDate
|
||||||
? new Date(
|
? new Date(
|
||||||
item.EndDate,
|
item.EndDate,
|
||||||
).toLocaleString(
|
).toLocaleString(
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ export const SideMenu = () => {
|
|||||||
if (
|
if (
|
||||||
location.pathname.includes("login") ||
|
location.pathname.includes("login") ||
|
||||||
location.pathname.includes("setup") ||
|
location.pathname.includes("setup") ||
|
||||||
|
location.pathname.includes("server") ||
|
||||||
location.pathname.includes("player") ||
|
location.pathname.includes("player") ||
|
||||||
location.pathname === "/"
|
location.pathname === "/"
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -514,10 +514,20 @@ export const UserLoginManual = () => {
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
loadingPosition="end"
|
loadingPosition="end"
|
||||||
size="large"
|
size="large"
|
||||||
sx={{ width: "100%" }}
|
sx={{ width: "100%", mb: 1 }}
|
||||||
>
|
>
|
||||||
Login
|
Login
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
variant="contained"
|
||||||
|
className="userEventButton"
|
||||||
|
size="large"
|
||||||
|
sx={{ width: "100%" }}
|
||||||
|
onClick={() => navigate("/servers/list")}
|
||||||
|
>
|
||||||
|
Change Server
|
||||||
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid sx={{ width: "100%" }}>
|
<Grid sx={{ width: "100%" }}>
|
||||||
<Typography variant="subtitle2">
|
<Typography variant="subtitle2">
|
||||||
|
|||||||
@@ -1,6 +1,173 @@
|
|||||||
/** @format */
|
/** @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 = () => {
|
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;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,6 +37,8 @@ export const getServer = async (serverId) => {
|
|||||||
*/
|
*/
|
||||||
export const getAllServer = async () => {
|
export const getAllServer = async () => {
|
||||||
let server = await servers.entries();
|
let server = await servers.entries();
|
||||||
|
// remove default server field from this result
|
||||||
|
server = server.filter((item) => item[0] != "defaultServer");
|
||||||
return server;
|
return server;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user