diff options
| author | Larvan2 <[email protected]> | 2026-07-05 17:36:35 +0800 |
|---|---|---|
| committer | Larvan2 <[email protected]> | 2026-07-05 17:36:35 +0800 |
| commit | 30dfb51a61a6d6083640d411da8c63cb076318ab (patch) | |
| tree | 457f95f9dafc6cf1196d35fdec5eb0d677667b23 /src/modules | |
| parent | a7a842ee25a5b7fc5aa0cd20e9a3086d747332bc (diff) | |
Wire up the mihomo rules API's extra fields (disabled, hitCount, hitAt)
and the /rules/disable endpoint so each rule can be toggled on/off and
shows its hit count. Also surface the rule provider's ruleCount for
RuleSet-type rules, since their own size field is always -1.
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; }; } |
