import { Box, Button, Tooltip } from "@mui/material"; import { useCallback, useMemo } from "react"; interface ProxyGroupNavigatorProps { proxyGroupNames: string[]; onGroupLocation: (groupName: string) => void; } // 提取代理组名的第一个字符 const getGroupDisplayChar = (groupName: string): string => { if (!groupName) return "?"; // 直接返回第一个字符,支持表情符号 const firstChar = Array.from(groupName)[0]; return firstChar || "?"; }; export const ProxyGroupNavigator = ({ proxyGroupNames, onGroupLocation, }: ProxyGroupNavigatorProps) => { const handleGroupClick = useCallback( (groupName: string) => { onGroupLocation(groupName); }, [onGroupLocation], ); // 处理代理组数据,去重和排序 const processedGroups = useMemo(() => { return proxyGroupNames .filter((name) => name && name.trim()) .map((name) => ({ name, displayChar: getGroupDisplayChar(name), })); }, [proxyGroupNames]); if (processedGroups.length === 0) { return null; } return ( {processedGroups.map(({ name, displayChar }) => ( ))} ); };