import { TextField, type TextFieldProps } from '@mui/material' import { useEffect, useEffectEvent, useRef, useState } from 'react' import { useProfiles } from '@/hooks/use-profiles' type Props = Omit & { value: string onCommit: (url: string) => void } export const ProxyTestUrlInput = ({ value, name, ...props }: Props) => { const { profiles } = useProfiles() return ( ) } const DraftTestUrlInput = ({ value, onCommit, ...props }: Props) => { const [draft, setDraft] = useState(null) const pendingRef = useRef(null) const commitOnUnmount = useEffectEvent(() => { if (pendingRef.current !== null && pendingRef.current !== value) onCommit(pendingRef.current) }) useEffect(() => () => commitOnUnmount(), []) return ( { pendingRef.current = event.target.value setDraft(event.target.value) }} onBlur={() => { const next = pendingRef.current pendingRef.current = null setDraft(null) if (next !== null && next !== value) onCommit(next) }} onKeyDown={(event) => { if (event.key === 'Enter') { event.preventDefault() const input = event.target as HTMLInputElement input.blur() } }} /> ) }