import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { Box, IconButton, TextField, SxProps } from "@mui/material"; import { AccessTimeRounded, MyLocationRounded, NetworkCheckRounded, FilterAltRounded, FilterAltOffRounded, VisibilityRounded, VisibilityOffRounded, WifiTetheringRounded, WifiTetheringOffRounded, SortByAlphaRounded, SortRounded, } from "@mui/icons-material"; import { useVergeConfig } from "@/hooks/use-verge-config"; import delayManager from "@/services/delay"; import type { HeadState } from "./use-head-state"; import type { ProxySortType } from "./use-filter-sort"; interface Props { sx?: SxProps; groupName: string; headState: HeadState; onLocation: () => void; onCheckDelay: () => void; onHeadState: (val: Partial) => void; } export const ProxyHead = (props: Props) => { const { sx = {}, groupName, headState, onHeadState } = props; const { showType, sortType, filterText, textState, testUrl } = headState; const { t } = useTranslation(); const [autoFocus, setAutoFocus] = useState(false); useEffect(() => { // fix the focus conflict const timer = setTimeout(() => setAutoFocus(true), 100); return () => clearTimeout(timer); }, []); const { data: vergeConfig } = useVergeConfig(); useEffect(() => { delayManager.setUrl( groupName, testUrl || vergeConfig?.default_latency_test! ); }, [groupName, testUrl, vergeConfig?.default_latency_test]); return ( { // Remind the user that it is custom test url if (testUrl?.trim() && textState !== "filter") { onHeadState({ textState: "url" }); } props.onCheckDelay(); }} > onHeadState({ sortType: ((sortType + 1) % 3) as ProxySortType }) } > {sortType === 0 && } {sortType === 1 && } {sortType === 2 && } onHeadState({ textState: textState === "url" ? null : "url" }) } > {textState === "url" ? ( ) : ( )} onHeadState({ showType: !showType })} > {showType ? : } onHeadState({ textState: textState === "filter" ? null : "filter" }) } > {textState === "filter" ? ( ) : ( )} {textState === "filter" && ( onHeadState({ filterText: e.target.value })} sx={{ ml: 0.5, flex: "1 1 auto", input: { py: 0.65, px: 1 } }} /> )} {textState === "url" && ( onHeadState({ testUrl: e.target.value })} sx={{ ml: 0.5, flex: "1 1 auto", input: { py: 0.65, px: 1 } }} /> )} ); };