22// Copyright contributors to the kepler.gl project
33
44import React , { useCallback , useEffect , useRef , useState } from 'react' ;
5- import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer' ;
65import styled , { ThemeProvider , StyleSheetManager } from 'styled-components' ;
7- import Window from 'global/window' ;
8- import { connect , useDispatch } from 'react-redux' ;
6+ import { useDispatch } from 'react-redux' ;
97import cloneDeep from 'lodash/cloneDeep' ;
108import isEqual from 'lodash/isEqual' ;
119import { useSelector } from 'react-redux' ;
@@ -173,6 +171,23 @@ const App = props => {
173171
174172 const prevQueryRef = useRef < number > ( null ) ;
175173
174+ const startScreenCapture = useSelector (
175+ ( state : any ) => state . demo . aiAssistant . screenshotToAsk . startScreenCapture
176+ ) ;
177+
178+ const mapContainerRef = useRef < HTMLDivElement > ( null ) ;
179+ const [ mapDimensions , setMapDimensions ] = useState ( { width : 0 , height : 0 } ) ;
180+
181+ useEffect ( ( ) => {
182+ if ( ! mapContainerRef . current ) return ;
183+ const observer = new ResizeObserver ( entries => {
184+ const { width, height} = entries [ 0 ] . contentRect ;
185+ setMapDimensions ( { width, height} ) ;
186+ } ) ;
187+ observer . observe ( mapContainerRef . current ) ;
188+ return ( ) => observer . disconnect ( ) ;
189+ } , [ ] ) ;
190+
176191 // Handle OAuth callback on /auth route
177192 useEffect ( ( ) => {
178193 if ( location . pathname === '/auth' && window . opener ) {
@@ -273,7 +288,7 @@ const App = props => {
273288
274289 const _disableBanner = useCallback ( ( ) => {
275290 hideBanner ( ) ;
276- Window . localStorage . setItem ( BannerKey , 'true' ) ;
291+ window . localStorage . setItem ( BannerKey , 'true' ) ;
277292 } , [ hideBanner ] ) ;
278293
279294 const _loadRowData = useCallback ( ( ) => {
@@ -575,7 +590,7 @@ const App = props => {
575590 features : sampleGeojsonPoints . features . slice ( 0 , 5 )
576591 } ) ;
577592 _loadGeojsonData ( ) ;
578- Window . setTimeout ( ( ) => {
593+ window . setTimeout ( ( ) => {
579594 dispatch (
580595 replaceDataInMap ( {
581596 datasetToReplaceId : 'bart-stops-geo' ,
@@ -874,7 +889,7 @@ const App = props => {
874889 // }}
875890 >
876891 < ScreenshotWrapper
877- startScreenCapture = { props . demo . aiAssistant . screenshotToAsk . startScreenCapture }
892+ startScreenCapture = { startScreenCapture }
878893 setScreenCaptured = { _setScreenCaptured }
879894 setStartScreenCapture = { _setStartScreenCapture }
880895 className = "h-screen"
@@ -887,23 +902,21 @@ const App = props => {
887902 < Panel defaultSize = { isAiAssistantPanelOpen ? 70 : 100 } >
888903 < PanelGroup direction = "vertical" >
889904 < Panel defaultSize = { isSqlPanelOpen ? 60 : 100 } >
890- < AutoSizer >
891- { ( { height, width} ) => (
892- < KeplerGl
893- mapboxApiAccessToken = { CLOUD_PROVIDERS_CONFIGURATION . MAPBOX_TOKEN }
894- id = "map"
895- getState = { keplerGlGetState }
896- width = { width }
897- height = { height }
898- cloudProviders = { CLOUD_PROVIDERS }
899- localeMessages = { messages }
900- onExportToCloudSuccess = { onExportFileSuccess }
901- onLoadCloudMapSuccess = { onLoadCloudMapSuccess }
902- featureFlags = { DEFAULT_FEATURE_FLAGS }
903- onViewStateChange = { onViewStateChange }
904- />
905- ) }
906- </ AutoSizer >
905+ < div ref = { mapContainerRef } style = { { width : '100%' , height : '100%' } } >
906+ < KeplerGl
907+ mapboxApiAccessToken = { CLOUD_PROVIDERS_CONFIGURATION . MAPBOX_TOKEN }
908+ id = "map"
909+ getState = { keplerGlGetState }
910+ width = { mapDimensions . width }
911+ height = { mapDimensions . height }
912+ cloudProviders = { CLOUD_PROVIDERS }
913+ localeMessages = { messages }
914+ onExportToCloudSuccess = { onExportFileSuccess }
915+ onLoadCloudMapSuccess = { onLoadCloudMapSuccess }
916+ featureFlags = { DEFAULT_FEATURE_FLAGS }
917+ onViewStateChange = { onViewStateChange }
918+ />
919+ </ div >
907920 </ Panel >
908921
909922 { isSqlPanelOpen && (
@@ -933,7 +946,4 @@ const App = props => {
933946 ) ;
934947} ;
935948
936- const mapStateToProps = state => state ;
937- const dispatchToProps = dispatch => ( { dispatch} ) ;
938-
939- export default connect ( mapStateToProps , dispatchToProps ) ( App ) ;
949+ export default App ;
0 commit comments