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

+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;
}
}
}