* feat: add tauri-plugin-mihomo * refactor: invock mihomo api by use tauri-plugin-mihomo * chore: todo * chore: update * chore: update * chore: update * chore: update * fix: incorrect delay status and update pretty config * chore: update * chore: remove cache * chore: update * chore: update * fix: app freezed when change group proxy * chore: update * chore: update * chore: add rustfmt.toml to tauri-plugin-mihomo * chore: happy clippy * refactor: connect mihomo websocket * chore: update * chore: update * fix: parse bigint to number * chore: update * Revert "fix: parse bigint to number" This reverts commit 74c006522e23aa52cf8979a8fb47d2b1ae0bb043. * chore: use number instead of bigint * chore: cleanup * fix: rule data not refresh when switch profile * chore: update * chore: cleanup * chore: update * fix: traffic graph data display * feat: add ipc connection pool * chore: update * chore: clippy * fix: incorrect delay status * fix: typo * fix: empty proxies tray menu * chore: clippy * chore: import tauri-plugin-mihomo by using git repo * chore: cleanup * fix: mihomo api * fix: incorrect delay status * chore: update tauri-plugin-mihomo dep chore: update
103 lines
2.8 KiB
TypeScript
103 lines
2.8 KiB
TypeScript
import { Box } from "@mui/material";
|
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Virtuoso, VirtuosoHandle } from "react-virtuoso";
|
|
|
|
import { BaseEmpty, BasePage } from "@/components/base";
|
|
import { BaseSearchBox } from "@/components/base/base-search-box";
|
|
import { ScrollTopButton } from "@/components/layout/scroll-top-button";
|
|
import { ProviderButton } from "@/components/rule/provider-button";
|
|
import RuleItem from "@/components/rule/rule-item";
|
|
import { useVisibility } from "@/hooks/use-visibility";
|
|
import { useAppData } from "@/providers/app-data-context";
|
|
|
|
const RulesPage = () => {
|
|
const { t } = useTranslation();
|
|
const { rules = [], refreshRules, refreshRuleProviders } = useAppData();
|
|
const [match, setMatch] = useState(() => (_: string) => true);
|
|
const virtuosoRef = useRef<VirtuosoHandle>(null);
|
|
const [showScrollTop, setShowScrollTop] = useState(false);
|
|
const pageVisible = useVisibility();
|
|
|
|
// 在组件挂载时和页面获得焦点时刷新规则数据
|
|
useEffect(() => {
|
|
refreshRules();
|
|
refreshRuleProviders();
|
|
|
|
if (pageVisible) {
|
|
refreshRules();
|
|
refreshRuleProviders();
|
|
}
|
|
}, [refreshRules, refreshRuleProviders, pageVisible]);
|
|
|
|
const filteredRules = useMemo(() => {
|
|
return rules.filter((item) => match(item.payload));
|
|
}, [rules, match]);
|
|
|
|
const scrollToTop = () => {
|
|
virtuosoRef.current?.scrollTo({
|
|
top: 0,
|
|
behavior: "smooth",
|
|
});
|
|
};
|
|
|
|
const handleScroll = (e: any) => {
|
|
setShowScrollTop(e.target.scrollTop > 100);
|
|
};
|
|
|
|
return (
|
|
<BasePage
|
|
full
|
|
title={t("Rules")}
|
|
contentStyle={{
|
|
height: "100%",
|
|
display: "flex",
|
|
flexDirection: "column",
|
|
overflow: "auto",
|
|
}}
|
|
header={
|
|
<Box display="flex" alignItems="center" gap={1}>
|
|
<ProviderButton />
|
|
</Box>
|
|
}
|
|
>
|
|
<Box
|
|
sx={{
|
|
pt: 1,
|
|
mb: 0.5,
|
|
mx: "10px",
|
|
height: "36px",
|
|
display: "flex",
|
|
alignItems: "center",
|
|
}}
|
|
>
|
|
<BaseSearchBox onSearch={(match) => setMatch(() => match)} />
|
|
</Box>
|
|
|
|
{filteredRules && filteredRules.length > 0 ? (
|
|
<>
|
|
<Virtuoso
|
|
ref={virtuosoRef}
|
|
data={filteredRules}
|
|
style={{
|
|
flex: 1,
|
|
}}
|
|
itemContent={(index, item) => (
|
|
<RuleItem index={index + 1} value={item} />
|
|
)}
|
|
followOutput={"smooth"}
|
|
scrollerRef={(ref) => {
|
|
if (ref) ref.addEventListener("scroll", handleScroll);
|
|
}}
|
|
/>
|
|
<ScrollTopButton onClick={scrollToTop} show={showScrollTop} />
|
|
</>
|
|
) : (
|
|
<BaseEmpty />
|
|
)}
|
|
</BasePage>
|
|
);
|
|
};
|
|
|
|
export default RulesPage;
|