@@ -25,12 +25,15 @@ export interface ExtendedConfigOptions extends Cypress.ConfigOptions {
25
25
}
26
26
27
27
interface AppProps {
28
- state : State ;
29
- // eslint-disable-next-line
28
+ state : State
30
29
eventManager : typeof EventManager
31
30
config : ExtendedConfigOptions
32
31
}
33
32
33
+ const DEFAULT_LEFT_SIDE_OF_SPLITPANE_WIDTH = 355
34
+ // needs to account for the left bar + the margins around the viewport
35
+ const VIEWPORT_SIDE_MARGIN = 40 + 17
36
+
34
37
const App : React . FC < AppProps > = observer (
35
38
function App ( props : AppProps ) {
36
39
const pluginRootContainer = React . useRef < null | HTMLDivElement > ( null )
@@ -40,13 +43,46 @@ const App: React.FC<AppProps> = observer(
40
43
const [ pluginsHeight , setPluginsHeight ] = React . useState ( 500 )
41
44
const [ isResizing , setIsResizing ] = React . useState ( false )
42
45
const [ isSpecsListOpen , setIsSpecsListOpen ] = React . useState ( true )
46
+ const [ leftSideOfSplitPaneWidth , setLeftSideOfSplitPaneWidth ] = React . useState ( DEFAULT_LEFT_SIDE_OF_SPLITPANE_WIDTH )
47
+ const headerRef = React . useRef ( null )
48
+
49
+ function monitorWindowResize ( ) {
50
+ // I can't use forwardref in class based components
51
+ // Header still is a class component
52
+ // FIXME: use a forwardRef when available
53
+ const header = headerRef . current . headerRef
54
+
55
+ function onWindowResize ( ) {
56
+ state . updateWindowDimensions ( {
57
+ windowWidth : window . innerWidth ,
58
+ windowHeight : window . innerHeight ,
59
+ reporterWidth : leftSideOfSplitPaneWidth + VIEWPORT_SIDE_MARGIN ,
60
+ headerHeight : header . offsetHeight || 0 ,
61
+ } )
62
+ }
63
+
64
+ window . addEventListener ( 'resize' , onWindowResize )
65
+ window . dispatchEvent ( new Event ( 'resize' ) )
66
+ }
43
67
44
68
React . useEffect ( ( ) => {
45
69
if ( pluginRootContainer . current ) {
46
70
state . initializePlugins ( config , pluginRootContainer . current )
47
71
}
72
+
73
+ monitorWindowResize ( )
48
74
} , [ ] )
49
75
76
+ function onSplitPaneChange ( newWidth : number ) {
77
+ setLeftSideOfSplitPaneWidth ( newWidth )
78
+ state . updateWindowDimensions ( {
79
+ reporterWidth : newWidth + VIEWPORT_SIDE_MARGIN ,
80
+ windowWidth : null ,
81
+ windowHeight : null ,
82
+ headerHeight : null ,
83
+ } )
84
+ }
85
+
50
86
return (
51
87
< >
52
88
< main className = "app-ct" >
@@ -73,6 +109,7 @@ const App: React.FC<AppProps> = observer(
73
109
defaultSize = { 355 }
74
110
onDragStarted = { ( ) => setIsResizing ( true ) }
75
111
onDragFinished = { ( ) => setIsResizing ( false ) }
112
+ onChange = { onSplitPaneChange }
76
113
className = { cs ( 'reporter-pane' , { 'is-reporter-resizing' : isResizing } ) }
77
114
>
78
115
< div >
@@ -105,7 +142,7 @@ const App: React.FC<AppProps> = observer(
105
142
}
106
143
>
107
144
< div className = "runner runner-ct container" >
108
- < Header { ...props } />
145
+ < Header { ...props } ref = { headerRef } />
109
146
< Iframes { ...props } />
110
147
< Message state = { state } />
111
148
</ div >
0 commit comments