mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor: profile config
This commit is contained in:
@@ -39,14 +39,14 @@ const round = keyframes`
|
||||
`;
|
||||
|
||||
interface Props {
|
||||
index: number;
|
||||
// index: number;
|
||||
selected: boolean;
|
||||
itemData: CmdType.ProfileItem;
|
||||
onSelect: (force: boolean) => void;
|
||||
}
|
||||
|
||||
const ProfileItem: React.FC<Props> = (props) => {
|
||||
const { index, selected, itemData, onSelect } = props;
|
||||
const { selected, itemData, onSelect } = props;
|
||||
|
||||
const { mutate } = useSWRConfig();
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -69,7 +69,7 @@ const ProfileItem: React.FC<Props> = (props) => {
|
||||
const onView = async () => {
|
||||
setAnchorEl(null);
|
||||
try {
|
||||
await viewProfile(index);
|
||||
await viewProfile(itemData.uid);
|
||||
} catch (err: any) {
|
||||
Notice.error(err.toString());
|
||||
}
|
||||
@@ -85,7 +85,7 @@ const ProfileItem: React.FC<Props> = (props) => {
|
||||
if (loading) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
await updateProfile(index, withProxy);
|
||||
await updateProfile(itemData.uid, withProxy);
|
||||
mutate("getProfiles");
|
||||
} catch (err: any) {
|
||||
Notice.error(err.toString());
|
||||
@@ -98,7 +98,7 @@ const ProfileItem: React.FC<Props> = (props) => {
|
||||
setAnchorEl(null);
|
||||
|
||||
try {
|
||||
await deleteProfile(index);
|
||||
await deleteProfile(itemData.uid);
|
||||
mutate("getProfiles");
|
||||
} catch (err: any) {
|
||||
Notice.error(err.toString());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import useSWR, { useSWRConfig } from "swr";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useSWRConfig } from "swr";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { Virtuoso } from "react-virtuoso";
|
||||
import {
|
||||
@@ -46,6 +46,8 @@ const ProxyGroup = ({ group }: Props) => {
|
||||
const virtuosoRef = useRef<any>();
|
||||
const filterProxies = useFilterProxy(proxies, group.name, filterText);
|
||||
|
||||
const { data: profiles } = useSWR("getProfiles", getProfiles);
|
||||
|
||||
const onChangeProxy = useLockFn(async (name: string) => {
|
||||
// Todo: support another proxy group type
|
||||
if (group.type !== "Selector") return;
|
||||
@@ -60,8 +62,7 @@ const ProxyGroup = ({ group }: Props) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const profiles = await getProfiles();
|
||||
const profile = profiles.items![profiles.current!]!;
|
||||
const profile = profiles?.items?.find((p) => p.uid === profiles.current);
|
||||
if (!profile) return;
|
||||
if (!profile.selected) profile.selected = [];
|
||||
|
||||
@@ -74,7 +75,7 @@ const ProxyGroup = ({ group }: Props) => {
|
||||
} else {
|
||||
profile.selected[index] = { name: group.name, now: name };
|
||||
}
|
||||
await patchProfile(profiles.current!, profile);
|
||||
await patchProfile(profiles!.current!, profile);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user