import type { FC, ReactNode } from "react" import { type PressEvent, addToast, Button } from "@heroui/react" import { useAutoRefresh } from "soda-hooks" import type { FirstParameter } from "soda-type" export interface AutoRefreshProps extends FirstParameter { onRefresh?: () => void children?: ReactNode } export const AutoRefresh: FC = ({ children, onRefresh, ...rest }) => { if (process.env.NODE_ENV === "development") return children function onPress(e: PressEvent) { const closeButton = e.target.parentElement?.querySelector(`[aria-label="关闭"]`) as HTMLButtonElement closeButton?.click() onRefresh?.() } // eslint-disable-next-line react-hooks/rules-of-hooks useAutoRefresh(() => addToast({ title: "检测到页面更新", description: "为了最佳的体验,请刷新页面", color: "warning", timeout: Infinity, endContent: ( ), ...rest, })) return children }