|
@@ -1,14 +1,18 @@
|
|
import { useState } from "react";
|
|
import { useState } from "react";
|
|
-import { Box, Button, TextField, Typography } from "@mui/material";
|
|
|
|
-import { importProfile } from "../services/command";
|
|
|
|
|
|
+import useSWR, { useSWRConfig } from "swr";
|
|
|
|
+import { Box, Button, Grid, TextField, Typography } from "@mui/material";
|
|
|
|
+import { getProfiles, importProfile, putProfiles } from "../services/command";
|
|
|
|
+import ProfileItemComp from "../components/profile-item";
|
|
import useNotice from "../utils/use-notice";
|
|
import useNotice from "../utils/use-notice";
|
|
|
|
|
|
const RulesPage = () => {
|
|
const RulesPage = () => {
|
|
const [url, setUrl] = useState("");
|
|
const [url, setUrl] = useState("");
|
|
const [disabled, setDisabled] = useState(false);
|
|
const [disabled, setDisabled] = useState(false);
|
|
-
|
|
|
|
const [notice, noticeElement] = useNotice();
|
|
const [notice, noticeElement] = useNotice();
|
|
|
|
|
|
|
|
+ const { mutate } = useSWRConfig();
|
|
|
|
+ const { data: profiles = {} } = useSWR("getProfiles", getProfiles);
|
|
|
|
+
|
|
const onClick = () => {
|
|
const onClick = () => {
|
|
if (!url) return;
|
|
if (!url) return;
|
|
setUrl("");
|
|
setUrl("");
|
|
@@ -19,14 +23,26 @@ const RulesPage = () => {
|
|
.finally(() => setDisabled(false));
|
|
.finally(() => setDisabled(false));
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const onProfileChange = (index: number) => {
|
|
|
|
+ putProfiles(index)
|
|
|
|
+ .then(() => {
|
|
|
|
+ mutate("getProfiles", { ...profiles, current: index }, true);
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => {
|
|
|
|
+ console.error(err);
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
|
|
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
|
|
<Typography variant="h4" component="h1" sx={{ py: 2, mb: 1 }}>
|
|
<Typography variant="h4" component="h1" sx={{ py: 2, mb: 1 }}>
|
|
Rules
|
|
Rules
|
|
</Typography>
|
|
</Typography>
|
|
|
|
|
|
- <Box sx={{ display: "flex" }}>
|
|
|
|
|
|
+ <Box sx={{ display: "flex", mb: 3 }}>
|
|
<TextField
|
|
<TextField
|
|
|
|
+ id="profile_url"
|
|
|
|
+ name="profile_url"
|
|
label="Profile URL"
|
|
label="Profile URL"
|
|
size="small"
|
|
size="small"
|
|
fullWidth
|
|
fullWidth
|
|
@@ -34,11 +50,27 @@ const RulesPage = () => {
|
|
onChange={(e) => setUrl(e.target.value)}
|
|
onChange={(e) => setUrl(e.target.value)}
|
|
sx={{ mr: 4 }}
|
|
sx={{ mr: 4 }}
|
|
/>
|
|
/>
|
|
- <Button disabled={disabled} variant="contained" onClick={onClick}>
|
|
|
|
|
|
+ <Button
|
|
|
|
+ disabled={!url || disabled}
|
|
|
|
+ variant="contained"
|
|
|
|
+ onClick={onClick}
|
|
|
|
+ >
|
|
Import
|
|
Import
|
|
</Button>
|
|
</Button>
|
|
</Box>
|
|
</Box>
|
|
|
|
|
|
|
|
+ <Grid container spacing={3}>
|
|
|
|
+ {profiles?.items?.map((item, idx) => (
|
|
|
|
+ <Grid item xs={12} sm={6} key={item.file}>
|
|
|
|
+ <ProfileItemComp
|
|
|
|
+ selected={profiles.current === idx}
|
|
|
|
+ itemData={item}
|
|
|
|
+ onClick={() => onProfileChange(idx)}
|
|
|
|
+ />
|
|
|
|
+ </Grid>
|
|
|
|
+ ))}
|
|
|
|
+ </Grid>
|
|
|
|
+
|
|
{noticeElement}
|
|
{noticeElement}
|
|
</Box>
|
|
</Box>
|
|
);
|
|
);
|