mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 06:43:44 +08:00
feat: auto-refresh rule data when switching to rules page
This commit is contained in:
parent
0bb042e085
commit
4d37e6870c
@ -31,6 +31,7 @@
|
|||||||
- 系统代理 Bypass 设置
|
- 系统代理 Bypass 设置
|
||||||
- Windows 下使用 Startup 文件夹的方式实现开机自启,解决管理员模式下开机自启的各种问题
|
- Windows 下使用 Startup 文件夹的方式实现开机自启,解决管理员模式下开机自启的各种问题
|
||||||
- 增加 IP 信息请求重试机制,减少 Network Error 发生的情况
|
- 增加 IP 信息请求重试机制,减少 Network Error 发生的情况
|
||||||
|
- 切换到规则页面时自动刷新规则数据
|
||||||
|
|
||||||
## v2.2.3
|
## v2.2.3
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useState, useMemo, useRef } from "react";
|
import { useState, useMemo, useRef, useEffect } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Virtuoso, VirtuosoHandle } from "react-virtuoso";
|
import { Virtuoso, VirtuosoHandle } from "react-virtuoso";
|
||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
@ -9,15 +9,28 @@ import { BaseSearchBox } from "@/components/base/base-search-box";
|
|||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { ScrollTopButton } from "@/components/layout/scroll-top-button";
|
import { ScrollTopButton } from "@/components/layout/scroll-top-button";
|
||||||
import { useAppData } from "@/providers/app-data-provider";
|
import { useAppData } from "@/providers/app-data-provider";
|
||||||
|
import { useVisibility } from "@/hooks/use-visibility";
|
||||||
|
|
||||||
const RulesPage = () => {
|
const RulesPage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { rules = [] } = useAppData();
|
const { rules = [], refreshRules, refreshRuleProviders } = useAppData();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isDark = theme.palette.mode === "dark";
|
const isDark = theme.palette.mode === "dark";
|
||||||
const [match, setMatch] = useState(() => (_: string) => true);
|
const [match, setMatch] = useState(() => (_: string) => true);
|
||||||
const virtuosoRef = useRef<VirtuosoHandle>(null);
|
const virtuosoRef = useRef<VirtuosoHandle>(null);
|
||||||
const [showScrollTop, setShowScrollTop] = useState(false);
|
const [showScrollTop, setShowScrollTop] = useState(false);
|
||||||
|
const pageVisible = useVisibility();
|
||||||
|
|
||||||
|
// 在组件挂载时和页面获得焦点时刷新规则数据
|
||||||
|
useEffect(() => {
|
||||||
|
refreshRules();
|
||||||
|
refreshRuleProviders();
|
||||||
|
|
||||||
|
if (pageVisible) {
|
||||||
|
refreshRules();
|
||||||
|
refreshRuleProviders();
|
||||||
|
}
|
||||||
|
}, [refreshRules, refreshRuleProviders, pageVisible]);
|
||||||
|
|
||||||
const filteredRules = useMemo(() => {
|
const filteredRules = useMemo(() => {
|
||||||
return rules.filter((item) => match(item.payload));
|
return rules.filter((item) => match(item.payload));
|
||||||
|
@ -117,12 +117,12 @@ export const AppDataProvider = ({ children }: { children: React.ReactNode }) =>
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// 高频率更新数据 (1秒)
|
// 高频率更新数据 (2秒)
|
||||||
const { data: uptimeData } = useSWR(
|
const { data: uptimeData } = useSWR(
|
||||||
"appUptime",
|
"appUptime",
|
||||||
getAppUptime,
|
getAppUptime,
|
||||||
{
|
{
|
||||||
refreshInterval: 1000,
|
refreshInterval: 2000,
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
suspense: false
|
suspense: false
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user