clash-verge/src/pages/rules.tsx

74 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-12-12 21:30:34 +03:00
import { useState } from "react";
2021-12-14 20:54:06 +03:00
import {
Box,
Button,
Grid,
Slide,
Snackbar,
TextField,
Typography,
} from "@mui/material";
import { importProfile } from "../services/command";
2021-12-11 20:09:51 +03:00
const RulesPage = () => {
2021-12-12 21:30:34 +03:00
const [url, setUrl] = useState("");
2021-12-14 20:54:06 +03:00
const [message, setMessage] = useState("");
const [disabled, setDisabled] = useState(false);
2021-12-12 21:30:34 +03:00
2021-12-14 20:54:06 +03:00
const onClick = () => {
2021-12-12 21:30:34 +03:00
if (!url) return;
2021-12-14 20:54:06 +03:00
setUrl("");
setDisabled(true);
importProfile(url)
.then(() => setMessage("Successfully import profile."))
.catch(() => setMessage("Failed to import profile."))
.finally(() => setDisabled(false));
2021-12-12 21:30:34 +03:00
};
2021-12-11 20:09:51 +03:00
return (
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
<Typography variant="h4" component="h1" sx={{ py: 2 }}>
Rules
</Typography>
2021-12-12 21:30:34 +03:00
<Grid
container
spacing={2}
justifyContent="space-between"
alignItems="center"
>
<Grid item xs={9}>
<TextField
label="Profile Url"
2021-12-14 20:54:06 +03:00
size="medium"
2021-12-12 21:30:34 +03:00
fullWidth
value={url}
onChange={(e) => setUrl(e.target.value)}
/>
</Grid>
<Grid item>
2021-12-14 20:54:06 +03:00
<Button
disabled={disabled}
size="large"
variant="contained"
onClick={onClick}
>
Import
2021-12-12 21:30:34 +03:00
</Button>
</Grid>
</Grid>
2021-12-14 20:54:06 +03:00
<Snackbar
open={!!message}
anchorOrigin={{ vertical: "top", horizontal: "right" }}
autoHideDuration={3000}
onClose={() => setMessage("")}
message={message}
TransitionComponent={(p) => <Slide {...p} direction="left" />}
/>
2021-12-11 20:09:51 +03:00
</Box>
);
};
export default RulesPage;