1- import React from 'react'
1+ import React , { useEffect , useRef } from 'react'
22import PropTypes from 'prop-types'
33import { graphql } from 'gatsby'
44
@@ -7,26 +7,49 @@ import './styles.scss'
77const Search = ( {
88 t,
99 searchConfig : {
10- siteMetadata : { assetsBaseUrl, apiBaseUrl } ,
10+ siteMetadata : { assetsBaseUrl, apiBaseUrl, bundlesUrl } ,
1111 } ,
12- } ) => (
13- < div href = "/" className = "et--search" >
14- < div className = "et--search__form" >
15- < label className = "et--search__label" >
16- { t . search . label }
17- < div
18- className = "et--search__input"
19- id = "teikei-search"
20- data-locale = "de"
21- data-country = "DE"
22- data-base-url = "/karte/#"
23- data-api-base-url = { apiBaseUrl }
24- data-assets-base-url = { assetsBaseUrl }
25- />
26- </ label >
12+ } ) => {
13+ const elRef = useRef ( null )
14+
15+ useEffect ( ( ) => {
16+ if ( ! elRef . current ) return
17+
18+ window . __sveltekit_teikei = {
19+ base : new URL ( '.' , window . location ) . pathname . slice ( 0 , - 1 ) ,
20+ }
21+
22+ const element = elRef . current
23+
24+ import ( /* webpackIgnore: true */ `${ bundlesUrl } /widgets/search-widget.js` )
25+ . then ( ( app ) => {
26+ app . start ( element )
27+ } )
28+ . catch ( ( err ) => {
29+ console . error ( 'Failed to load teikei bundle' , err )
30+ } )
31+ } , [ bundlesUrl ] )
32+
33+ return (
34+ < div href = "/" className = "et--search" >
35+ < div className = "et--search__form" >
36+ < label className = "et--search__label" >
37+ { t . search . label }
38+ < div
39+ ref = { elRef }
40+ className = "et--search__input"
41+ id = "teikei-search"
42+ data-locale = "de"
43+ data-country = "DE"
44+ data-base-url = "/karte/#"
45+ data-api-base-url = { apiBaseUrl }
46+ data-assets-base-url = { assetsBaseUrl }
47+ />
48+ </ label >
49+ </ div >
2750 </ div >
28- </ div >
29- )
51+ )
52+ }
3053
3154Search . propTypes = {
3255 t : PropTypes . shape ( ) . isRequired ,
@@ -44,6 +67,7 @@ export const query = graphql`
4467 siteMetadata {
4568 apiBaseUrl
4669 assetsBaseUrl
70+ bundlesUrl
4771 }
4872 }
4973`
0 commit comments