feat(web): Allow managing servers from settings dialog

This commit is contained in:
Prayag Prajapati committed 2024-02-17 23:40:22 +05:30
1 parent b155daa83b
commit faf3dc2a48
5 files changed
+556 -168

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
- # v0.0.5-dev - # v0.0.5-dev
> **Note** : This is an unstable release > **Note** : This is an unstable release
- feat(web): Add new About page (#258) by @prayag17 - feat(web): Add new About page (#258) by @prayag17
- feat(web): Allow managing servers from settings dialog by @prayag17
+1 -1
View File
@@ -505,7 +505,7 @@ function AppReady() {
</ErrorBoundary> </ErrorBoundary>
</div> </div>
<ReactQueryDevtools buttonPosition="bottom-right" /> <ReactQueryDevtools buttonPosition="bottom-right" position="right" />
</ThemeProvider> </ThemeProvider>
</SnackbarProvider> </SnackbarProvider>
); );
+15 -18
View File
@@ -35,6 +35,7 @@ import { useApi } from "../../utils/store/api";
import { getTypeIcon } from "../utils/iconsCollection"; import { getTypeIcon } from "../utils/iconsCollection";
import { Divider } from "@mui/material";
import logo from "../../assets/icon.svg"; import logo from "../../assets/icon.svg";
import { import {
setSettingsDialogOpen, setSettingsDialogOpen,
@@ -384,10 +385,23 @@ export const AppBar = () => {
sx={{ mt: 2 }} sx={{ mt: 2 }}
disableScrollLock disableScrollLock
> >
<MenuItem
onClick={() => {
handleLogout();
handleMenuClose();
}}
>
<ListItemIcon>
<div className="material-symbols-rounded">logout</div>
</ListItemIcon>
Logout
</MenuItem>
<Divider />
<MenuItem <MenuItem
onClick={() => { onClick={() => {
setSettingsDialogOpen(true); setSettingsDialogOpen(true);
setSettingsTabValue(1); setSettingsTabValue(1);
handleMenuClose();
}} }}
> >
<ListItemIcon> <ListItemIcon>
@@ -399,6 +413,7 @@ export const AppBar = () => {
onClick={() => { onClick={() => {
setSettingsDialogOpen(true); setSettingsDialogOpen(true);
setSettingsTabValue(10); setSettingsTabValue(10);
handleMenuClose();
}} }}
> >
<ListItemIcon> <ListItemIcon>
@@ -406,24 +421,6 @@ export const AppBar = () => {
</ListItemIcon> </ListItemIcon>
About About
</MenuItem> </MenuItem>
<MenuItem onClick={handleLogout}>
<ListItemIcon>
<div className="material-symbols-rounded">logout</div>
</ListItemIcon>
Logout
</MenuItem>
<MenuItem
onClick={async () => {
navigate("/servers/list");
}}
>
<ListItemIcon>
<div className="material-symbols-rounded appBar-icon">
dns
</div>
</ListItemIcon>
Select Server
</MenuItem>
</Menu> </Menu>
</div> </div>
</Toolbar> </Toolbar>
+483 -148
View File
@@ -1,12 +1,19 @@
import { import {
Button,
Chip, Chip,
Dialog, Dialog,
DialogActions,
DialogContent,
DialogTitle,
Fab,
FormControlLabel, FormControlLabel,
IconButton,
Link, Link,
Skeleton, Skeleton,
Switch, Switch,
Tab, Tab,
Tabs, Tabs,
TextField,
Typography, Typography,
styled, styled,
withStyles, withStyles,
@@ -21,33 +28,36 @@ import useSettingsStore, {
import logo from "../../assets/logoBlack.png"; 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 { useQuery } from "@tanstack/react-query"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useApi } from "../../utils/store/api"; import { 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 { LoadingButton } from "@mui/lab"; import { LoadingButton } from "@mui/lab";
import { red } 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";
import { useNavigate } from "react-router-dom";
import {
delServer,
getDefaultServer,
setDefaultServer,
setServer,
} from "../../utils/storage/servers";
import { delUser } from "../../utils/storage/user";
const motionConfig = { const motionConfig = {
forward: { initial: {
opacity: 0, opacity: 0,
transform: "translateY(-20px)",
}, },
visible: { visible: {
opacity: 1, opacity: 1,
transform: "translateY(0px)",
},
backward: {
opacity: 0,
transform: "translateY(20px)",
}, },
}; };
const Settings = () => { const Settings = () => {
const [api] = useApi((state) => [state.api]); const [api, jellyfin] = useApi((state) => [state.api, state.jellyfin]);
const systemInfo = useQuery({ const systemInfo = useQuery({
queryKey: ["about", "systemInfo"], queryKey: ["about", "systemInfo"],
queryFn: async () => { queryFn: async () => {
@@ -57,6 +67,18 @@ const Settings = () => {
enabled: Boolean(api), enabled: Boolean(api),
}); });
const navigate = useNavigate();
const [applicationVersion, serversOnDiskFn] = useCentralStore((state) => [
state.clientVersion,
state.allServersOnDisk,
]);
const serversOnDisk = useQuery({
queryKey: ["settings", "serversOnDisk"],
queryFn: serversOnDiskFn,
});
const updateInfo = useQuery({ const updateInfo = useQuery({
queryKey: ["about", "updater"], queryKey: ["about", "updater"],
queryFn: async () => { queryFn: async () => {
@@ -65,6 +87,11 @@ const Settings = () => {
}, },
}); });
const defaultServer = useQuery({
queryKey: ["settings", "default-server"],
queryFn: async () => await getDefaultServer(),
});
const { enqueueSnackbar } = useSnackbar(); const { enqueueSnackbar } = useSnackbar();
const [open, tabValue] = useSettingsStore((state) => [ const [open, tabValue] = useSettingsStore((state) => [
@@ -72,12 +99,80 @@ const Settings = () => {
state.tabValue, state.tabValue,
]); ]);
const [applicationVersion] = useCentralStore((state) => [ const queryClient = useQueryClient();
state.clientVersion,
]);
const [updating, setUpdating] = useState(false); const [updating, setUpdating] = useState(false);
const [animDirection, setAnimDirection] = useState("forward"); const [animDirection, setAnimDirection] = useState("forward");
const [serverState, setServerState] = useState("");
const [ask, setAsk] = useState(false);
const [action, setAction] = useState(null);
const [addServerDialog, setAddServerDialog] = useState(false);
const [serverIp, setServerIp] = useState("");
const handleServerChange = useMutation({
mutationFn: async () => {
await delUser();
localStorage.clear();
await setDefaultServer(serverState);
},
onSuccess: async () => {
await relaunch();
},
onError: (error) => {
console.error(error);
enqueueSnackbar("Error changing the server", {
variant: "error",
});
},
});
const handleDelete = async (serverId: string) => {
await delServer(serverId);
if (serverId === defaultServer.data) {
await delUser();
await serversOnDisk.refetch();
if (serversOnDisk.data?.length > 0) {
setDefaultServer(serversOnDisk.data[0].id);
}
}
setSettingsDialogOpen(false);
await relaunch();
};
const checkServer = useMutation({
mutationFn: async () => {
const servers =
await jellyfin.discovery.getRecommendedServerCandidates(serverIp);
const bestServer = jellyfin.discovery.findBestServer(servers);
return bestServer;
},
onSuccess: (bestServer) => {
if (bestServer) {
setServer(bestServer.systemInfo.Id, bestServer);
setAddServerDialog(false);
serversOnDisk.refetch();
enqueueSnackbar("Client added successfully", {
variant: "success",
});
}
},
onError: (err) => {
console.error(err);
enqueueSnackbar(`${err}`, { variant: "error" });
enqueueSnackbar("Something went wrong", { variant: "error" });
},
onSettled: (bestServer) => {
console.log(bestServer);
if (!bestServer) {
enqueueSnackbar("Provided server address is not a Jellyfin server.", {
variant: "error",
});
}
},
});
return ( return (
<Dialog <Dialog
@@ -93,10 +188,14 @@ 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) { if (newValue > tabValue) {
setAnimDirection("backward"); console.log("forward");
} else {
setAnimDirection("forward"); setAnimDirection("forward");
} else {
console.log("backward");
setAnimDirection("backward");
} }
setSettingsTabValue(newValue); setSettingsTabValue(newValue);
}} }}
@@ -115,6 +214,17 @@ const Settings = () => {
height: "48px", height: "48px",
}} }}
/> />
<Tab
icon={<span className="material-symbols-rounded">dns</span>}
iconPosition="start"
value={2}
label="Servers"
className="settings-tab"
sx={{
minHeight: "48px",
height: "48px",
}}
/>
<Tab <Tab
icon={<span className="material-symbols-rounded">info</span>} icon={<span className="material-symbols-rounded">info</span>}
iconPosition="start" iconPosition="start"
@@ -124,152 +234,22 @@ const Settings = () => {
sx={{ sx={{
minHeight: "48px", minHeight: "48px",
height: "48px", height: "48px",
marginTop: "auto",
}} }}
/> />
</Tabs> </Tabs>
<AnimatePresence mode="wait"> <AnimatePresence mode="wait">
<motion.div <motion.div
variants={motionConfig} variants={motionConfig}
initial={animDirection === "backward" ? "backward" : "forward"} initial="initial"
animate="visible" animate="visible"
exit={animDirection === "backward" ? "backward" : "forward"} exit="initial"
key={tabValue} key={tabValue}
transition={{ transition={{
duration: 0.1, duration: 0.25,
}} }}
className="settings-scroll " className="settings-scroll "
> >
{/* About */}
{tabValue === 10 && (
<div className="settings-container settings-about">
<img src={logo} className="settings-logo" alt="JellyPlayer" />
<div className="settings-grid">
<div className="settings-info-container">
<div className="settings-info">
<Typography>Client Version:</Typography>
<Chip
icon={
<span className="material-symbols-rounded">
{updateInfo.data?.shouldUpdate
? "update"
: "update_disabled"}
</span>
}
label={
<Typography variant="subtitle1">
{applicationVersion}
</Typography>
}
color={
updateInfo.data?.shouldUpdate ? "error" : "success"
}
size="medium"
style={{
width: "fit-content !important",
}}
/>
</div>
<div className="settings-info">
<Typography>Update Available:</Typography>
<Typography>
{updateInfo.isFetching
? "Checking for new updates..."
: updateInfo.data?.shouldUpdate
? updateInfo.data.manifest?.version
: "No update found."}
</Typography>
</div>
<LoadingButton
style={{
marginTop: "auto",
}}
loading={updateInfo.isFetching || updating}
variant="contained"
disabled={!updateInfo.data?.shouldUpdate}
loadingPosition="start"
onClick={async () => {
if (updateInfo.data?.shouldUpdate) {
setUpdating(true);
await installUpdate();
enqueueSnackbar(
"Update has been installed! You need to relaunch JellyPlayer.",
{
variant: "success",
},
);
await relaunch();
}
}}
>
{updateInfo.isFetching
? "Checking for Update..."
: updateInfo.data?.shouldUpdate
? "Update"
: "No Update Found"}
</LoadingButton>
</div>
{systemInfo.isSuccess ? (
<div className="settings-info-container">
<div className="settings-info">
<Typography>Server:</Typography>
<Typography>{systemInfo.data?.ServerName}</Typography>
</div>
<div className="settings-info">
<Typography>Jellyfin Version:</Typography>
<Typography>{systemInfo.data?.Version}</Typography>
</div>
<div className="settings-info">
<Typography>Operating System:</Typography>
<Typography>
{systemInfo.data?.OperatingSystemDisplayName}
</Typography>
</div>
<div className="settings-info">
<Typography>Server Architecture:</Typography>
<Typography>
{systemInfo.data?.SystemArchitecture}
</Typography>
</div>
</div>
) : (
<Skeleton
variant="rectangular"
sx={{
height: "100%",
borderRadius: "10px",
}}
/>
)}
</div>
<div
style={{
marginTop: "1em",
background: "rgb(0 0 0 / 0.3)",
padding: "1em",
borderRadius: "10px",
border: "1px solid rgb(255 255 255 / 0.1)",
}}
>
<Typography variant="h6" fontWeight={300} mb={1}>
Links:
</Typography>
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
gap: "0.1em",
}}
>
<Link href="https://github.com/prayag17/JellyPlayer">
https://github.com/prayag17/JellyPlayer
</Link>
<Link href="https://jellyfin.org">https://jellyfin.org</Link>
</div>
</div>
</div>
)}
{/* General */} {/* General */}
{tabValue === 1 && ( {tabValue === 1 && (
<div className="settings-container"> <div className="settings-container">
@@ -515,8 +495,363 @@ const Settings = () => {
/> />
</div> </div>
)} )}
{/* Server */}
{tabValue === 2 && (
<div className="settings-container settings-server-container">
{serversOnDisk.isSuccess &&
serversOnDisk.data.map((server) => {
return (
<div className="settings-server">
<span className="material-symbols-rounded settings-server-icon">
dns
</span>
<div className="settings-server-info">
<Typography
variant="h5"
style={{
display: "flex",
alignItems: "center",
}}
>
{server.systemInfo?.ServerName}
{systemInfo.data?.Id === server.id && (
<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">
{server.address}
</Typography>
<Typography
variant="subtitle2"
className="settings-server-info-version"
>
Version:{" "}
<Typography
className="gradient-text"
variant="subtitle2"
fontWeight={700}
>
{server.systemInfo?.Version}
</Typography>
</Typography>
</div>
<div className="settings-buttons">
<IconButton
style={{
fontSize: "1.64em",
}}
onClick={() => {
setAsk(true);
setAction("change-server");
setServerState(server.id);
}}
disabled={handleServerChange.isPending}
>
<div className="material-symbols-rounded">start</div>
</IconButton>
<IconButton
style={{
fontSize: "1.64em",
color: red[400],
}}
disabled={handleServerChange.isPending}
onClick={() => {
setAsk(true);
setAction("delete-server");
setServerState(server.id);
}}
>
<div className="material-symbols-rounded">
delete_forever
</div>
</IconButton>
</div>
</div>
);
})}
<Fab
variant="extended"
onClick={() => setAddServerDialog(true)}
style={{
position: "absolute",
bottom: "20px",
right: "20px",
}}
>
<span
className="material-symbols-rounded"
style={{
marginRight: "0.25em",
fontVariationSettings:
'"FILL" 1, "wght" 300, "GRAD" 25, "opsz" 40',
}}
>
add_circle
</span>
Add server
</Fab>
</div>
)}
{/* About */}
{tabValue === 10 && (
<div className="settings-container settings-about">
<img src={logo} className="settings-logo" alt="JellyPlayer" />
<div className="settings-grid">
<div className="settings-info-container">
<div className="settings-info">
<Typography>Client Version:</Typography>
<Chip
icon={
<span className="material-symbols-rounded">
{updateInfo.data?.shouldUpdate
? "update"
: "update_disabled"}
</span>
}
label={
<Typography variant="subtitle1">
{applicationVersion}
</Typography>
}
color={
updateInfo.data?.shouldUpdate ? "error" : "success"
}
size="medium"
style={{
width: "fit-content !important",
}}
/>
</div>
<div className="settings-info">
<Typography>Update Available:</Typography>
<Typography>
{updateInfo.isFetching
? "Checking for new updates..."
: updateInfo.data?.shouldUpdate
? updateInfo.data.manifest?.version
: "No update found."}
</Typography>
</div>
<LoadingButton
style={{
marginTop: "auto",
}}
loading={updateInfo.isFetching || updating}
variant="contained"
disabled={!updateInfo.data?.shouldUpdate}
loadingPosition="start"
onClick={async () => {
if (updateInfo.data?.shouldUpdate) {
setUpdating(true);
await installUpdate();
enqueueSnackbar(
"Update has been installed! You need to relaunch JellyPlayer.",
{
variant: "success",
},
);
await relaunch();
}
}}
>
{updateInfo.isFetching
? "Checking for Update..."
: updateInfo.data?.shouldUpdate
? "Update"
: "No Update Found"}
</LoadingButton>
</div>
{systemInfo.isSuccess ? (
<div className="settings-info-container">
<div className="settings-info">
<Typography>Server:</Typography>
<Typography>{systemInfo.data?.ServerName}</Typography>
</div>
<div className="settings-info">
<Typography>Jellyfin Version:</Typography>
<Typography>{systemInfo.data?.Version}</Typography>
</div>
<div className="settings-info">
<Typography>Operating System:</Typography>
<Typography>
{systemInfo.data?.OperatingSystemDisplayName}
</Typography>
</div>
<div className="settings-info">
<Typography>Server Architecture:</Typography>
<Typography>
{systemInfo.data?.SystemArchitecture}
</Typography>
</div>
</div>
) : (
<Skeleton
variant="rectangular"
sx={{
height: "100%",
borderRadius: "10px",
}}
/>
)}
</div>
<div
style={{
marginTop: "1em",
background: "rgb(0 0 0 / 0.3)",
padding: "1em",
borderRadius: "10px",
border: "1px solid rgb(255 255 255 / 0.1)",
}}
>
<Typography variant="h6" fontWeight={300} mb={1}>
Links:
</Typography>
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
gap: "0.1em",
}}
>
<Link
target="_blank"
href="https://github.com/prayag17/JellyPlayer"
>
https://github.com/prayag17/JellyPlayer
</Link>
<Link target="_blank" href="https://jellyfin.org">
https://jellyfin.org
</Link>
</div>
</div>
</div>
)}
</motion.div> </motion.div>
</AnimatePresence> </AnimatePresence>
{/* Show dialog before deleting or changing server */}
<Dialog open={ask} fullWidth maxWidth="xs">
<DialogTitle>Are you sure?</DialogTitle>
<DialogContent style={{ opacity: 0.8 }}>
JellyPlayer will relaunch.
</DialogContent>
<DialogActions
style={{
alignItems: "center",
justifyContent: "center",
padding: "1em",
gap: "1em",
}}
>
<Button
variant="contained"
color="error"
fullWidth
onClick={() => setAsk(false)}
>
No
</Button>
<Button
variant="contained"
color="success"
fullWidth
style={{
margin: 0,
}}
onClick={() => {
if (action === "change-server") {
handleServerChange.mutate();
} else if (action === "delete-server") {
handleDelete(serverState);
}
}}
>
yes
</Button>
</DialogActions>
</Dialog>
{/* Add Server */}
<Dialog open={addServerDialog} fullWidth>
<DialogTitle>Add Server</DialogTitle>
<DialogContent className="settings-server-add">
<TextField
variant="filled"
label="Address"
fullWidth
onChange={(e) => setServerIp(e.target.value)}
/>
</DialogContent>
<DialogActions
style={{
alignItems: "center",
justifyContent: "center",
padding: "1em",
gap: "1em",
}}
>
<Button
variant="contained"
startIcon={
<span
className="material-symbols-rounded"
style={{
marginRight: "0.25em",
fontVariationSettings:
'"FILL" 1, "wght" 300, "GRAD" 25, "opsz" 40',
}}
>
cancel
</span>
}
color="error"
onClick={() => setAddServerDialog(false)}
>
Close
</Button>
<LoadingButton
startIcon={
<span
className="material-symbols-rounded"
style={{
marginRight: "0.25em",
fontVariationSettings:
'"FILL" 1, "wght" 300, "GRAD" 25, "opsz" 40',
}}
>
add_circle
</span>
}
variant="contained"
loading={checkServer.isPending}
loadingPosition="start"
onClick={checkServer.mutate}
color="success"
>
Add
</LoadingButton>
</DialogActions>
</Dialog>
</Dialog> </Dialog>
); );
}; };
+56 -1
View File
@@ -4,8 +4,11 @@
height: 60vh; height: 60vh;
overflow: hidden !important; overflow: hidden !important;
.MuiTabs-flexContainerVertical{
height: 100%;
}
&-container{ &-container{
margin: 14px 0em 14px 14px; margin: 14px 0 14px 14px;
} }
&-tab{ &-tab{
display: grid !important; display: grid !important;
@@ -21,6 +24,7 @@
&-scroll{ &-scroll{
overflow-y: auto; overflow-y: auto;
mask-image: linear-gradient(to top, transparent, black 15px calc(100% - 15px), transparent); mask-image: linear-gradient(to top, transparent, black 15px calc(100% - 15px), transparent);
scrollbar-gutter:stable ;
// Magic scrollbar // Magic scrollbar
&::-webkit-scrollbar { &::-webkit-scrollbar {
&-thumb { &-thumb {
@@ -75,7 +79,58 @@
width: 100%; width: 100%;
padding: 0 !important; padding: 0 !important;
margin: 0 0 0.4em 0!important; margin: 0 0 0.4em 0!important;
}
//serverList
&-server{
&-container{
display: flex;
flex-direction: column;
gap: 1em;
align-items: center;
padding-bottom: 4.6em;
}
display: grid;
grid-template-columns: 3.4em 1fr auto;
justify-items: start;
align-items: center;
gap: 0.8em;
background: rgb(0 0 0 / 0.3);
padding: 1em;
width: 100%;
border-radius: $border-radius-default;
&-icon {
font-size: 3.4em !important;
font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 10, "opsz" 40;
}
&-info {
display: flex;
flex-direction: column;
// width: 100%;
&-version {
display: flex;
align-items: center;
gap:0.4em;
}
}
&-buttons {
display: flex;
flex-direction: row;
gap: 0.5em;
// width: 100%;
overflow: hidden;
}
// Dialog
&-add {
display: flex;
flex-direction: column;
align-items: center;
gap: 1em;
}
} }
} }