feat: refactor commands and support update profile

This commit is contained in:
GyDi
2021-12-18 02:01:02 +08:00
parent c1bcfc6785
commit 98378e6261
9 changed files with 280 additions and 229 deletions

View File

@@ -1,7 +1,12 @@
import { useState } from "react";
import useSWR, { useSWRConfig } from "swr";
import { Box, Button, Grid, TextField, Typography } from "@mui/material";
import { getProfiles, importProfile, putProfiles } from "../services/command";
import {
getProfiles,
importProfile,
putProfiles,
updateProfile,
} from "../services/command";
import ProfileItemComp from "../components/profile-item";
import useNotice from "../utils/use-notice";
@@ -33,6 +38,16 @@ const RulesPage = () => {
});
};
const onUpdateProfile = (index: number) => {
updateProfile(index)
.then(() => {
mutate("getProfiles");
})
.catch((err) => {
console.error(err);
});
};
return (
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
<Typography variant="h4" component="h1" sx={{ py: 2, mb: 1 }}>
@@ -66,6 +81,7 @@ const RulesPage = () => {
selected={profiles.current === idx}
itemData={item}
onClick={() => onProfileChange(idx)}
onUpdate={() => onUpdateProfile(idx)}
/>
</Grid>
))}