summaryrefslogtreecommitdiff
path: root/src/modules/rules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/rules')
-rw-r--r--src/modules/rules/hooks.ts18
-rw-r--r--src/modules/rules/utils.ts2
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;
};
}