diff options
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/rules/hooks.ts | 18 | ||||
| -rw-r--r-- | src/modules/rules/utils.ts | 2 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/modules/rules/hooks.ts b/src/modules/rules/hooks.ts index e13ea65..20c675e 100644 --- a/src/modules/rules/hooks.ts +++ b/src/modules/rules/hooks.ts @@ -7,7 +7,7 @@ import { refreshRuleProviderByName, updateRuleProviders, } from '~/api/rule-provider'; -import { fetchRules } from '~/api/rules'; +import { fetchRules, updateRuleDisabledStatus } from '~/api/rules'; import { ruleFilterText } from '~/store/rules'; import type { ClashAPIConfig } from '~/types'; @@ -49,6 +49,22 @@ export function useUpdateAllRuleProviderItems( return [onClickRefreshButton, isPending]; } +export function useToggleRuleDisabled(apiConfig: ClashAPIConfig) { + const queryClient = useQueryClient(); + const { mutate, isPending } = useMutation({ + mutationFn: ({ index, disabled }: { index: number; disabled: boolean }) => + updateRuleDisabledStatus(apiConfig, { [index]: disabled }), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['/rules'] }); + }, + }); + const toggleRule = useCallback( + (index: number, disabled: boolean) => mutate({ index, disabled }), + [mutate] + ); + return { toggleRule, isPending }; +} + export function useInvalidateQueries() { const queryClient = useQueryClient(); return useCallback(() => { diff --git a/src/modules/rules/utils.ts b/src/modules/rules/utils.ts index c1d1464..8ce0fc1 100644 --- a/src/modules/rules/utils.ts +++ b/src/modules/rules/utils.ts @@ -15,7 +15,7 @@ export function itemKey(index: number, { rules, provider }: RulesListItemData) { export function getItemSizeFactory({ isRulesTab }: { isRulesTab: boolean }) { return function getItemSize() { - return isRulesTab ? 70 : 100; + return isRulesTab ? 88 : 100; }; } |
