fix(server): Use redirect instead of relaunch when changing or deleting a server
This commit is contained in:
11 files changed
+102
-332
No files matched your search
@@ -5,3 +5,4 @@
|
|||||||
- feat(search): Add Episode to search by @prayag17
|
- feat(search): Add Episode to search by @prayag17
|
||||||
- feat(settings-server): Add a refretch button by @prayag17
|
- feat(settings-server): Add a refretch button by @prayag17
|
||||||
- feat(web): Add a global query fetch/mutation status by @prayag17
|
- feat(web): Add a global query fetch/mutation status by @prayag17
|
||||||
|
- fix(server): Use redirect instead of relaunch when changing or deleting a server by @prayag17
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
# 📝 Prerequisites
|
# 📝 Prerequisites
|
||||||
|
|
||||||
- Nodejs (≥19.1.0)
|
- Nodejs (≥19.1.0)
|
||||||
- Rust (≥1.66.1)
|
- Rust (≥1.76.0)
|
||||||
- Visual Studio C++ Build tools
|
- Visual Studio C++ Build tools
|
||||||
- [pnpm](https://pnpm.io/)
|
- [pnpm](https://pnpm.io/)
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -438,7 +438,6 @@ function AppReady() {
|
|||||||
transition: "padding 250ms",
|
transition: "padding 250ms",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* <SideMenu /> */}
|
|
||||||
<AppBar />
|
<AppBar />
|
||||||
{audioPlayerVisible && <AudioPlayer />}
|
{audioPlayerVisible && <AudioPlayer />}
|
||||||
<ErrorBoundary FallbackComponent={ErrorNotice} key={location.key}>
|
<ErrorBoundary FallbackComponent={ErrorNotice} key={location.key}>
|
||||||
@@ -505,7 +504,7 @@ function AppReady() {
|
|||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ReactQueryDevtools buttonPosition="bottom-right" position="right" />
|
<ReactQueryDevtools buttonPosition="bottom-right" position="left" />
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</SnackbarProvider>
|
</SnackbarProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export const AppBar = () => {
|
|||||||
});
|
});
|
||||||
return libs.data;
|
return libs.data;
|
||||||
},
|
},
|
||||||
enabled: !!user.data,
|
enabled: !!user.data && !!api.accessToken,
|
||||||
networkMode: "always",
|
networkMode: "always",
|
||||||
});
|
});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,177 +0,0 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
|
||||||
|
|
||||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
|
||||||
import { getUserViewsApi } from "@jellyfin/sdk/lib/utils/api/user-views-api";
|
|
||||||
import { useQuery } from "@tanstack/react-query";
|
|
||||||
|
|
||||||
import { NavLink, useLocation } from "react-router-dom";
|
|
||||||
|
|
||||||
import MuiDrawer from "@mui/material/Drawer";
|
|
||||||
import Tooltip from "@mui/material/Tooltip";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import { styled } from "@mui/material/styles";
|
|
||||||
|
|
||||||
import { getTypeIcon } from "../../components/utils/iconsCollection.jsx";
|
|
||||||
|
|
||||||
import { useApi } from "../../utils/store/api";
|
|
||||||
import "./sidemenu.module.scss";
|
|
||||||
|
|
||||||
import Icon from "../../assets/icon.svg";
|
|
||||||
|
|
||||||
const DrawerHeader = styled("div")(({ theme }) => ({
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "flex-end",
|
|
||||||
padding: theme.spacing(0, 1),
|
|
||||||
...theme.mixins.toolbar,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const MiniDrawer = styled(MuiDrawer, {
|
|
||||||
shouldForwardProp: (prop) => prop !== "open",
|
|
||||||
})(({ theme }) => ({
|
|
||||||
flexShrink: 0,
|
|
||||||
whiteSpace: "nowrap",
|
|
||||||
boxSizing: "border-box",
|
|
||||||
backgroundColor: theme.palette.primary.background.dark,
|
|
||||||
overflowX: "hidden",
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const SideMenu = () => {
|
|
||||||
const [api] = useApi((state) => [state.api]);
|
|
||||||
const location = useLocation();
|
|
||||||
|
|
||||||
const [display, setDisplay] = useState(false);
|
|
||||||
|
|
||||||
const user = useQuery({
|
|
||||||
queryKey: ["user"],
|
|
||||||
queryFn: async () => {
|
|
||||||
const usr = await getUserApi(api).getCurrentUser();
|
|
||||||
return usr.data;
|
|
||||||
},
|
|
||||||
enabled: display,
|
|
||||||
networkMode: "always",
|
|
||||||
});
|
|
||||||
const libraries = useQuery({
|
|
||||||
queryKey: ["libraries"],
|
|
||||||
queryFn: async () => {
|
|
||||||
const libs = await getUserViewsApi(api).getUserViews({
|
|
||||||
userId: user.data.Id,
|
|
||||||
});
|
|
||||||
return libs.data;
|
|
||||||
},
|
|
||||||
enabled: !!user.data,
|
|
||||||
networkMode: "always",
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (
|
|
||||||
location.pathname.includes("login") ||
|
|
||||||
location.pathname.includes("setup") ||
|
|
||||||
location.pathname.includes("server") ||
|
|
||||||
location.pathname.includes("player") ||
|
|
||||||
location.pathname.includes("error") ||
|
|
||||||
location.pathname === "/"
|
|
||||||
) {
|
|
||||||
setDisplay(false);
|
|
||||||
} else {
|
|
||||||
setDisplay(true);
|
|
||||||
}
|
|
||||||
}, [location]);
|
|
||||||
|
|
||||||
if (!display) {
|
|
||||||
return <></>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (display) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<MiniDrawer
|
|
||||||
variant="permanent"
|
|
||||||
open={false}
|
|
||||||
PaperProps={{
|
|
||||||
sx: {
|
|
||||||
backgroundColor: "inherit",
|
|
||||||
border: "none",
|
|
||||||
width: "5em",
|
|
||||||
height: "100vh",
|
|
||||||
zIndex: "1",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
sx={{
|
|
||||||
zIndex: 1,
|
|
||||||
width: "5em",
|
|
||||||
background: "transparent !important ",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<DrawerHeader
|
|
||||||
className="Mui-DrawerHeader"
|
|
||||||
sx={{
|
|
||||||
justifyContent: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img alt="JellyPlayer" src={Icon} className="sidemenu-icon" />
|
|
||||||
</DrawerHeader>
|
|
||||||
<div className="sidemenu-item-container">
|
|
||||||
{libraries.isPending ? (
|
|
||||||
<></>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<NavLink to="/home" className="sidemenu-item small">
|
|
||||||
<div className="sidemenu-item-icon">
|
|
||||||
{getTypeIcon("Home")}
|
|
||||||
</div>
|
|
||||||
<Typography
|
|
||||||
className="sidemenu-item-text"
|
|
||||||
variant="caption"
|
|
||||||
fontWeight={500}
|
|
||||||
style={{
|
|
||||||
width: "80%",
|
|
||||||
}}
|
|
||||||
overflow="hidden"
|
|
||||||
textOverflow="ellipsis"
|
|
||||||
textAlign="center"
|
|
||||||
>
|
|
||||||
Home
|
|
||||||
</Typography>
|
|
||||||
</NavLink>
|
|
||||||
{libraries.data.Items.map((lib) => {
|
|
||||||
return (
|
|
||||||
<Tooltip
|
|
||||||
title={lib.Name}
|
|
||||||
placement="right"
|
|
||||||
arrow
|
|
||||||
followCursor
|
|
||||||
key={lib.Id}
|
|
||||||
>
|
|
||||||
<NavLink
|
|
||||||
to={`/library/${lib.Id}`}
|
|
||||||
className="sidemenu-item"
|
|
||||||
>
|
|
||||||
<div className="sidemenu-item-icon">
|
|
||||||
{getTypeIcon(lib.CollectionType)}
|
|
||||||
</div>
|
|
||||||
<Typography
|
|
||||||
className="sidemenu-item-text"
|
|
||||||
variant="caption"
|
|
||||||
fontWeight={500}
|
|
||||||
style={{
|
|
||||||
width: "80%",
|
|
||||||
}}
|
|
||||||
overflow="hidden"
|
|
||||||
textOverflow="ellipsis"
|
|
||||||
textAlign="center"
|
|
||||||
>
|
|
||||||
{lib.Name}
|
|
||||||
</Typography>
|
|
||||||
</NavLink>
|
|
||||||
</Tooltip>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</MiniDrawer>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
|
|
||||||
.sidemenu {
|
|
||||||
&-icon {
|
|
||||||
width: 60%;
|
|
||||||
object-fit: cover;
|
|
||||||
}
|
|
||||||
&-item {
|
|
||||||
&-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
margin-top: 1em;
|
|
||||||
overflow-y: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
color: rgb(255 255 255 / 0.7);
|
|
||||||
transition: color $transition-time-fast;
|
|
||||||
text-decoration: none;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 0.2em;
|
|
||||||
margin-bottom: 0.8em;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
color: white;
|
|
||||||
.material-symbols-rounded {
|
|
||||||
font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 25,
|
|
||||||
"opsz" 40;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.active {
|
|
||||||
color: white;
|
|
||||||
.sidemenu-item-icon::before {
|
|
||||||
opacity: 1;
|
|
||||||
transform: scaleX(1);
|
|
||||||
}
|
|
||||||
.sidemenu-item-text {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
.material-symbols-rounded {
|
|
||||||
font-variation-settings: "FILL" 1, "wght" 300, "GRAD" 25,
|
|
||||||
"opsz" 40;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&-text {
|
|
||||||
transition: max-height 0.5s;
|
|
||||||
transition-delay: 0.05s;
|
|
||||||
|
|
||||||
font-size: 0.7em !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-icon {
|
|
||||||
padding: 0.15em 0.75em;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
position: relative;
|
|
||||||
&::before {
|
|
||||||
content: "";
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
position: absolute;
|
|
||||||
background: $clr-gradient-default;
|
|
||||||
z-index: -1;
|
|
||||||
transform: scaleX(0.25);
|
|
||||||
opacity: 0;
|
|
||||||
border-radius: 100px;
|
|
||||||
transition: opacity $transition-time-fast,
|
|
||||||
transform $transition-time-fast;
|
|
||||||
transition-delay: 0.1s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -30,12 +30,13 @@ import logo from "../../assets/logoBlack.png";
|
|||||||
|
|
||||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useApi } from "../../utils/store/api";
|
import { createApi, useApi } from "../../utils/store/api";
|
||||||
import { useCentralStore } from "../../utils/store/central";
|
import { useCentralStore } from "../../utils/store/central";
|
||||||
import "./settings.module.scss";
|
import "./settings.module.scss";
|
||||||
|
|
||||||
|
import { RecommendedServerInfo } from "@jellyfin/sdk";
|
||||||
import { LoadingButton } from "@mui/lab";
|
import { LoadingButton } from "@mui/lab";
|
||||||
import { red } from "@mui/material/colors";
|
import { red, yellow } from "@mui/material/colors";
|
||||||
import { relaunch } from "@tauri-apps/api/process";
|
import { relaunch } from "@tauri-apps/api/process";
|
||||||
import { checkUpdate, installUpdate } from "@tauri-apps/api/updater";
|
import { checkUpdate, installUpdate } from "@tauri-apps/api/updater";
|
||||||
import { enqueueSnackbar, useSnackbar } from "notistack";
|
import { enqueueSnackbar, useSnackbar } from "notistack";
|
||||||
@@ -59,6 +60,10 @@ const motionConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Settings = () => {
|
const Settings = () => {
|
||||||
|
const [open, tabValue] = useSettingsStore((state) => [
|
||||||
|
state.dialogOpen,
|
||||||
|
state.tabValue,
|
||||||
|
]);
|
||||||
const [api, jellyfin] = useApi((state) => [state.api, state.jellyfin]);
|
const [api, jellyfin] = useApi((state) => [state.api, state.jellyfin]);
|
||||||
const systemInfo = useQuery({
|
const systemInfo = useQuery({
|
||||||
queryKey: ["about", "systemInfo"],
|
queryKey: ["about", "systemInfo"],
|
||||||
@@ -66,10 +71,11 @@ const Settings = () => {
|
|||||||
const result = await getSystemApi(api).getSystemInfo();
|
const result = await getSystemApi(api).getSystemInfo();
|
||||||
return result.data;
|
return result.data;
|
||||||
},
|
},
|
||||||
enabled: Boolean(api),
|
enabled: Boolean(api) && open,
|
||||||
});
|
});
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
const [applicationVersion, serversOnDiskFn] = useCentralStore((state) => [
|
const [applicationVersion, serversOnDiskFn] = useCentralStore((state) => [
|
||||||
state.clientVersion,
|
state.clientVersion,
|
||||||
@@ -79,33 +85,25 @@ const Settings = () => {
|
|||||||
const serversOnDisk = useQuery({
|
const serversOnDisk = useQuery({
|
||||||
queryKey: ["settings", "serversOnDisk"],
|
queryKey: ["settings", "serversOnDisk"],
|
||||||
queryFn: async () => await getAllServers(),
|
queryFn: async () => await getAllServers(),
|
||||||
|
enabled: open,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateInfo = useQuery({
|
const updateInfo = useQuery({
|
||||||
queryKey: ["about", "updater"],
|
queryKey: ["about", "updater"],
|
||||||
queryFn: async () => {
|
queryFn: async () => await checkUpdate(),
|
||||||
const result = await checkUpdate();
|
enabled: open,
|
||||||
return result;
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const defaultServer = useQuery({
|
const defaultServer = useQuery({
|
||||||
queryKey: ["settings", "default-server"],
|
queryKey: ["settings", "default-server"],
|
||||||
queryFn: async () => await getDefaultServer(),
|
queryFn: async () => await getDefaultServer(),
|
||||||
|
enabled: open,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
|
||||||
|
|
||||||
const [open, tabValue] = useSettingsStore((state) => [
|
|
||||||
state.dialogOpen,
|
|
||||||
state.tabValue,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const [updating, setUpdating] = useState(false);
|
const [updating, setUpdating] = useState(false);
|
||||||
const [animDirection, setAnimDirection] = useState("forward");
|
const [serverState, setServerState] = useState();
|
||||||
const [serverState, setServerState] = useState("");
|
|
||||||
const [ask, setAsk] = useState(false);
|
const [ask, setAsk] = useState(false);
|
||||||
const [action, setAction] = useState(null);
|
const [action, setAction] = useState(null);
|
||||||
const [addServerDialog, setAddServerDialog] = useState(false);
|
const [addServerDialog, setAddServerDialog] = useState(false);
|
||||||
@@ -114,11 +112,15 @@ const Settings = () => {
|
|||||||
const handleServerChange = useMutation({
|
const handleServerChange = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await delUser();
|
await delUser();
|
||||||
localStorage.clear();
|
await setDefaultServer(serverState.id);
|
||||||
await setDefaultServer(serverState);
|
await defaultServer.refetch();
|
||||||
|
createApi(serverState.address, null);
|
||||||
|
queryClient.removeQueries();
|
||||||
},
|
},
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
await relaunch();
|
setAsk(false);
|
||||||
|
setSettingsDialogOpen(false);
|
||||||
|
navigate("/login/index");
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -128,32 +130,40 @@ const Settings = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleDelete = async (serverId: string) => {
|
const handleDelete = async (server: RecommendedServerInfo) => {
|
||||||
await delServer(serverId);
|
await delServer(server.id);
|
||||||
|
|
||||||
if (serverId === defaultServer.data) {
|
if (server.id === defaultServer.data) {
|
||||||
await delUser();
|
await delUser();
|
||||||
await serversOnDisk.refetch();
|
await serversOnDisk.refetch();
|
||||||
|
|
||||||
if (serversOnDisk.data?.length > 0) {
|
if (serversOnDisk.data.length > 0) {
|
||||||
setDefaultServer(serversOnDisk.data[0].id);
|
setDefaultServer(serversOnDisk.data[0].id);
|
||||||
|
createApi(serversOnDisk.data[0].address, null);
|
||||||
|
} else {
|
||||||
|
// Reset Api as no server is present on disk
|
||||||
|
useApi.setState(useApi.getInitialState());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
setSettingsDialogOpen(false);
|
setSettingsDialogOpen(false);
|
||||||
await relaunch();
|
queryClient.removeQueries();
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
enqueueSnackbar("Server deleted successfully!", { variant: "success" });
|
||||||
|
setAsk(false);
|
||||||
|
await serversOnDisk.refetch();
|
||||||
|
await defaultServer.refetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkServer = useMutation({
|
const addServer = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const servers =
|
const servers =
|
||||||
await jellyfin.discovery.getRecommendedServerCandidates(serverIp);
|
await jellyfin.discovery.getRecommendedServerCandidates(serverIp);
|
||||||
const bestServer = jellyfin.discovery.findBestServer(servers);
|
const bestServer = jellyfin.discovery.findBestServer(servers);
|
||||||
return bestServer;
|
return bestServer;
|
||||||
},
|
},
|
||||||
onSuccess: (bestServer) => {
|
onSuccess: async (bestServer) => {
|
||||||
if (bestServer) {
|
if (bestServer) {
|
||||||
setServer(bestServer.systemInfo.Id, bestServer);
|
await setServer(bestServer.systemInfo.Id, bestServer);
|
||||||
setAddServerDialog(false);
|
setAddServerDialog(false);
|
||||||
enqueueSnackbar(
|
enqueueSnackbar(
|
||||||
"Client added successfully. You might need to refresh client list.",
|
"Client added successfully. You might need to refresh client list.",
|
||||||
@@ -161,6 +171,7 @@ const Settings = () => {
|
|||||||
variant: "success",
|
variant: "success",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
await serversOnDisk.refetch();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
@@ -168,8 +179,7 @@ const Settings = () => {
|
|||||||
enqueueSnackbar(`${err}`, { variant: "error" });
|
enqueueSnackbar(`${err}`, { variant: "error" });
|
||||||
enqueueSnackbar("Something went wrong", { variant: "error" });
|
enqueueSnackbar("Something went wrong", { variant: "error" });
|
||||||
},
|
},
|
||||||
onSettled: (bestServer) => {
|
onSettled: async (bestServer) => {
|
||||||
serversOnDisk.refetch();
|
|
||||||
if (!bestServer) {
|
if (!bestServer) {
|
||||||
enqueueSnackbar("Provided server address is not a Jellyfin server.", {
|
enqueueSnackbar("Provided server address is not a Jellyfin server.", {
|
||||||
variant: "error",
|
variant: "error",
|
||||||
@@ -192,15 +202,6 @@ const Settings = () => {
|
|||||||
orientation="vertical"
|
orientation="vertical"
|
||||||
value={tabValue}
|
value={tabValue}
|
||||||
onChange={(e, newValue) => {
|
onChange={(e, newValue) => {
|
||||||
console.log(`NewValue: ${newValue}`);
|
|
||||||
console.log(`TabValue: ${tabValue}`);
|
|
||||||
if (newValue > tabValue) {
|
|
||||||
console.log("forward");
|
|
||||||
setAnimDirection("forward");
|
|
||||||
} else {
|
|
||||||
console.log("backward");
|
|
||||||
setAnimDirection("backward");
|
|
||||||
}
|
|
||||||
setSettingsTabValue(newValue);
|
setSettingsTabValue(newValue);
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
@@ -502,13 +503,29 @@ const Settings = () => {
|
|||||||
|
|
||||||
{/* Server */}
|
{/* Server */}
|
||||||
{tabValue === 2 && (
|
{tabValue === 2 && (
|
||||||
<div className="settings-container settings-server-container">
|
<motion.div
|
||||||
|
layoutScroll
|
||||||
|
className="settings-container settings-server-container"
|
||||||
|
>
|
||||||
{serversOnDisk.isSuccess &&
|
{serversOnDisk.isSuccess &&
|
||||||
serversOnDisk.data.map((server) => {
|
serversOnDisk.data.map((server, index) => {
|
||||||
return (
|
return (
|
||||||
<div className="settings-server">
|
<motion.div
|
||||||
|
key={server.id}
|
||||||
|
className="settings-server"
|
||||||
|
initial={{
|
||||||
|
transform: "translateY(10px)",
|
||||||
|
opacity: 0,
|
||||||
|
}}
|
||||||
|
animate={{ transform: "translateY(0px)", opacity: 1 }}
|
||||||
|
exit={{ transform: "translateY(-10px)", opacity: 1 }}
|
||||||
|
transition={{
|
||||||
|
delay: 0.1 * index,
|
||||||
|
duration: 0.15,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<span className="material-symbols-rounded settings-server-icon">
|
<span className="material-symbols-rounded settings-server-icon">
|
||||||
dns
|
hard_drive
|
||||||
</span>
|
</span>
|
||||||
<div className="settings-server-info">
|
<div className="settings-server-info">
|
||||||
<Typography
|
<Typography
|
||||||
@@ -564,7 +581,7 @@ const Settings = () => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
setAsk(true);
|
setAsk(true);
|
||||||
setAction("change-server");
|
setAction("change-server");
|
||||||
setServerState(server.id);
|
setServerState(server);
|
||||||
}}
|
}}
|
||||||
disabled={handleServerChange.isPending}
|
disabled={handleServerChange.isPending}
|
||||||
>
|
>
|
||||||
@@ -580,7 +597,7 @@ const Settings = () => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
setAsk(true);
|
setAsk(true);
|
||||||
setAction("delete-server");
|
setAction("delete-server");
|
||||||
setServerState(server.id);
|
setServerState(server);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="material-symbols-rounded">
|
<div className="material-symbols-rounded">
|
||||||
@@ -588,7 +605,7 @@ const Settings = () => {
|
|||||||
</div>
|
</div>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</motion.div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
<div className="settings-server-fab-container">
|
<div className="settings-server-fab-container">
|
||||||
@@ -623,7 +640,7 @@ const Settings = () => {
|
|||||||
Add server
|
Add server
|
||||||
</Fab>
|
</Fab>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</motion.div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* About */}
|
{/* About */}
|
||||||
@@ -766,9 +783,6 @@ const Settings = () => {
|
|||||||
{/* Show dialog before deleting or changing server */}
|
{/* Show dialog before deleting or changing server */}
|
||||||
<Dialog open={ask} fullWidth maxWidth="xs">
|
<Dialog open={ask} fullWidth maxWidth="xs">
|
||||||
<DialogTitle>Are you sure?</DialogTitle>
|
<DialogTitle>Are you sure?</DialogTitle>
|
||||||
<DialogContent style={{ opacity: 0.8 }}>
|
|
||||||
JellyPlayer will relaunch.
|
|
||||||
</DialogContent>
|
|
||||||
<DialogActions
|
<DialogActions
|
||||||
style={{
|
style={{
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
@@ -857,9 +871,9 @@ const Settings = () => {
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
loading={checkServer.isPending}
|
loading={addServer.isPending}
|
||||||
loadingPosition="start"
|
loadingPosition="start"
|
||||||
onClick={checkServer.mutate}
|
onClick={addServer.mutate}
|
||||||
color="success"
|
color="success"
|
||||||
>
|
>
|
||||||
Add
|
Add
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const Home = () => {
|
|||||||
});
|
});
|
||||||
return libs.data;
|
return libs.data;
|
||||||
},
|
},
|
||||||
enabled: !!user.data,
|
enabled: !!user.data && !!api.accessToken,
|
||||||
networkMode: "always",
|
networkMode: "always",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import { getQuickConnectApi } from "@jellyfin/sdk/lib/utils/api/quick-connect-ap
|
|||||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||||
|
|
||||||
import { ErrorNotice } from "../../components/notices/errorNotice/errorNotice.jsx";
|
import { ErrorNotice } from "../../components/notices/errorNotice/errorNotice.jsx";
|
||||||
import { useApi } from "../../utils/store/api";
|
import { createApi, useApi } from "../../utils/store/api";
|
||||||
import "./login.module.scss";
|
import "./login.module.scss";
|
||||||
|
|
||||||
import { setBackdrop } from "../../utils/store/backdrop.js";
|
import { setBackdrop } from "../../utils/store/backdrop.js";
|
||||||
@@ -134,10 +134,10 @@ export const LoginWithImage = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
const user = await authUser();
|
const user = await authUser();
|
||||||
sessionStorage.setItem("accessToken", user.data.AccessToken);
|
sessionStorage.setItem("accessToken", user.data.AccessToken);
|
||||||
|
createApi(api.basePath, user.data.AccessToken);
|
||||||
if (rememberMe === true) {
|
if (rememberMe === true) {
|
||||||
await saveUser(userName, user.data.AccessToken);
|
await saveUser(userName, user.data.AccessToken);
|
||||||
}
|
}
|
||||||
event.emit("set-api-accessToken", api.basePath);
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
navigate("/home");
|
navigate("/home");
|
||||||
};
|
};
|
||||||
@@ -225,11 +225,11 @@ export const LoginWithImage = () => {
|
|||||||
>
|
>
|
||||||
{password.showpass ? (
|
{password.showpass ? (
|
||||||
<span className="material-symbols-rounded">
|
<span className="material-symbols-rounded">
|
||||||
visibility_off
|
visibility
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="material-symbols-rounded">
|
<span className="material-symbols-rounded">
|
||||||
visibility
|
visibility_off
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -369,12 +369,12 @@ export const UserLogin = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sessionStorage.setItem("accessToken", auth.data.AccessToken);
|
sessionStorage.setItem("accessToken", auth.data.AccessToken);
|
||||||
|
createApi(api.basePath, auth.data.AccessToken);
|
||||||
|
|
||||||
if (rememberMe === true) {
|
if (rememberMe === true) {
|
||||||
await saveUser(auth.data.User.Name, auth.data.AccessToken);
|
await saveUser(auth.data.User.Name, auth.data.AccessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.emit("set-api-accessToken", api.basePath);
|
|
||||||
setQuickConnectLoading(-1);
|
setQuickConnectLoading(-1);
|
||||||
enqueueSnackbar(`Logged in as ${auth.data.User.Name}!`, {
|
enqueueSnackbar(`Logged in as ${auth.data.User.Name}!`, {
|
||||||
variant: "success",
|
variant: "success",
|
||||||
@@ -629,10 +629,10 @@ export const UserLoginManual = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
const user = await authUser();
|
const user = await authUser();
|
||||||
sessionStorage.setItem("accessToken", user.data.AccessToken);
|
sessionStorage.setItem("accessToken", user.data.AccessToken);
|
||||||
|
createApi(api.basePath, user.data.AccessToken);
|
||||||
if (rememberMe === true) {
|
if (rememberMe === true) {
|
||||||
await saveUser(userName, user.data.AccessToken);
|
await saveUser(userName, user.data.AccessToken);
|
||||||
}
|
}
|
||||||
event.emit("set-api-accessToken", api.basePath);
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
navigate("/home");
|
navigate("/home");
|
||||||
};
|
};
|
||||||
@@ -713,12 +713,12 @@ export const UserLoginManual = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sessionStorage.setItem("accessToken", auth.data.AccessToken);
|
sessionStorage.setItem("accessToken", auth.data.AccessToken);
|
||||||
|
createApi(api.basePath, auth.data.AccessToken);
|
||||||
|
|
||||||
if (rememberMe === true) {
|
if (rememberMe === true) {
|
||||||
await saveUser(userName, auth.data.AccessToken);
|
await saveUser(userName, auth.data.AccessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.emit("set-api-accessToken", api.basePath);
|
|
||||||
setQuickConnectLoading(-1);
|
setQuickConnectLoading(-1);
|
||||||
enqueueSnackbar(`Logged in as ${auth.data.User.Name}!`, {
|
enqueueSnackbar(`Logged in as ${auth.data.User.Name}!`, {
|
||||||
variant: "success",
|
variant: "success",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import Paper from "@mui/material/Paper";
|
|||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import { red } from "@mui/material/colors";
|
import { red } from "@mui/material/colors";
|
||||||
|
|
||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { AppBarBackOnly } from "../../../components/appBar/backOnly";
|
import { AppBarBackOnly } from "../../../components/appBar/backOnly";
|
||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
setDefaultServer,
|
setDefaultServer,
|
||||||
} from "../../../utils/storage/servers";
|
} from "../../../utils/storage/servers";
|
||||||
import { delUser } from "../../../utils/storage/user";
|
import { delUser } from "../../../utils/storage/user";
|
||||||
|
import { createApi, useApi } from "../../../utils/store/api";
|
||||||
import { setBackdrop } from "../../../utils/store/backdrop";
|
import { setBackdrop } from "../../../utils/store/backdrop";
|
||||||
import "./serverList.module.scss";
|
import "./serverList.module.scss";
|
||||||
|
|
||||||
@@ -26,6 +27,9 @@ const ServerList = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [serverState, setServerState] = useState(null);
|
const [serverState, setServerState] = useState(null);
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const servers = useQuery({
|
const servers = useQuery({
|
||||||
queryKey: ["servers-list"],
|
queryKey: ["servers-list"],
|
||||||
queryFn: async () => await getAllServers(),
|
queryFn: async () => await getAllServers(),
|
||||||
@@ -39,8 +43,11 @@ const ServerList = () => {
|
|||||||
const handleServerChange = useMutation({
|
const handleServerChange = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await delUser();
|
await delUser();
|
||||||
console.log(serverState);
|
await setDefaultServer(serverState.id);
|
||||||
await setDefaultServer(serverState);
|
queryClient.clear();
|
||||||
|
await defaultServer.refetch();
|
||||||
|
createApi(serverState.address);
|
||||||
|
queryClient.removeQueries();
|
||||||
},
|
},
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
navigate("/login/index");
|
navigate("/login/index");
|
||||||
@@ -53,22 +60,26 @@ const ServerList = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleDelete = async (serverId) => {
|
const handleDelete = async (server) => {
|
||||||
await delServer(serverId);
|
await delServer(server.id);
|
||||||
|
|
||||||
if (serverId === defaultServer.data) {
|
if (server.id === defaultServer.data) {
|
||||||
await delUser();
|
await delUser();
|
||||||
await servers.refetch();
|
await servers.refetch();
|
||||||
|
|
||||||
if (servers.length > 0) {
|
if (servers.length > 0) {
|
||||||
setDefaultServer(servers[0].id);
|
setDefaultServer(servers[0].id);
|
||||||
|
createApi(servers[0].address);
|
||||||
} else {
|
} else {
|
||||||
navigate("/login/index");
|
useApi.setState(useApi.getInitialState());
|
||||||
}
|
}
|
||||||
|
queryClient.removeQueries();
|
||||||
|
navigate("/");
|
||||||
}
|
}
|
||||||
|
enqueueSnackbar("Server deleted successfully!", { variant: "success" });
|
||||||
|
|
||||||
servers.refetch();
|
await servers.refetch();
|
||||||
defaultServer.refetch();
|
await defaultServer.refetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
@@ -161,7 +172,7 @@ const ServerList = () => {
|
|||||||
fontSize: "1.64em",
|
fontSize: "1.64em",
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setServerState(server.id);
|
setServerState(server);
|
||||||
handleServerChange.mutate();
|
handleServerChange.mutate();
|
||||||
}}
|
}}
|
||||||
disabled={handleServerChange.isPending}
|
disabled={handleServerChange.isPending}
|
||||||
@@ -176,7 +187,7 @@ const ServerList = () => {
|
|||||||
}}
|
}}
|
||||||
disabled={handleServerChange.isPending}
|
disabled={handleServerChange.isPending}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleDelete(server.id);
|
handleDelete(server);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="material-symbols-rounded">delete_forever</div>
|
<div className="material-symbols-rounded">delete_forever</div>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const getUser = async () => {
|
|||||||
* Delete user from storage
|
* Delete user from storage
|
||||||
*/
|
*/
|
||||||
const delUser = async () => {
|
const delUser = async () => {
|
||||||
|
sessionStorage.removeItem("accessToken");
|
||||||
await user.clear();
|
await user.clear();
|
||||||
await user.save();
|
await user.save();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user