import { useState, useMemo, useRef } from "react"; import { useTranslation } from "react-i18next"; import { Virtuoso, VirtuosoHandle } from "react-virtuoso"; import { Box } from "@mui/material"; import { BaseEmpty, BasePage } from "@/components/base"; import RuleItem from "@/components/rule/rule-item"; import { ProviderButton } from "@/components/rule/provider-button"; import { BaseSearchBox } from "@/components/base/base-search-box"; import { useTheme } from "@mui/material/styles"; import { ScrollTopButton } from "@/components/layout/scroll-top-button"; import { useAppData } from "@/providers/app-data-provider"; const RulesPage = () => { const { t } = useTranslation(); const { rules = [] } = useAppData(); const theme = useTheme(); const isDark = theme.palette.mode === "dark"; const [match, setMatch] = useState(() => (_: string) => true); const virtuosoRef = useRef(null); const [showScrollTop, setShowScrollTop] = useState(false); 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 ( } > setMatch(() => match)} /> {filteredRules.length > 0 ? ( <> ( )} followOutput={"smooth"} scrollerRef={(ref) => { if (ref) ref.addEventListener("scroll", handleScroll); }} /> ) : ( )} ); }; export default RulesPage;