mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-18 18:02:08 +08:00
refactor(app-data): split monolithic context into focused SWR hooks (#5576)
* refactor(app-data): split monolithic context into focused SWR hooks * refactor(swr): unify polling and consolidate proxy/config/provider data flow
This commit is contained in:
@@ -21,7 +21,7 @@ import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { updateRuleProvider } from "tauri-plugin-mihomo-api";
|
||||
|
||||
import { useAppData } from "@/providers/app-data-context";
|
||||
import type { useRuleProvidersData, useRulesData } from "@/hooks/app-data";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
|
||||
// 辅助组件 - 类型框
|
||||
@@ -37,10 +37,22 @@ const TypeBox = styled(Box)<{ component?: React.ElementType }>(({ theme }) => ({
|
||||
lineHeight: 1.25,
|
||||
}));
|
||||
|
||||
export const ProviderButton = () => {
|
||||
type RuleProvidersHook = ReturnType<typeof useRuleProvidersData>;
|
||||
type RulesHook = ReturnType<typeof useRulesData>;
|
||||
|
||||
interface ProviderButtonProps {
|
||||
ruleProviders: RuleProvidersHook["ruleProviders"];
|
||||
refreshRuleProviders: RuleProvidersHook["refreshRuleProviders"];
|
||||
refreshRules: RulesHook["refreshRules"];
|
||||
}
|
||||
|
||||
export const ProviderButton = ({
|
||||
ruleProviders,
|
||||
refreshRuleProviders,
|
||||
refreshRules,
|
||||
}: ProviderButtonProps) => {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const { ruleProviders, refreshRules, refreshRuleProviders } = useAppData();
|
||||
const [updating, setUpdating] = useState<Record<string, boolean>>({});
|
||||
|
||||
// 检查是否有提供者
|
||||
@@ -163,8 +175,8 @@ export const ProviderButton = () => {
|
||||
<List sx={{ py: 0, minHeight: 250 }}>
|
||||
{Object.entries(ruleProviders || {})
|
||||
.sort()
|
||||
.map(([key, item]) => {
|
||||
const provider = item;
|
||||
.map(([key, provider]) => {
|
||||
if (!provider) return null;
|
||||
const time = dayjs(provider.updatedAt);
|
||||
const isUpdating = updating[key];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user