feat: update rule page
This commit is contained in:
parent
65dd6bc6a6
commit
1c3ae5c4bc
@ -1,14 +1,28 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { invoke } from "@tauri-apps/api";
|
import {
|
||||||
import { Box, Button, Grid, TextField, Typography } from "@mui/material";
|
Box,
|
||||||
|
Button,
|
||||||
|
Grid,
|
||||||
|
Slide,
|
||||||
|
Snackbar,
|
||||||
|
TextField,
|
||||||
|
Typography,
|
||||||
|
} from "@mui/material";
|
||||||
|
import { importProfile } from "../services/command";
|
||||||
|
|
||||||
const RulesPage = () => {
|
const RulesPage = () => {
|
||||||
const [url, setUrl] = useState("");
|
const [url, setUrl] = useState("");
|
||||||
|
const [message, setMessage] = useState("");
|
||||||
|
const [disabled, setDisabled] = useState(false);
|
||||||
|
|
||||||
const onClick = async () => {
|
const onClick = () => {
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
const data = await invoke("cmd_import_profile", { url });
|
setUrl("");
|
||||||
console.log(data);
|
setDisabled(true);
|
||||||
|
importProfile(url)
|
||||||
|
.then(() => setMessage("Successfully import profile."))
|
||||||
|
.catch(() => setMessage("Failed to import profile."))
|
||||||
|
.finally(() => setDisabled(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -26,17 +40,32 @@ const RulesPage = () => {
|
|||||||
<Grid item xs={9}>
|
<Grid item xs={9}>
|
||||||
<TextField
|
<TextField
|
||||||
label="Profile Url"
|
label="Profile Url"
|
||||||
|
size="medium"
|
||||||
fullWidth
|
fullWidth
|
||||||
value={url}
|
value={url}
|
||||||
onChange={(e) => setUrl(e.target.value)}
|
onChange={(e) => setUrl(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<Button size="large" variant="contained" onClick={onClick}>
|
<Button
|
||||||
View
|
disabled={disabled}
|
||||||
|
size="large"
|
||||||
|
variant="contained"
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
Import
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
<Snackbar
|
||||||
|
open={!!message}
|
||||||
|
anchorOrigin={{ vertical: "top", horizontal: "right" }}
|
||||||
|
autoHideDuration={3000}
|
||||||
|
onClose={() => setMessage("")}
|
||||||
|
message={message}
|
||||||
|
TransitionComponent={(p) => <Slide {...p} direction="left" />}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user