Skip to content

Commit

Permalink
feat: update rule page
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzgydi committed Dec 14, 2021
1 parent 65dd6bc commit 1c3ae5c
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/pages/rules.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { useState } from "react";
import { invoke } from "@tauri-apps/api";
import { Box, Button, Grid, TextField, Typography } from "@mui/material";
import {
Box,
Button,
Grid,
Slide,
Snackbar,
TextField,
Typography,
} from "@mui/material";
import { importProfile } from "../services/command";

const RulesPage = () => {
const [url, setUrl] = useState("");
const [message, setMessage] = useState("");
const [disabled, setDisabled] = useState(false);

const onClick = async () => {
const onClick = () => {
if (!url) return;
const data = await invoke("cmd_import_profile", { url });
console.log(data);
setUrl("");
setDisabled(true);
importProfile(url)
.then(() => setMessage("Successfully import profile."))
.catch(() => setMessage("Failed to import profile."))
.finally(() => setDisabled(false));
};

return (
Expand All @@ -26,17 +40,32 @@ const RulesPage = () => {
<Grid item xs={9}>
<TextField
label="Profile Url"
size="medium"
fullWidth
value={url}
onChange={(e) => setUrl(e.target.value)}
/>
</Grid>
<Grid item>
<Button size="large" variant="contained" onClick={onClick}>
View
<Button
disabled={disabled}
size="large"
variant="contained"
onClick={onClick}
>
Import
</Button>
</Grid>
</Grid>

<Snackbar
open={!!message}
anchorOrigin={{ vertical: "top", horizontal: "right" }}
autoHideDuration={3000}
onClose={() => setMessage("")}
message={message}
TransitionComponent={(p) => <Slide {...p} direction="left" />}
/>
</Box>
);
};
Expand Down

0 comments on commit 1c3ae5c

Please sign in to comment.