@@ -13,33 +13,45 @@ const detectRouteData = (value: string) => {
1313
1414 // Json
1515 try {
16- JSON . parse ( value ) ;
17- return { route : '/json-formatter' , state : { input1 : value } } ;
16+ if ( typeof JSON . parse ( value ) === 'object' ) {
17+ return { route : '/json-formatter' , state : { input1 : value } } ;
18+ }
1819 } catch ( e ) {
1920 // ignore
2021 }
2122
2223 return { } ;
2324} ;
2425
26+ interface LocationState {
27+ auto : boolean ;
28+ }
29+
2530const Auto = ( ) => {
2631 const [ value , setValue ] = useState ( '' ) ;
2732 const [ hotkey , setHotkey ] = useState ( '' ) ;
2833 const history = useHistory ( ) ;
29- const location = useLocation ( ) ;
34+ const location = useLocation < LocationState > ( ) ;
3035
3136 useEffect ( ( ) => {
32- setValue ( clipboard . readText ( ) ) ;
37+ if ( location . state && location . state . auto ) {
38+ setValue ( clipboard . readText ( ) ) ;
39+ }
3340 } , [ location ] ) ;
3441
3542 useEffect ( ( ) => {
43+ let isMounted = true ;
3644 ipcRenderer
3745 . invoke ( 'get-store' , { key : 'hotkey' } )
3846 . then ( ( v : string ) => {
39- setHotkey ( v ) ;
47+ if ( isMounted ) setHotkey ( v ) ;
4048 return null ;
4149 } )
4250 . catch ( ( ) => { } ) ;
51+
52+ return ( ) => {
53+ isMounted = false ;
54+ } ;
4355 } ) ;
4456
4557 useEffect ( ( ) => {
@@ -70,12 +82,29 @@ const Auto = () => {
7082 ) }
7183 </ section >
7284 < div className = "flex items-center justify-between w-full my-1" >
73- < span > No tools was detected for this content:</ span >
74- < button type = "button" className = "w-16 btn" onClick = { ( ) => setValue ( '' ) } >
75- Clear
76- </ button >
85+ < section className = "flex items-center space-x-2" >
86+ < button
87+ type = "button"
88+ className = "btn"
89+ onClick = { ( ) => setValue ( clipboard . readText ( ) ) }
90+ >
91+ Clipboard
92+ </ button >
93+ < button
94+ type = "button"
95+ className = "w-16 btn"
96+ onClick = { ( ) => setValue ( '' ) }
97+ >
98+ Clear
99+ </ button >
100+ </ section >
101+ { value ? < span > No tools was detected for this content</ span > : < span /> }
77102 </ div >
78- < textarea className = "flex w-full p-2 h-1/3" value = { value } readOnly />
103+ < textarea
104+ className = "flex w-full p-2 h-1/3"
105+ value = { value }
106+ onChange = { ( e ) => setValue ( e . target . value ) }
107+ />
79108 </ div >
80109 ) ;
81110} ;
0 commit comments