1+ import clsx from 'clsx'
12import React , { useCallback , useEffect , useState } from 'react'
2- import Draggable from 'react-draggable'
3+ import Draggable , { DraggableEventHandler } from 'react-draggable'
34import cc from 'chrome-call'
5+ // @ts -ignore
6+ import ScrollToBottom from 'react-scroll-to-bottom'
47
58import logger from '../../../../common/logger'
69import { Config } from '../../../../common/types'
10+ import IconButton from '../../../../components/IconButton'
11+ import CloseIcon from '../../../../components/svg/Close'
712import translationStack from '../../common/translation-stack'
813import { TranslateJob } from '../../common/types'
914import { ConfigContext , ConfigState } from '../../providers/config'
@@ -12,6 +17,7 @@ import TranslationList from '../TranslationList'
1217
1318const App : React . FC = ( ) => {
1419 const [ config , setConfig ] = useState < ConfigState > ( )
20+ const [ close , setClose ] = useState ( false )
1521 const dispatch = useTranslateJobsDispatch ( )
1622
1723 const onNewJob = useCallback (
@@ -33,6 +39,16 @@ const App: React.FC = () => {
3339 [ dispatch ] ,
3440 )
3541
42+ const onDragStart : DraggableEventHandler = ( e ) => {
43+ if (
44+ document
45+ . querySelector < HTMLButtonElement > ( '.ate_App__close-button' )
46+ ?. contains ( e . target as Node )
47+ ) {
48+ return false
49+ }
50+ }
51+
3652 useEffect ( ( ) => {
3753 translationStack . attachQueue ( onNewJob )
3854
@@ -47,20 +63,40 @@ const App: React.FC = () => {
4763 targetLang : config . targetLang ,
4864 } )
4965 } )
66+
67+ window . __ate_setClose = setClose
5068 } , [ ] )
5169
5270 return (
5371 < ConfigContext . Provider value = { config } >
54- < Draggable handle = ".ate_App__header" defaultPosition = { { x : 20 , y : 20 } } >
55- < div className = "ate_App" >
56- < div className = "ate_App__header" > A Translator</ div >
57- < div className = "ate_App__container" >
58- < TranslationList />
72+ < Draggable
73+ handle = ".ate_App__header"
74+ onStart = { onDragStart }
75+ defaultPosition = { { x : 20 , y : 20 } } >
76+ < div className = { clsx ( [ 'ate_App' , close && 'ate_App--inactive' ] ) } >
77+ < div className = "ate_App__header" >
78+ < span > A Translator</ span >
79+ < span >
80+ < IconButton
81+ className = "ate_App__close-button"
82+ onClick = { ( ) => setClose ( true ) } >
83+ < CloseIcon />
84+ </ IconButton >
85+ </ span >
5986 </ div >
87+ < ScrollToBottom className = "ate_App__container" debug = { false } >
88+ < TranslationList />
89+ </ ScrollToBottom >
6090 </ div >
6191 </ Draggable >
6292 </ ConfigContext . Provider >
6393 )
6494}
6595
6696export default App
97+
98+ declare global {
99+ interface Window {
100+ __ate_setClose ?: React . Dispatch < any >
101+ }
102+ }
0 commit comments