fork/replay-manager-for-slippi
git clone https://git.julia.blue/fork/replay-manager-for-slippi
1b12ff3
2.5.0
1import { Clear } from '@mui/icons-material' ; 2import { 3Box , 4IconButton , 5InputAdornment , 6TextField , 7Tooltip , 8} from '@mui/material' ; 9import { useCallback , useEffect , useRef , useState } from 'react' ; 10import { Mode } from '../common/types' ; 11import { setWindowEventListener , WindowEvent } from './setWindowEventListener' ; 12 13export default function SearchBox ({ 14 mode, 15 searchSubstr, 16 setSearchSubstr, 17 vlerkMode, 18} :{ 19mode :Mode ; 20searchSubstr :string ; 21setSearchSubstr :( searchSubstr :string ) => void ; 22vlerkMode :boolean ; 23}) { 24const searchInputRef = useRef < HTMLInputElement >(); 25const [ showSearch , setShowSearch ] = useState ( false ); 26 27const clearSearch = useCallback (() => { 28setSearchSubstr ( '' ); 29setShowSearch ( false ); 30}, [ setSearchSubstr ]); 31 32const ctrlF = useCallback (() => { 33setShowSearch ( true ); 34searchInputRef . current ?. select (); 35}, []); 36 37useEffect (() => { 38setWindowEventListener ( WindowEvent . ESCAPE , clearSearch ); 39}, [ clearSearch ]); 40 41useEffect (() => { 42setWindowEventListener ( WindowEvent . CTRLF , ctrlF ); 43}, [ ctrlF ]); 44 45return ( 46( showSearch || ( vlerkMode && mode === Mode . STARTGG )) && ( 47<> 48< Box 49style = {{ 50background :'#F5A9B8' , 51padding :'8px' , 52position :'fixed' , 53width :'300px' , 54right :0 , 55}} 56sx = {{ 57zIndex :( theme ) => theme . zIndex . drawer + 5 , 58}} 59> 60< TextField 61autoFocus 62fullWidth 63label = "Search" 64onChange = {( event ) => { 65setSearchSubstr ( event . target . value ); 66}} 67onKeyDown = {( event ) => { 68if ( event . key === 'Escape' ) { 69clearSearch (); 70} else if ( 71(( window . electron . isMac && event . metaKey ) || 72( ! window . electron . isMac && event . ctrlKey )) && 73event . key === 'f' 74) { 75searchInputRef . current ?. select (); 76} 77}} 78inputRef = { searchInputRef } 79size = "small" 80value = { searchSubstr } 81InputProps = {{ 82endAdornment :( 83< InputAdornment position = "end" > 84< Tooltip arrow title = "Clear search" > 85< IconButton 86onClick = {() => { 87clearSearch (); 88}} 89> 90< Clear /> 91</ IconButton > 92</ Tooltip > 93</ InputAdornment > 94), 95}} 96/> 97</ Box > 98< Box marginTop = "56px" /> 99</> 100) 101); 102}