File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,20 +96,34 @@ const styles = ({ mq }) => {
9696 } ;
9797} ;
9898
99- window . apiKey = "5cc87b12d7c5370001c1d6554840ecb89d2743d2b0aad0588b8ba7eb" ;
100-
10199export function StyleGuideRenderer ( {
102100 children,
103101 classes,
104102 hasSidebar,
105103 toc,
106104 version = null ,
107105} ) {
106+ const [ apiKey , setApiKey ] = useState ( ) ;
108107 const [ dropdownOpen , toggleDropdown ] = useState ( false ) ;
109108 const [ expanded , expandSection ] = useState ( ) ;
110109 const [ selected , setSelected ] = useState ( "Components" ) ;
111110 const [ node , setNode ] = useState ( ) ;
112111
112+ useEffect ( ( ) => {
113+ fetch ( "https://backend.developer.geops.io/publickey" )
114+ . then ( ( response ) => {
115+ return response . json ( ) ;
116+ } )
117+ . then ( ( data ) => {
118+ setApiKey ( data . key ) ;
119+ } )
120+ . catch ( ( ) => {
121+ setApiKey ( "error" ) ;
122+ // eslint-disable-next-line no-console
123+ console . error ( "Request to get the apiKey failed" ) ;
124+ } ) ;
125+ } , [ ] ) ;
126+
113127 useEffect ( ( ) => {
114128 if ( ! node ) return ;
115129 const { hash } = window . location ;
@@ -118,6 +132,13 @@ export function StyleGuideRenderer({
118132 }
119133 } , [ node ] ) ;
120134
135+ if ( ! apiKey ) {
136+ return null ;
137+ }
138+
139+ // Makes apiKey accessible for all components.
140+ window . apiKey = apiKey ;
141+
121142 return (
122143 < ThemeProvider theme = { geopsTheme } >
123144 < div className = { classes . root } >
You can’t perform that action at this time.
0 commit comments