mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
feat: optimize proxy page ui
This commit is contained in:
29
src/hooks/use-profiles.ts
Normal file
29
src/hooks/use-profiles.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import useSWR from "swr";
|
||||
import {
|
||||
getProfiles,
|
||||
patchProfile,
|
||||
patchProfilesConfig,
|
||||
} from "@/services/cmds";
|
||||
|
||||
export const useProfiles = () => {
|
||||
const { data: profiles, mutate } = useSWR("getProfiles", getProfiles);
|
||||
|
||||
const patchProfiles = async (value: Partial<IProfilesConfig>) => {
|
||||
await patchProfilesConfig(value);
|
||||
mutate();
|
||||
};
|
||||
|
||||
const patchCurrent = async (value: Partial<IProfileItem>) => {
|
||||
if (profiles?.current) {
|
||||
await patchProfile(profiles.current, value);
|
||||
mutate();
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
profiles,
|
||||
current: profiles?.items?.find((p) => p.uid === profiles.current),
|
||||
patchProfiles,
|
||||
patchCurrent,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user