Skip to content

Commit ca9f557

Browse files
committed
feat(next): configure svelte app and widgets.
1 parent 70bb6dd commit ca9f557

File tree

6 files changed

+90
-41
lines changed

6 files changed

+90
-41
lines changed

.env.development

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
GATSBY_TEIKEI_BUNDLES_URL=https://map-staging.ernte-teilen.org
2-
GATSBY_TEIKEI_API_BASE_URL=https://api-staging.ernte-teilen.org
3-
GATSBY_TEIKEI_ASSETS_BASE_URL=https://map-staging.ernte-teilen.org/assets
1+
GATSBY_TEIKEI_BUNDLES_URL=https://map-next.ernte-teilen.org
2+
GATSBY_TEIKEI_API_BASE_URL=https://api-next.ernte-teilen.org
3+
GATSBY_TEIKEI_ASSETS_BASE_URL=https://map-next.ernte-teilen.org/assets

.env.production

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
GATSBY_TEIKEI_BUNDLES_URL=https://map.ernte-teilen.org
2-
GATSBY_TEIKEI_API_BASE_URL=https://api.ernte-teilen.org
3-
GATSBY_TEIKEI_ASSETS_BASE_URL=https://map.ernte-teilen.org/assets
1+
GATSBY_TEIKEI_BUNDLES_URL=https://map-next.ernte-teilen.org
2+
GATSBY_TEIKEI_API_BASE_URL=https://api-next.ernte-teilen.org
3+
GATSBY_TEIKEI_ASSETS_BASE_URL=https://map-next.ernte-teilen.org/assets

gatsby-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ module.exports = {
3535
'Hier finden Landwirte und Verbraucher zusammen, die sich an Solidarischer Landwirtschaft beteiligen möchten.',
3636
apiBaseUrl: process.env.GATSBY_TEIKEI_API_BASE_URL,
3737
assetsBaseUrl: process.env.GATSBY_TEIKEI_ASSETS_BASE_URL,
38+
bundlesUrl: process.env.GATSBY_TEIKEI_BUNDLES_URL,
3839
},
3940
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Source code for the ernte-teilen.org website",
44
"license": "AGPL-3.0",
55
"scripts": {
6-
"dev": "gatsby develop",
6+
"dev": "gatsby develop -p 3000",
77
"clean": "gatsby clean",
88
"build": "gatsby build",
99
"serve": "gatsby serve",

src/components/Search/index.js

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, { useEffect, useRef } from 'react'
22
import PropTypes from 'prop-types'
33
import { graphql } from 'gatsby'
44

@@ -7,26 +7,49 @@ import './styles.scss'
77
const 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

3154
Search.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
`

src/templates/teikei.js

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, { useEffect, useRef } from 'react'
22
import PropTypes from 'prop-types'
33
import { graphql } from 'gatsby'
44

@@ -15,22 +15,45 @@ const TeikeiTemplate = ({
1515
frontmatter: { title },
1616
},
1717
site: {
18-
siteMetadata: { apiBaseUrl, assetsBaseUrl },
18+
siteMetadata: { apiBaseUrl, assetsBaseUrl, bundlesUrl },
1919
},
2020
},
21-
}) => (
22-
<PageWrapper t={t} fixedHeader>
23-
<PageMeta pathname={location.pathname} title={title} />
24-
<div
25-
id="teikei-app"
26-
data-locale="de"
27-
data-base-url="/karte#"
28-
data-country="DE"
29-
data-api-base-url={apiBaseUrl}
30-
data-assets-base-url={assetsBaseUrl}
31-
/>
32-
</PageWrapper>
33-
)
21+
}) => {
22+
const elRef = useRef(null)
23+
24+
useEffect(() => {
25+
if (!elRef.current) return
26+
27+
window.__sveltekit_teikei = {
28+
base: new URL('.', window.location).pathname.slice(0, -1),
29+
}
30+
31+
const element = elRef.current
32+
33+
import(/* webpackIgnore: true */ `${bundlesUrl}/main.js`)
34+
.then((app) => {
35+
app.start(element)
36+
})
37+
.catch((err) => {
38+
console.error('Failed to load teikei bundle', err)
39+
})
40+
}, [bundlesUrl])
41+
42+
return (
43+
<PageWrapper t={t} fixedHeader>
44+
<PageMeta pathname={location.pathname} title={title} />
45+
<div
46+
ref={elRef}
47+
id="teikei-app"
48+
data-locale="de"
49+
data-base-url="/karte#"
50+
data-country="DE"
51+
data-api-base-url={apiBaseUrl}
52+
data-assets-base-url={assetsBaseUrl}
53+
/>
54+
</PageWrapper>
55+
)
56+
}
3457

3558
TeikeiTemplate.propTypes = {
3659
location: PropTypes.shape({
@@ -53,6 +76,7 @@ export const query = graphql`
5376
siteMetadata {
5477
apiBaseUrl
5578
assetsBaseUrl
79+
bundlesUrl
5680
}
5781
}
5882
t: localesYaml(locale: { eq: "de" }) {

0 commit comments

Comments
 (0)