Change server reachability #202

This commit is contained in:
Prayag Prajapati committed 2023-10-27 19:38:43 +05:30
1 parent 09bcee155c
commit aa47e2fda5
6 files changed
+75 -38

No files matched your search

-2
View File
@@ -7,8 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Jellyplayer</title> <title>Jellyplayer</title>
<script src="http://localhost:8097"></script>
<style> <style>
.app-loading { .app-loading {
position: fixed; position: fixed;
+63 -34
View File
@@ -96,6 +96,8 @@ 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"; import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
import { setServerReachability, useServerStore } from "./utils/store/server";
const anim = { const anim = {
initial: { initial: {
@@ -115,6 +117,7 @@ const anim = {
const LogicalRoute = () => { const LogicalRoute = () => {
const [api] = useApi((state) => [state.api]); const [api] = useApi((state) => [state.api]);
const navigate = useNavigate(); const navigate = useNavigate();
const { enqueueSnackbar } = useSnackbar();
const defaultServer = useQuery({ const defaultServer = useQuery({
queryKey: ["routing", "defaultServer"], queryKey: ["routing", "defaultServer"],
queryFn: async () => { queryFn: async () => {
@@ -129,6 +132,14 @@ const LogicalRoute = () => {
}, },
enabled: defaultServer.isSuccess, enabled: defaultServer.isSuccess,
}); });
const pingServer = useQuery({
queryKey: ["routing", "pingServer"],
queryFn: async () => {
const result = await getSystemApi(api).getPingSystem();
return result.data;
},
enabled: Boolean(api) && server.isSuccess,
});
const userSaved = useQuery({ const userSaved = useQuery({
queryKey: ["routing", "savedUser"], queryKey: ["routing", "savedUser"],
queryFn: async () => await getUser(), queryFn: async () => await getUser(),
@@ -140,13 +151,14 @@ const LogicalRoute = () => {
); );
return res; return res;
}; };
useEffect(() => {
if ( if (
!defaultServer.isPending && !defaultServer.isPending &&
!server.isPending && !server.isPending &&
!userSaved.isPending !userSaved.isPending &&
!pingServer.isPending
) { ) {
if (defaultServer.data) { if (defaultServer.data) {
if (pingServer.data == "Jellyfin Server") {
if (userSaved.data) { if (userSaved.data) {
authenticateUser(); authenticateUser();
navigate("/home"); navigate("/home");
@@ -156,12 +168,14 @@ const LogicalRoute = () => {
navigate("/login/index"); navigate("/login/index");
// return <Navigate replace to={`/login/index`} />; // return <Navigate replace to={`/login/index`} />;
} }
} else {
navigate("/error");
}
} else { } else {
navigate("/setup/server"); navigate("/setup/server");
// return <Navigate replace to={`/setup/server`} />; // return <Navigate replace to={`/setup/server`} />;
} }
} }
}, []);
return ( return (
<div <div
style={{ style={{
@@ -189,7 +203,6 @@ 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");
@@ -199,7 +212,6 @@ const LoginRoute = () => {
// <Navigate replace to="/login/manual" />; // <Navigate replace to="/login/manual" />;
} }
} }
}, []);
return ( return (
<div <div
style={{ style={{
@@ -238,12 +250,12 @@ function App() {
*/ */
const [api] = useApi((state) => [state.api]); const [api] = useApi((state) => [state.api]);
const [serverReachable] = useState(true);
const [playbackDataLoading] = usePlaybackDataLoadStore((state) => [ const [playbackDataLoading] = usePlaybackDataLoadStore((state) => [
state.isPending, state.isPending,
]); ]);
const [serverReachable] = useServerStore((state) => [state.reachable]);
const { enqueueSnackbar } = useSnackbar(); const { enqueueSnackbar } = useSnackbar();
const serverSaved = async () => { const serverSaved = async () => {
@@ -320,6 +332,8 @@ function App() {
], ],
}); });
const navigate = useNavigate();
return ( return (
<SnackbarProvider maxSnack={5}> <SnackbarProvider maxSnack={5}>
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
@@ -371,33 +385,7 @@ function App() {
</Slide> </Slide>
{/* Show Dialog if server not reachable */} {/* Show Dialog if server not reachable */}
<Dialog
open={!serverReachable}
onClose={handleRelaunch}
aria-labelledby="alert-dialog-text"
aria-describedby="alert-dialog-desc"
maxWidth="md"
sx={{
padding: "1em",
}}
>
<DialogTitle id="alert-dialog-text">
Unable to reach server
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-desc">
Unable to connect to the jellyfin server.
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleRemoveServer}>
Remove Server
</Button>
<Button onClick={handleRelaunch}>
Restart JellyPlayer
</Button>
</DialogActions>
</Dialog>
<div className="app-backdrop-container"> <div className="app-backdrop-container">
<AnimatePresence> <AnimatePresence>
<motion.img <motion.img
@@ -454,6 +442,47 @@ function App() {
element={<LogicalRoute />} element={<LogicalRoute />}
// element={<></>} // element={<></>}
/> />
<Route
path="/error"
element={
<Dialog
open
onClose={handleRelaunch}
aria-labelledby="alert-dialog-text"
aria-describedby="alert-dialog-desc"
maxWidth="md"
>
<DialogTitle id="alert-dialog-text">
Unable to reach server
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-desc">
Unable to connect to
the jellyfin server.
</DialogContentText>
</DialogContent>
<DialogActions>
<Button
onClick={() =>
navigate(
"/servers/list",
)
}
>
Change Server
</Button>
<Button
variant="outlined"
onClick={
handleRelaunch
}
>
Restart JellyPlayer
</Button>
</DialogActions>
</Dialog>
}
/>
<Route <Route
path="/login/index" path="/login/index"
exact exact
+1
View File
@@ -92,6 +92,7 @@ export const AppBar = () => {
location.pathname.includes("setup") || location.pathname.includes("setup") ||
location.pathname.includes("server") || location.pathname.includes("server") ||
location.pathname.includes("player") || location.pathname.includes("player") ||
location.pathname.includes("error") ||
location.pathname === "/" location.pathname === "/"
) { ) {
setDisplay(false); setDisplay(false);
+1
View File
@@ -96,6 +96,7 @@ export const SideMenu = () => {
location.pathname.includes("setup") || location.pathname.includes("setup") ||
location.pathname.includes("server") || location.pathname.includes("server") ||
location.pathname.includes("player") || location.pathname.includes("player") ||
location.pathname.includes("error") ||
location.pathname === "/" location.pathname === "/"
) { ) {
setDisplay(false); setDisplay(false);
+1 -2
View File
@@ -5,8 +5,7 @@ import Typography from "@mui/material/Typography";
import Paper from "@mui/material/Paper"; import Paper from "@mui/material/Paper";
import IconButton from "@mui/material/IconButton"; import IconButton from "@mui/material/IconButton";
import Chip from "@mui/material/Chip"; import Chip from "@mui/material/Chip";
import Divider from "@mui/material/Divider"; import { red } from "@mui/material/colors";
import { green, red } from "@mui/material/colors";
import "./serverList.module.scss"; import "./serverList.module.scss";
import { useMutation, useQuery } from "@tanstack/react-query"; import { useMutation, useQuery } from "@tanstack/react-query";
+9
View File
@@ -0,0 +1,9 @@
/** @format */
import { create } from "zustand";
export const useServerStore = create(() => ({
reachable: true,
}));
export const setServerReachability = (reach) =>
useServerStore.setState(() => ({ reachable: reach }));