fix: clash field state error
This commit is contained in:
parent
7f321c89cb
commit
2f8146b11f
@ -46,8 +46,11 @@ const handleFields = [...HANDLE_FIELDS, ...DEFAULT_FIELDS].sort(fieldSorter);
|
|||||||
const ClashFieldViewer = ({ handler }: Props) => {
|
const ClashFieldViewer = ({ handler }: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { data, mutate } = useSWR("getProfiles", getProfiles);
|
const { data: profiles = {}, mutate: mutateProfile } = useSWR(
|
||||||
const { data: existsKeys = [] } = useSWR(
|
"getProfiles",
|
||||||
|
getProfiles
|
||||||
|
);
|
||||||
|
const { data: existsKeys = [], mutate: mutateExists } = useSWR(
|
||||||
"getRuntimeExists",
|
"getRuntimeExists",
|
||||||
getRuntimeExists
|
getRuntimeExists
|
||||||
);
|
);
|
||||||
@ -63,12 +66,12 @@ const ClashFieldViewer = ({ handler }: Props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open) mutate();
|
if (open) {
|
||||||
}, [open]);
|
mutateProfile();
|
||||||
|
mutateExists();
|
||||||
useEffect(() => {
|
setSelected(profiles.valid || []);
|
||||||
setSelected(data?.valid || []);
|
}
|
||||||
}, [data?.valid]);
|
}, [open, profiles.valid]);
|
||||||
|
|
||||||
const handleChange = (item: string) => {
|
const handleChange = (item: string) => {
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
@ -81,7 +84,7 @@ const ClashFieldViewer = ({ handler }: Props) => {
|
|||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
|
||||||
const oldSet = new Set(data?.valid || []);
|
const oldSet = new Set(profiles.valid || []);
|
||||||
const curSet = new Set(selected);
|
const curSet = new Set(selected);
|
||||||
const joinSet = new Set(selected.concat([...oldSet]));
|
const joinSet = new Set(selected.concat([...oldSet]));
|
||||||
|
|
||||||
@ -89,7 +92,7 @@ const ClashFieldViewer = ({ handler }: Props) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await changeProfileValid([...curSet]);
|
await changeProfileValid([...curSet]);
|
||||||
mutate();
|
mutateProfile();
|
||||||
Notice.success("Refresh clash config", 1000);
|
Notice.success("Refresh clash config", 1000);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
Notice.error(err?.message || err.toString());
|
Notice.error(err?.message || err.toString());
|
||||||
@ -112,7 +115,6 @@ const ClashFieldViewer = ({ handler }: Props) => {
|
|||||||
{otherFields.map((item) => {
|
{otherFields.map((item) => {
|
||||||
const inSelect = selected.includes(item);
|
const inSelect = selected.includes(item);
|
||||||
const inConfig = existsKeys.includes(item);
|
const inConfig = existsKeys.includes(item);
|
||||||
const inValid = data?.valid?.includes(item);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack key={item} mb={0.5} direction="row" alignItems="center">
|
<Stack key={item} mb={0.5} direction="row" alignItems="center">
|
||||||
@ -124,7 +126,7 @@ const ClashFieldViewer = ({ handler }: Props) => {
|
|||||||
/>
|
/>
|
||||||
<Typography width="100%">{item}</Typography>
|
<Typography width="100%">{item}</Typography>
|
||||||
|
|
||||||
{!inSelect && inConfig && !inValid && <WarnIcon />}
|
{!inSelect && inConfig && <WarnIcon />}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
Loading…
Reference in New Issue
Block a user