gatsby-core-theme 40.0.2 → 40.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/gatsby-node.mjs +56 -41
- package/package.json +2 -2
- package/src/components/app-ssr.js +3 -41
- package/src/components/app.js +3 -38
- package/src/components/atoms/admin/bar/bar.module.scss +26 -0
- package/src/components/atoms/admin/bar/index.js +47 -22
- package/src/components/molecules/footer/index.js +1 -1
- package/src/constants/pick-keys.mjs +0 -1
- package/src/context/MainProvider.js +1 -0
- package/src/helpers/api.mjs +12 -36
- package/src/helpers/fetch-site-settings.mjs +46 -0
- package/src/helpers/processor/game.mjs +16 -0
- package/src/helpers/processor/game.test.js +113 -0
- package/src/helpers/processor/modules.mjs +2 -1
- package/src/helpers/processor/relations.mjs +3 -1
- package/src/helpers/server-data.js +52 -7
- package/src/pages/preview/index.js +93 -0
- package/src/components/app-preview.js +0 -85
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
## [40.0.4](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v40.0.3...v40.0.4) (2024-10-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* preview feature ([e01820d](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/e01820d1a5a543dd6209c78dd3826d9b13bf3ed4))
|
|
7
|
+
|
|
8
|
+
## [40.0.3](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v40.0.2...v40.0.3) (2024-10-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* added tests for game.mjs ([4d3848c](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/4d3848c7a55c3bbdc2d603ce3f08ec7e665bff09))
|
|
14
|
+
* admin bar ([e9f3430](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/e9f3430a9cded767cef9647baf37df9151c34be7))
|
|
15
|
+
* clean up ([8a413b0](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/8a413b09fa3ab645511d4ca20a65175ba3d9cc77))
|
|
16
|
+
* fix prevview ([fe5a7e8](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/fe5a7e88edda1f6fe99994e298f0c263cd79f6fb))
|
|
17
|
+
* game sanitization ([502e6fd](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/502e6fd020ab3f4cc5b80e029be9d5741d6d058d))
|
|
18
|
+
* premain ([c06770c](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/c06770c3064f1c49fcf1b595bfddbb97b2be97b1))
|
|
19
|
+
* preview logic ([ddc883d](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/ddc883d8261484eb3c6bc4137206aefd3cc18f22))
|
|
20
|
+
* sitemap changes ([1198642](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/11986422dcf9930d1a199213c49e8e7182d053d0))
|
|
21
|
+
* sitemap changes ([600b0bc](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/600b0bcf8aad82f403ffa6991ca531261cb29565))
|
|
22
|
+
* sitemap changes ([1dd5f66](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/1dd5f6639b3493711676f7b5b79fae001b681bc0))
|
|
23
|
+
* update relations mjs ([c3c6cc8](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/c3c6cc8dd924f68ab640a63629a329755ec65be0))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
* Merge branch 'tm-4857-sitemap-changes' into 'master' ([6924cb1](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/6924cb19082dc397f22975d1a5d87064e555bc5c))
|
|
27
|
+
* Merge branch 'tm-4682-previewLogic' into 'master' ([b3f573c](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/b3f573ce4153cae6a087b1b1b89b0017b900ea70))
|
|
28
|
+
* Merge branch 'merge-market-values-before' into 'master' ([7feb898](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/7feb8981db130d7b18d69e4ec8d42a3716d53657))
|
|
29
|
+
* Merge branch 'master' into tm-4682-previewLogic ([cd7d01f](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/cd7d01f9e77158712c2a18a7deac564349eea4a6))
|
|
30
|
+
|
|
1
31
|
## [40.0.2](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v40.0.1...v40.0.2) (2024-10-11)
|
|
2
32
|
|
|
3
33
|
|
package/gatsby-node.mjs
CHANGED
|
@@ -10,8 +10,8 @@ import chalk from 'chalk';
|
|
|
10
10
|
import fs from 'fs';
|
|
11
11
|
import { dirname } from 'path';
|
|
12
12
|
import { fileURLToPath } from 'url';
|
|
13
|
-
import { getData, getLocalData, getTranslations
|
|
14
|
-
|
|
13
|
+
import { getData, getLocalData, getTranslations } from './src/helpers/api.mjs';
|
|
14
|
+
import { fetchSiteSettings } from './src/helpers/fetch-site-settings.mjs';
|
|
15
15
|
import { generateTrackerLink } from './src/helpers/generators.mjs';
|
|
16
16
|
import processor, { processSitemapPages } from './src/helpers/processor/index.mjs';
|
|
17
17
|
import { pickTrackerOperatorKeys } from './src/constants/pick-keys.mjs';
|
|
@@ -37,6 +37,7 @@ let authors = null;
|
|
|
37
37
|
let responsableGamingData = null;
|
|
38
38
|
let toplistData = null;
|
|
39
39
|
let contentData = null;
|
|
40
|
+
let pagesData = null;
|
|
40
41
|
let translationsData = null;
|
|
41
42
|
let siteSettingsData = null;
|
|
42
43
|
let siteGeneralData = null;
|
|
@@ -247,19 +248,6 @@ export const createPages = async ({ actions: { createPage } }, themeOptions) =>
|
|
|
247
248
|
// create every single page
|
|
248
249
|
Object.keys(processed.site_markets).forEach((siteMarket) => {
|
|
249
250
|
if (!processed.pages[siteMarket]['page']) processed.pages[siteMarket]['page'] = [];
|
|
250
|
-
processed.pages[siteMarket]['page'].push({
|
|
251
|
-
meta_title: 'Preview',
|
|
252
|
-
relation_type: 'page',
|
|
253
|
-
path: 'preview',
|
|
254
|
-
template: 'default',
|
|
255
|
-
meta_robots: ['noindex', 'nofollow'],
|
|
256
|
-
sections: {
|
|
257
|
-
main: { modules: [] },
|
|
258
|
-
navigation: { modules: [] },
|
|
259
|
-
sidebar: { modules: [] },
|
|
260
|
-
footer: { modules: [] },
|
|
261
|
-
},
|
|
262
|
-
});
|
|
263
251
|
let count = 0;
|
|
264
252
|
Object.keys(processed.pages[siteMarket]).forEach((pageType) => {
|
|
265
253
|
processed.pages[siteMarket][pageType].forEach((page) => {
|
|
@@ -270,10 +258,7 @@ export const createPages = async ({ actions: { createPage } }, themeOptions) =>
|
|
|
270
258
|
const processedPage = page;
|
|
271
259
|
processedPage.preconnect_links = preconnectLinks;
|
|
272
260
|
|
|
273
|
-
siteSchema =
|
|
274
|
-
page.path === 'preview'
|
|
275
|
-
? (page.siteSchema = Object.values(schemaData || {})[0])
|
|
276
|
-
: schemaData[page['market_id']];
|
|
261
|
+
siteSchema = schemaData[page['market_id']];
|
|
277
262
|
authors = response.authors;
|
|
278
263
|
|
|
279
264
|
// siteInfo, siteSchema and authors are added to page for schemaGenerator()
|
|
@@ -328,8 +313,7 @@ export const createPages = async ({ actions: { createPage } }, themeOptions) =>
|
|
|
328
313
|
path: `/${page.path}`,
|
|
329
314
|
component: `${__dirname}/src/components/app-ssr.js`,
|
|
330
315
|
context: {
|
|
331
|
-
...contextData
|
|
332
|
-
isPreview: page.path === 'preview',
|
|
316
|
+
...contextData
|
|
333
317
|
},
|
|
334
318
|
});
|
|
335
319
|
} else {
|
|
@@ -341,8 +325,7 @@ export const createPages = async ({ actions: { createPage } }, themeOptions) =>
|
|
|
341
325
|
path: page.path.charAt(0) === '/' ? page.path : `/${page.path}`,
|
|
342
326
|
component,
|
|
343
327
|
context: {
|
|
344
|
-
...contextData
|
|
345
|
-
isPreview: page.path === 'preview',
|
|
328
|
+
...contextData
|
|
346
329
|
},
|
|
347
330
|
});
|
|
348
331
|
}
|
|
@@ -430,7 +413,7 @@ export const createPages = async ({ actions: { createPage } }, themeOptions) =>
|
|
|
430
413
|
|
|
431
414
|
export const onCreatePage = async ({ page, actions }) => {
|
|
432
415
|
const { createPage, deletePage } = actions;
|
|
433
|
-
|
|
416
|
+
|
|
434
417
|
if (is404Page(allMarketPrefixes, page.path)) {
|
|
435
418
|
const oldPage = { ...page };
|
|
436
419
|
const pathPrefix = page.path.split(`/`)[1];
|
|
@@ -463,7 +446,13 @@ export const onCreatePage = async ({ page, actions }) => {
|
|
|
463
446
|
component: `${__dirname}/src/components/app.js`,
|
|
464
447
|
context: context404,
|
|
465
448
|
});
|
|
466
|
-
}
|
|
449
|
+
}
|
|
450
|
+
else if (page.path.includes('preview')) {
|
|
451
|
+
createPage({
|
|
452
|
+
...page
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
467
456
|
createPage({
|
|
468
457
|
path: page.path,
|
|
469
458
|
component: `${__dirname}/src/components/app.js`,
|
|
@@ -474,21 +463,18 @@ export const onCreatePage = async ({ page, actions }) => {
|
|
|
474
463
|
|
|
475
464
|
export const onPreBootstrap = async () => {
|
|
476
465
|
// Get Data from Hercules
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
schemaData = siteSettingsData.schema;
|
|
490
|
-
templatesData = siteSettingsData.templates;
|
|
491
|
-
allMarketSectionsData = siteSettingsData.market_sections;
|
|
466
|
+
({siteSettingsData,
|
|
467
|
+
siteGeneralData,
|
|
468
|
+
allMarketsData,
|
|
469
|
+
allMarketPrefixes,
|
|
470
|
+
schemaData,
|
|
471
|
+
templatesData,
|
|
472
|
+
allMarketSectionsData,
|
|
473
|
+
ribbonsData,
|
|
474
|
+
responsableGamingData,
|
|
475
|
+
toplistData,
|
|
476
|
+
contentData,
|
|
477
|
+
pagesData } = await fetchSiteSettings(process.env.GATSBY_SITE_NAME));
|
|
492
478
|
}
|
|
493
479
|
|
|
494
480
|
export const sourceNodes = async ({ actions, createNodeId, createContentDigest }) => {
|
|
@@ -533,6 +519,35 @@ export const sourceNodes = async ({ actions, createNodeId, createContentDigest }
|
|
|
533
519
|
createNode(node)
|
|
534
520
|
});
|
|
535
521
|
});
|
|
522
|
+
|
|
523
|
+
// eslint-disable-next-line array-callback-return
|
|
524
|
+
Object.keys(pagesData).map((pageId) => {
|
|
525
|
+
const page = pagesData[pageId]
|
|
526
|
+
if(page && page.robot_options && page.robot_options.page_index) {
|
|
527
|
+
const pageSitemap = {
|
|
528
|
+
'path': page.path,
|
|
529
|
+
'updated_at': page.updated_at,
|
|
530
|
+
'market': page.market,
|
|
531
|
+
'language': page.language
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const nodeMeta = {
|
|
535
|
+
id: createNodeId(keygen()),
|
|
536
|
+
parent: null,
|
|
537
|
+
children: [],
|
|
538
|
+
internal: {
|
|
539
|
+
type: `Sitemap`,
|
|
540
|
+
mediaType: `text/html`,
|
|
541
|
+
contentDigest: createContentDigest(pageId),
|
|
542
|
+
},
|
|
543
|
+
};
|
|
544
|
+
const node = { ...pageSitemap, ...nodeMeta}
|
|
545
|
+
createNode(node)
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
})
|
|
550
|
+
|
|
536
551
|
};
|
|
537
552
|
|
|
538
553
|
export const onCreateWebpackConfig = ({ actions, stage, getConfig }) => {
|
|
@@ -566,4 +581,4 @@ export const onCreateWebpackConfig = ({ actions, stage, getConfig }) => {
|
|
|
566
581
|
},
|
|
567
582
|
},
|
|
568
583
|
});
|
|
569
|
-
};
|
|
584
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby-core-theme",
|
|
3
|
-
"version": "40.0.
|
|
3
|
+
"version": "40.0.4",
|
|
4
4
|
"description": "Gatsby Theme NPM Package",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"gatsby-plugin-postcss": "^6.11.0",
|
|
34
34
|
"gatsby-plugin-sass": "^6.11.0",
|
|
35
35
|
"gatsby-plugin-sharp": "^5.11.0",
|
|
36
|
-
"gatsby-plugin-sitemap": "^
|
|
36
|
+
"gatsby-plugin-sitemap": "^6.13.1",
|
|
37
37
|
"gatsby-plugin-webfonts": "^2.2.1",
|
|
38
38
|
"gatsby-source-filesystem": "^5.11.0",
|
|
39
39
|
"gatsby-transformer-sharp": "^5.11.0",
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
/* eslint-disable react/forbid-prop-types */
|
|
3
3
|
import React, { useEffect, useState } from 'react';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
|
-
import { globalHistory } from '@reach/router';
|
|
6
5
|
import { graphql, useStaticQuery } from 'gatsby';
|
|
7
6
|
import MainProvider from '~context/MainProvider';
|
|
8
7
|
import { getCookie } from "~helpers/cookies";
|
|
@@ -26,43 +25,10 @@ const AppSSR = ({ pageContext, serverData }) => {
|
|
|
26
25
|
}
|
|
27
26
|
`);
|
|
28
27
|
|
|
29
|
-
const { isPreview } = pageContext;
|
|
30
|
-
const [previewContext, setPreviewContext] = useState({});
|
|
31
|
-
const [isLoading, setIsLoading] = useState({});
|
|
32
28
|
const [isAdmin, setIsAdmin] = useState(false);
|
|
33
29
|
|
|
34
|
-
async function getData(searchParams, staticPath = null) {
|
|
35
|
-
const { getPreview } = await import('~helpers/api');
|
|
36
|
-
getPreview(
|
|
37
|
-
pageContext.siteName,
|
|
38
|
-
!staticPath ? searchParams.get('path') || '/' : staticPath,
|
|
39
|
-
pageContext
|
|
40
|
-
).then((previewResponse) => {
|
|
41
|
-
if (previewResponse.page) {
|
|
42
|
-
// siteInfo and siteSchema are added to page for schemaGenerator()
|
|
43
|
-
previewResponse.page.siteInfo = pageContext.siteInfo;
|
|
44
|
-
previewResponse.page.siteSchema = pageContext.siteSchema;
|
|
45
|
-
}
|
|
46
|
-
setPreviewContext(previewResponse);
|
|
47
|
-
setIsLoading(false);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
30
|
|
|
51
31
|
useEffect(() => {
|
|
52
|
-
if (isPreview) {
|
|
53
|
-
setIsLoading(true);
|
|
54
|
-
const searchParams =
|
|
55
|
-
typeof window !== 'undefined' ? new URLSearchParams(window.location.search) : null;
|
|
56
|
-
if (!searchParams.get('path')) {
|
|
57
|
-
window.location = `${window.location.origin}/preview?path=/`;
|
|
58
|
-
}
|
|
59
|
-
getData(searchParams);
|
|
60
|
-
globalHistory.listen(({ location }) => {
|
|
61
|
-
setIsLoading(true);
|
|
62
|
-
|
|
63
|
-
getData(null, location.search.replace('?path=', ''));
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
32
|
|
|
67
33
|
if (
|
|
68
34
|
typeof window !== `undefined` &&
|
|
@@ -73,16 +39,12 @@ const AppSSR = ({ pageContext, serverData }) => {
|
|
|
73
39
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
40
|
}, []);
|
|
75
41
|
|
|
76
|
-
|
|
77
|
-
if (isLoading) {
|
|
78
|
-
return 'Loading...';
|
|
79
|
-
}
|
|
80
|
-
}
|
|
42
|
+
|
|
81
43
|
|
|
82
44
|
return (
|
|
83
45
|
<>
|
|
84
46
|
<MainProvider value={{ admin: isAdmin, translations: data.translations, language: pageContext.page.language }} >
|
|
85
|
-
<Body pageContext={
|
|
47
|
+
<Body pageContext={pageContext} serverData={serverData} />
|
|
86
48
|
</MainProvider>
|
|
87
49
|
</>
|
|
88
50
|
);
|
|
@@ -122,4 +84,4 @@ export async function getServerData(props) {
|
|
|
122
84
|
let res = '';
|
|
123
85
|
res = await getAPIData(pageContext.page, url, headers);
|
|
124
86
|
return res;
|
|
125
|
-
}
|
|
87
|
+
}
|
package/src/components/app.js
CHANGED
|
@@ -9,9 +9,7 @@ import Body from '~pages/body';
|
|
|
9
9
|
import HeadData from '~organisms/head';
|
|
10
10
|
|
|
11
11
|
const App = ({ pageContext }) => {
|
|
12
|
-
|
|
13
|
-
const [previewContext, setPreviewContext] = useState({});
|
|
14
|
-
const [isLoading, setIsLoading] = useState({});
|
|
12
|
+
|
|
15
13
|
const [isAdmin, setIsAdmin] = useState(false);
|
|
16
14
|
|
|
17
15
|
const data = useStaticQuery(graphql`
|
|
@@ -28,35 +26,7 @@ const App = ({ pageContext }) => {
|
|
|
28
26
|
}
|
|
29
27
|
`);
|
|
30
28
|
|
|
31
|
-
async function getData(searchParams, staticPath = null) {
|
|
32
|
-
const { getPreview } = await import('~helpers/api');
|
|
33
|
-
getPreview(
|
|
34
|
-
pageContext.siteName,
|
|
35
|
-
!staticPath ? searchParams.get('path') || '/' : staticPath,
|
|
36
|
-
searchParams.get('market_id'),
|
|
37
|
-
pageContext
|
|
38
|
-
).then((previewResponse) => {
|
|
39
|
-
if (previewResponse.page) {
|
|
40
|
-
// siteInfo and siteSchema are added to page for schemaGenerator()
|
|
41
|
-
previewResponse.page.siteInfo = pageContext.siteInfo;
|
|
42
|
-
previewResponse.page.siteSchema = pageContext.siteSchema;
|
|
43
|
-
}
|
|
44
|
-
setPreviewContext(previewResponse);
|
|
45
|
-
setIsLoading(false);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
29
|
useEffect(() => {
|
|
50
|
-
if (isPreview) {
|
|
51
|
-
setIsLoading(true);
|
|
52
|
-
const searchParams =
|
|
53
|
-
typeof window !== 'undefined' ? new URLSearchParams(window.location.search) : null;
|
|
54
|
-
if (!searchParams.get('path')) {
|
|
55
|
-
window.location = `${window.location.origin}/preview?path=/`;
|
|
56
|
-
}
|
|
57
|
-
getData(searchParams);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
30
|
if (
|
|
61
31
|
typeof window !== `undefined` &&
|
|
62
32
|
getCookie("showAdminBar") === "true"
|
|
@@ -66,23 +36,18 @@ const App = ({ pageContext }) => {
|
|
|
66
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
37
|
}, []);
|
|
68
38
|
|
|
69
|
-
if (isPreview) {
|
|
70
|
-
if (isLoading) {
|
|
71
|
-
return 'Loading...';
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
39
|
|
|
75
40
|
return (
|
|
76
41
|
<MainProvider value={{ admin: isAdmin , translations: data.translations, language: pageContext.page?.language }}>
|
|
77
42
|
<div
|
|
78
43
|
dir={
|
|
79
|
-
(
|
|
44
|
+
(pageContext.page?.language === 'ar')
|
|
80
45
|
? 'rtl'
|
|
81
46
|
: 'ltr'
|
|
82
47
|
}
|
|
83
48
|
id="container-modules"
|
|
84
49
|
>
|
|
85
|
-
<Body pageContext={
|
|
50
|
+
<Body pageContext={pageContext} />
|
|
86
51
|
</div>
|
|
87
52
|
</MainProvider>
|
|
88
53
|
);
|
|
@@ -23,6 +23,21 @@
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
|
|
27
|
+
.label {
|
|
28
|
+
@include flex-align(center, flex-start);
|
|
29
|
+
|
|
30
|
+
color: #fff;
|
|
31
|
+
font-size: 1.3rem;
|
|
32
|
+
padding: 1rem 2rem;
|
|
33
|
+
gap: .5rem;
|
|
34
|
+
font-weight: bold;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.labelBorder {
|
|
38
|
+
border-top: 1px solid #fff;
|
|
39
|
+
}
|
|
40
|
+
|
|
26
41
|
.menuList {
|
|
27
42
|
@include flex-align(center, center);
|
|
28
43
|
|
|
@@ -45,4 +60,15 @@
|
|
|
45
60
|
@include flex-align(center, flex-start);
|
|
46
61
|
}
|
|
47
62
|
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.preview {
|
|
66
|
+
background-color: #00b9eb;
|
|
67
|
+
color: #23282d;
|
|
68
|
+
font-weight: bold;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.previewOff {
|
|
72
|
+
background-color: #23282d;
|
|
73
|
+
color: #fff;
|
|
48
74
|
}
|
|
@@ -35,7 +35,9 @@ const getRelationLinks = (page) => {
|
|
|
35
35
|
|
|
36
36
|
return (
|
|
37
37
|
<>
|
|
38
|
-
<li
|
|
38
|
+
<li>
|
|
39
|
+
<span className={`${styles.label}`}>Relations</span>
|
|
40
|
+
</li>
|
|
39
41
|
<li>
|
|
40
42
|
<a
|
|
41
43
|
className={styles.menuItem}
|
|
@@ -73,7 +75,7 @@ const getFooterLinks = (section) => {
|
|
|
73
75
|
};
|
|
74
76
|
|
|
75
77
|
const AdminBar = ({ page, marketSections, menu }) => {
|
|
76
|
-
const { setShowTranslationKeys } = useContext(Context) || {};
|
|
78
|
+
const { setShowTranslationKeys, preview } = useContext(Context) || {};
|
|
77
79
|
const [val, setVal] = useState(false);
|
|
78
80
|
|
|
79
81
|
const navSection = marketSections && marketSections.navigation;
|
|
@@ -112,45 +114,66 @@ const AdminBar = ({ page, marketSections, menu }) => {
|
|
|
112
114
|
Show translation keys
|
|
113
115
|
</label>
|
|
114
116
|
</li>
|
|
117
|
+
<li>|</li>
|
|
118
|
+
<li>
|
|
119
|
+
<span className={styles.menuItem}>
|
|
120
|
+
<MdArtTrack /> Layout
|
|
121
|
+
</span>
|
|
122
|
+
<ul className={styles.subMenuList}>
|
|
123
|
+
<li>
|
|
124
|
+
<span className={`${styles.label}`}>Navigation Section</span>
|
|
125
|
+
</li>
|
|
126
|
+
<li>
|
|
127
|
+
{menuObj && (
|
|
128
|
+
<a
|
|
129
|
+
className={styles.menuItem}
|
|
130
|
+
target="_blank"
|
|
131
|
+
href={`${process.env.HERCULES_BACKEND_URL}site-menus/${menuObj.menu_id}/items`}
|
|
132
|
+
rel="noreferrer"
|
|
133
|
+
>
|
|
134
|
+
<FaLayerGroup /> Edit Main Menu
|
|
135
|
+
</a>
|
|
136
|
+
)}
|
|
137
|
+
</li>
|
|
138
|
+
<li>
|
|
139
|
+
<span className={`${styles.label} ${styles.labelBorder}`}>Footer Section</span>
|
|
140
|
+
</li>
|
|
141
|
+
{footerExtraFields && getFooterLinks(footerExtraFields)}
|
|
142
|
+
</ul>
|
|
143
|
+
</li>
|
|
144
|
+
|
|
115
145
|
<li>
|
|
116
146
|
<span className={styles.menuItem}>
|
|
117
|
-
<
|
|
147
|
+
<FaEdit /> Page
|
|
118
148
|
</span>
|
|
119
149
|
<ul className={styles.subMenuList}>
|
|
120
|
-
|
|
150
|
+
<li>
|
|
121
151
|
<a
|
|
122
152
|
className={styles.menuItem}
|
|
123
153
|
target="_blank"
|
|
124
|
-
href={`${process.env.HERCULES_BACKEND_URL}site-
|
|
154
|
+
href={`${process.env.HERCULES_BACKEND_URL}site-pages/${page.id}`}
|
|
125
155
|
rel="noreferrer"
|
|
126
156
|
>
|
|
127
|
-
<
|
|
157
|
+
<FaEdit /> Edit Page
|
|
128
158
|
</a>
|
|
129
|
-
|
|
159
|
+
</li>
|
|
160
|
+
{getRelationLinks(page)}
|
|
130
161
|
</ul>
|
|
131
162
|
</li>
|
|
132
|
-
{footerExtraFields && (
|
|
133
|
-
<li>
|
|
134
|
-
<span className={styles.menuItem}>
|
|
135
|
-
<MdArtTrack /> Footer Section
|
|
136
|
-
</span>
|
|
137
163
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
</ul>
|
|
141
|
-
</li>
|
|
142
|
-
)}
|
|
164
|
+
{!preview && <li>|</li>}
|
|
165
|
+
|
|
143
166
|
<li>
|
|
144
167
|
<a
|
|
145
|
-
className={styles.menuItem}
|
|
146
|
-
|
|
147
|
-
|
|
168
|
+
className={`${styles.menuItem} ${styles.preview} ${
|
|
169
|
+
!preview ? styles.previewOff : ""
|
|
170
|
+
}`}
|
|
171
|
+
href={!preview ? `/preview/?path=${page.path}&market_id=${page.market_id}` : `${page.path}`}
|
|
148
172
|
rel="noreferrer"
|
|
149
173
|
>
|
|
150
|
-
|
|
174
|
+
{preview ? "Preview Mode On" : "Preview Mode Off"}
|
|
151
175
|
</a>
|
|
152
176
|
</li>
|
|
153
|
-
{getRelationLinks(page)}
|
|
154
177
|
</ul>
|
|
155
178
|
</div>
|
|
156
179
|
</div>
|
|
@@ -160,6 +183,8 @@ const AdminBar = ({ page, marketSections, menu }) => {
|
|
|
160
183
|
AdminBar.propTypes = {
|
|
161
184
|
page: PropTypes.shape({
|
|
162
185
|
id: PropTypes.number,
|
|
186
|
+
market_id: PropTypes.number,
|
|
187
|
+
path: PropTypes.string,
|
|
163
188
|
}),
|
|
164
189
|
marketSections: PropTypes.shape({
|
|
165
190
|
navigation: PropTypes.shape({}),
|
|
@@ -47,7 +47,7 @@ const Footer = (props) => {
|
|
|
47
47
|
const getFooterLogos = () => {
|
|
48
48
|
let refactoredFooterLogos = { children: [] };
|
|
49
49
|
|
|
50
|
-
if (footerLogos === null) {
|
|
50
|
+
if (footerLogos === null || !footerLogos.children) {
|
|
51
51
|
refactoredFooterLogos = {
|
|
52
52
|
children: [...page?.page?.responsibleGaming],
|
|
53
53
|
};
|
package/src/helpers/api.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import axios from 'axios';
|
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { groupBy } from './getters.mjs';
|
|
5
|
-
import processor from './processor/index.mjs';
|
|
6
5
|
|
|
7
6
|
// const axios = require('axios');
|
|
8
7
|
// const chalk = require('chalk');
|
|
@@ -11,36 +10,6 @@ const API_URL = process.env.GATSBY_API_URL;
|
|
|
11
10
|
|
|
12
11
|
/* eslint no-console: ["error", { allow: ["log"] }] */
|
|
13
12
|
|
|
14
|
-
export async function getPreview(siteName, page = null, marketId, themeOptions) {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
axios
|
|
17
|
-
.get(
|
|
18
|
-
`${API_URL}/sites/v0.1/pages/sorted?site_name=${siteName}&path=${page}&market_id=${marketId}&preview=1&relations=1`
|
|
19
|
-
)
|
|
20
|
-
.then((response) => {
|
|
21
|
-
console.log(response);
|
|
22
|
-
const pagePreview = response.data.result.pages.preview;
|
|
23
|
-
const processed = processor.run(response.data.result, themeOptions, null, null, true);
|
|
24
|
-
|
|
25
|
-
const { path } = processed.pages[pagePreview.market].preview[0];
|
|
26
|
-
|
|
27
|
-
const pagePreviewProcessed = processed.pages[pagePreview.market][
|
|
28
|
-
pagePreview.relation_type
|
|
29
|
-
// eslint-disable-next-line no-shadow
|
|
30
|
-
].find((page) => page.path === path);
|
|
31
|
-
|
|
32
|
-
resolve({
|
|
33
|
-
marketSections: processed.market_sections[pagePreview.market],
|
|
34
|
-
prefilledModules: processed.prefilled_market_modules[pagePreview.market],
|
|
35
|
-
page: pagePreviewProcessed,
|
|
36
|
-
allMarkets: processed.site_markets,
|
|
37
|
-
siteInfo: processed.general,
|
|
38
|
-
});
|
|
39
|
-
})
|
|
40
|
-
.catch((error) => reject(error));
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
13
|
function callAPIV2(endpointPath) {
|
|
45
14
|
const headers = {
|
|
46
15
|
headers: {
|
|
@@ -65,6 +34,7 @@ function callAPIV2(endpointPath) {
|
|
|
65
34
|
resolve(response.data.result);
|
|
66
35
|
})
|
|
67
36
|
.catch((error) => {
|
|
37
|
+
console.log(error);
|
|
68
38
|
reject(error.response.data.errors.join());
|
|
69
39
|
});
|
|
70
40
|
});
|
|
@@ -92,6 +62,10 @@ export async function getSiteSettings(siteName) {
|
|
|
92
62
|
return callAPIV2(`v0.1/sites/settings/sorted-v2/${siteName}`);
|
|
93
63
|
}
|
|
94
64
|
|
|
65
|
+
export async function getPages(siteName) {
|
|
66
|
+
return callAPIV2(`v0.1/sites/pages/sorted-v2/${siteName}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
95
69
|
export async function getRibbons(params) {
|
|
96
70
|
return callAPIV2(`v0.1/globals/ribbons/sorted${params ? `?${params}` : ''}`);
|
|
97
71
|
}
|
|
@@ -112,15 +86,16 @@ export async function getContent(siteName) {
|
|
|
112
86
|
return callAPIV2(`v0.1/content/sorted/${siteName}`)
|
|
113
87
|
}
|
|
114
88
|
|
|
115
|
-
export async function getData(siteName, page = null) {
|
|
89
|
+
export async function getData(siteName, page = null, marketId = null, preview = false) {
|
|
116
90
|
let path = `${API_URL}/sites/v0.1/pages/sorted?site_name=${siteName}`;
|
|
117
|
-
|
|
91
|
+
|
|
118
92
|
if (page) {
|
|
119
93
|
path += `&path=${page}`;
|
|
94
|
+
if(preview) path +=`&market_id=${marketId}&preview=1`
|
|
120
95
|
}
|
|
121
96
|
path += '&reverse_order=1&relations=1';
|
|
122
97
|
console.log(chalk.magenta('calling ') + chalk.whiteBright(path));
|
|
123
|
-
|
|
98
|
+
|
|
124
99
|
const start = new Date();
|
|
125
100
|
return new Promise((resolve, reject) => {
|
|
126
101
|
axios
|
|
@@ -135,15 +110,16 @@ export async function getData(siteName, page = null) {
|
|
|
135
110
|
});
|
|
136
111
|
});
|
|
137
112
|
}
|
|
138
|
-
|
|
113
|
+
|
|
139
114
|
export async function getLocalData(fs) {
|
|
140
115
|
return new Promise((resolve, reject) => {
|
|
141
116
|
if (!fs.existsSync('./src/data/source/data.json')) {
|
|
142
117
|
reject(new Error('Local Data file not found!'));
|
|
143
118
|
}
|
|
144
|
-
|
|
119
|
+
|
|
145
120
|
let response = fs.readFileSync('./src/data/source/data.json');
|
|
146
121
|
response = JSON.parse(response);
|
|
147
122
|
resolve(response.result);
|
|
148
123
|
});
|
|
149
124
|
}
|
|
125
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
import {
|
|
3
|
+
getSiteSettings,
|
|
4
|
+
getRibbons,
|
|
5
|
+
getResponsableGamings,
|
|
6
|
+
getContent,
|
|
7
|
+
getToplists,
|
|
8
|
+
getPages
|
|
9
|
+
} from "./api.mjs";
|
|
10
|
+
|
|
11
|
+
export const fetchSiteSettings = async (siteName, isPreview) => {
|
|
12
|
+
const siteSettingsData = await getSiteSettings(siteName);
|
|
13
|
+
const ribbonsData = await getRibbons(`site=${process.env.GATSBY_SITE_NAME}`);
|
|
14
|
+
const siteId = Object.keys(siteSettingsData.general)[0];
|
|
15
|
+
const responsableGamingData = await getResponsableGamings(
|
|
16
|
+
process.env.GATSBY_SITE_NAME,
|
|
17
|
+
siteId
|
|
18
|
+
);
|
|
19
|
+
const toplistData = await getToplists(process.env.GATSBY_SITE_NAME);
|
|
20
|
+
const contentData = await getContent(process.env.GATSBY_SITE_NAME);
|
|
21
|
+
const pagesData = !isPreview ? await getPages(process.env.GATSBY_SITE_NAME) : null;
|
|
22
|
+
|
|
23
|
+
const allMarketsData = siteSettingsData.site_markets;
|
|
24
|
+
const allMarketPrefixes = Object.keys(allMarketsData)
|
|
25
|
+
.map((key) => allMarketsData[key].path_prefix)
|
|
26
|
+
.filter((item) => !!item);
|
|
27
|
+
|
|
28
|
+
const schemaData = siteSettingsData.schema;
|
|
29
|
+
const templatesData = siteSettingsData.templates;
|
|
30
|
+
const allMarketSectionsData = siteSettingsData.market_sections;
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
siteSettingsData,
|
|
34
|
+
siteGeneralData: siteSettingsData.general[siteId],
|
|
35
|
+
allMarketsData,
|
|
36
|
+
allMarketPrefixes,
|
|
37
|
+
schemaData,
|
|
38
|
+
templatesData,
|
|
39
|
+
pagesData,
|
|
40
|
+
allMarketSectionsData,
|
|
41
|
+
ribbonsData,
|
|
42
|
+
responsableGamingData,
|
|
43
|
+
toplistData,
|
|
44
|
+
contentData
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
|
|
3
|
+
export function mergeMarketValues(relation, currentMarket) {
|
|
4
|
+
const marketValues =
|
|
5
|
+
(relation?.markets && relation?.markets[currentMarket]) || {};
|
|
6
|
+
|
|
7
|
+
const mergedValues = Object.keys(relation).reduce((acc, key) => {
|
|
8
|
+
acc[key] =
|
|
9
|
+
marketValues[key] !== "" && marketValues[key] !== undefined
|
|
10
|
+
? marketValues[key]
|
|
11
|
+
: relation[key];
|
|
12
|
+
return acc;
|
|
13
|
+
}, {});
|
|
14
|
+
|
|
15
|
+
return mergedValues;
|
|
16
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { mergeMarketValues } from "./game.mjs";
|
|
2
|
+
|
|
3
|
+
describe("mergeMarketValues", () => {
|
|
4
|
+
test("should return original relation values when there are no market values", () => {
|
|
5
|
+
const relation = {
|
|
6
|
+
id: 1,
|
|
7
|
+
name: "Test",
|
|
8
|
+
markets: {},
|
|
9
|
+
};
|
|
10
|
+
const result = mergeMarketValues(relation, "che_fr");
|
|
11
|
+
expect(result).toEqual({
|
|
12
|
+
id: 1,
|
|
13
|
+
name: "Test",
|
|
14
|
+
markets: {},
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("should merge market values and relation values", () => {
|
|
19
|
+
const relation = {
|
|
20
|
+
id: 1,
|
|
21
|
+
name: "Test",
|
|
22
|
+
description: "Original description",
|
|
23
|
+
markets: {
|
|
24
|
+
che_fr: {
|
|
25
|
+
description: "Market description Switzerland",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const result = mergeMarketValues(relation, "che_fr");
|
|
30
|
+
expect(result).toEqual({
|
|
31
|
+
id: 1,
|
|
32
|
+
name: "Test",
|
|
33
|
+
description: "Market description Switzerland",
|
|
34
|
+
markets: {
|
|
35
|
+
che_fr: {
|
|
36
|
+
description: "Market description Switzerland",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("should return relation values when market values are empty strings", () => {
|
|
43
|
+
const relation = {
|
|
44
|
+
id: 1,
|
|
45
|
+
name: "Test",
|
|
46
|
+
description: "Original description",
|
|
47
|
+
markets: {
|
|
48
|
+
che_fr: {
|
|
49
|
+
description: "",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const result = mergeMarketValues(relation, "che_fr");
|
|
54
|
+
expect(result).toEqual({
|
|
55
|
+
id: 1,
|
|
56
|
+
name: "Test",
|
|
57
|
+
description: "Original description",
|
|
58
|
+
markets: {
|
|
59
|
+
che_fr: {
|
|
60
|
+
description: "",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("should prefer market values when they are non-empty", () => {
|
|
67
|
+
const relation = {
|
|
68
|
+
id: 1,
|
|
69
|
+
name: "Test",
|
|
70
|
+
description: "Original description",
|
|
71
|
+
markets: {
|
|
72
|
+
che_fr: {
|
|
73
|
+
description: "Updated Switzerland description",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const result = mergeMarketValues(relation, "che_fr");
|
|
78
|
+
expect(result).toEqual({
|
|
79
|
+
id: 1,
|
|
80
|
+
name: "Test",
|
|
81
|
+
description: "Updated Switzerland description",
|
|
82
|
+
markets: {
|
|
83
|
+
che_fr: {
|
|
84
|
+
description: "Updated Switzerland description",
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("should return original relation if no matching market", () => {
|
|
91
|
+
const relation = {
|
|
92
|
+
id: 1,
|
|
93
|
+
name: "Test",
|
|
94
|
+
description: "Original description",
|
|
95
|
+
markets: {
|
|
96
|
+
UK: {
|
|
97
|
+
description: "Market description UK",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
const result = mergeMarketValues(relation, "che_fr");
|
|
102
|
+
expect(result).toEqual({
|
|
103
|
+
id: 1,
|
|
104
|
+
name: "Test",
|
|
105
|
+
description: "Original description",
|
|
106
|
+
markets: {
|
|
107
|
+
UK: {
|
|
108
|
+
description: "Market description UK",
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -133,7 +133,8 @@ export function processCardsV2(
|
|
|
133
133
|
module.cards_selector_filters && module.cards_selector_filters.categories;
|
|
134
134
|
const moduleSelectedTypes =
|
|
135
135
|
module.cards_selector_filters && module.cards_selector_filters.types;
|
|
136
|
-
|
|
136
|
+
|
|
137
|
+
const market = pagesMappedById[pageId] ? pagesMappedById[pageId].market : '';
|
|
137
138
|
|
|
138
139
|
module.items = [];
|
|
139
140
|
|
|
@@ -3,6 +3,7 @@ import loadash from 'lodash/index.js';
|
|
|
3
3
|
import { updateArrayTranslations } from '../getters.mjs';
|
|
4
4
|
// eslint-disable-next-line import/named
|
|
5
5
|
import { sanitizeOperatorData } from './operators.mjs';
|
|
6
|
+
import { mergeMarketValues } from './game.mjs';
|
|
6
7
|
import { pickRelationKeys } from '../../constants/pick-keys.mjs';
|
|
7
8
|
|
|
8
9
|
const { pick, cloneDeep } = loadash;
|
|
@@ -43,7 +44,8 @@ export const processRelations = (
|
|
|
43
44
|
: [];
|
|
44
45
|
transformedPages[market][pageType][index].relation.game_provider.path =
|
|
45
46
|
providerPage.length > 0 ? providerPage[0].path : null;
|
|
46
|
-
page.relation = pick(page.relation, pickRelationKeys.game);
|
|
47
|
+
page.relation = pick(mergeMarketValues(page.relation, market), pickRelationKeys.game);
|
|
48
|
+
|
|
47
49
|
}
|
|
48
50
|
break;
|
|
49
51
|
// Add author for page from authors
|
|
@@ -4,15 +4,60 @@
|
|
|
4
4
|
import loadSource from '~helpers/search-source';
|
|
5
5
|
import { deparam } from '~helpers/strings';
|
|
6
6
|
import { groupBy } from '~helpers/getters';
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import {getData} from '~helpers/api'
|
|
8
|
+
import processor from "./processor/index.mjs";
|
|
9
|
+
import { fetchSiteSettings } from './fetch-site-settings.mjs';
|
|
10
|
+
|
|
11
|
+
export async function getAPIData(page, url, headers, preview) {
|
|
12
|
+
if (preview) {
|
|
13
|
+
try {
|
|
14
|
+
const siteName = process.env.GATSBY_SITE_NAME;
|
|
15
|
+
const params = deparam(url.split('?')[1]);
|
|
16
|
+
// eslint-disable-next-line camelcase
|
|
17
|
+
const response = await getData(siteName, params?.path, params?.market_id, true);
|
|
18
|
+
const {siteSettingsData, siteGeneralData, responsableGamingData, toplistData, contentData} = await fetchSiteSettings(siteName, true);
|
|
19
|
+
|
|
20
|
+
const pagePreview = response.pages.preview;
|
|
21
|
+
|
|
22
|
+
const processed = processor.run({
|
|
23
|
+
...response,
|
|
24
|
+
siteSettingsData,
|
|
25
|
+
general: siteGeneralData,
|
|
26
|
+
prefilled_market_modules:siteSettingsData.prefilled_modules,
|
|
27
|
+
responsible_gamings: responsableGamingData,
|
|
28
|
+
toplist: toplistData,
|
|
29
|
+
content: contentData
|
|
30
|
+
},{}, null, true);
|
|
31
|
+
|
|
32
|
+
const { path } = processed.pages[pagePreview.market].preview[0];
|
|
33
|
+
|
|
34
|
+
const pagePreviewProcessed = processed.pages[pagePreview.market][
|
|
35
|
+
pagePreview.relation_type
|
|
36
|
+
// eslint-disable-next-line no-shadow
|
|
37
|
+
].find((page) => page.path === path);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
props: {
|
|
41
|
+
marketSections: processed.market_sections[pagePreview.market],
|
|
42
|
+
prefilledModules: processed.prefilled_market_modules[pagePreview.market],
|
|
43
|
+
page: pagePreviewProcessed,
|
|
44
|
+
allMarkets: processed.site_markets,
|
|
45
|
+
siteInfo: processed.general
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
} catch (error) {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.log("Error fetching preview data:", error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
9
54
|
const results = await loadSource(page.market);
|
|
10
55
|
if (page.path.endsWith('/s') || page.path === 's') {
|
|
11
56
|
let urlParams = null;
|
|
12
57
|
if (url && url.split('?').length === 2) {
|
|
13
58
|
urlParams = deparam(`${url.split('?')[1]}`);
|
|
14
59
|
}
|
|
15
|
-
|
|
60
|
+
|
|
16
61
|
const searchData = urlParams
|
|
17
62
|
? urlParams.hasOwnProperty('s')
|
|
18
63
|
? groupBy(
|
|
@@ -21,7 +66,7 @@ export async function getAPIData(page, url) {
|
|
|
21
66
|
)
|
|
22
67
|
: null
|
|
23
68
|
: null;
|
|
24
|
-
|
|
69
|
+
|
|
25
70
|
return {
|
|
26
71
|
props: {
|
|
27
72
|
data: searchData,
|
|
@@ -29,11 +74,11 @@ export async function getAPIData(page, url) {
|
|
|
29
74
|
},
|
|
30
75
|
};
|
|
31
76
|
}
|
|
32
|
-
|
|
77
|
+
|
|
33
78
|
const res = await fetch(`https://random-data-api.com/api/appliance/random_appliance/`);
|
|
34
79
|
const data = await res.json();
|
|
35
|
-
|
|
80
|
+
|
|
36
81
|
return {
|
|
37
82
|
props: data.equipment,
|
|
38
83
|
};
|
|
39
|
-
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* eslint-disable react/prop-types */
|
|
2
|
+
/* eslint-disable react/forbid-prop-types */
|
|
3
|
+
import React, {useState, useEffect} from "react";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import { graphql, useStaticQuery } from "gatsby";
|
|
6
|
+
import { getCookie } from "~helpers/cookies";
|
|
7
|
+
import MainProvider from "~context/MainProvider";
|
|
8
|
+
import Body from "~pages/body";
|
|
9
|
+
import HeadData from "~organisms/head";
|
|
10
|
+
import { getAPIData } from "~helpers/server-data";
|
|
11
|
+
|
|
12
|
+
const AppSSR = ({serverData }) => {
|
|
13
|
+
const [isAdmin, setIsAdmin] = useState(false);
|
|
14
|
+
|
|
15
|
+
const data = useStaticQuery(graphql`
|
|
16
|
+
query {
|
|
17
|
+
translations: allTranslation(filter: {}) {
|
|
18
|
+
edges {
|
|
19
|
+
node {
|
|
20
|
+
key
|
|
21
|
+
language
|
|
22
|
+
value
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`);
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (
|
|
32
|
+
typeof window !== `undefined` &&
|
|
33
|
+
getCookie("showAdminBar") === "true"
|
|
34
|
+
) {
|
|
35
|
+
setIsAdmin(true);
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
+
}, []);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<MainProvider
|
|
43
|
+
value={{
|
|
44
|
+
admin: isAdmin ,
|
|
45
|
+
translations: data.translations,
|
|
46
|
+
language: serverData.page.language,
|
|
47
|
+
isPreview: true
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<Body
|
|
51
|
+
pageContext={serverData}
|
|
52
|
+
/>
|
|
53
|
+
</MainProvider>
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const Head = ({ serverData }) => (
|
|
59
|
+
<HeadData page={serverData.page} siteInfo={serverData.siteInfo} />
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
AppSSR.propTypes = {
|
|
63
|
+
pageContext: PropTypes.shape({
|
|
64
|
+
siteName: PropTypes.string,
|
|
65
|
+
isTracker: PropTypes.bool,
|
|
66
|
+
isPreview: PropTypes.bool,
|
|
67
|
+
page: PropTypes.shape({
|
|
68
|
+
id: PropTypes.number,
|
|
69
|
+
path: PropTypes.string,
|
|
70
|
+
}),
|
|
71
|
+
translations: PropTypes.object,
|
|
72
|
+
siteInfo: PropTypes.shape({
|
|
73
|
+
robots_txt: PropTypes.string,
|
|
74
|
+
site_logo: PropTypes.string,
|
|
75
|
+
site_name: PropTypes.string,
|
|
76
|
+
}),
|
|
77
|
+
siteSchema: PropTypes.shape({
|
|
78
|
+
site_name: PropTypes.string,
|
|
79
|
+
}),
|
|
80
|
+
}),
|
|
81
|
+
serverData: PropTypes.any,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default AppSSR;
|
|
85
|
+
|
|
86
|
+
export async function getServerData(props) {
|
|
87
|
+
// eslint-disable-next-line no-shadow
|
|
88
|
+
const { pageContext, url, headers } = props;
|
|
89
|
+
let res = "";
|
|
90
|
+
res = await getAPIData(pageContext.page, url, headers, true);
|
|
91
|
+
|
|
92
|
+
return res;
|
|
93
|
+
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import { globalHistory } from '@reach/router';
|
|
5
|
-
|
|
6
|
-
// import Body from '~pages/body';
|
|
7
|
-
// import Head from '~organisms/head';
|
|
8
|
-
// import { getPreview } from '~helpers/api';
|
|
9
|
-
|
|
10
|
-
const AppPreview = ({ pageContext }) => {
|
|
11
|
-
const [previewContext, setPreviewContext] = useState({});
|
|
12
|
-
const [isLoading, setIsLoading] = useState({});
|
|
13
|
-
|
|
14
|
-
async function getData(searchParams, staticPath = null) {
|
|
15
|
-
const { getPreview } = await import('~helpers/api');
|
|
16
|
-
getPreview(
|
|
17
|
-
pageContext.siteName,
|
|
18
|
-
!staticPath ? searchParams.get('path') || '/' : staticPath,
|
|
19
|
-
pageContext
|
|
20
|
-
).then((previewResponse) => {
|
|
21
|
-
setPreviewContext(previewResponse);
|
|
22
|
-
setIsLoading(false);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
setIsLoading(true);
|
|
28
|
-
const searchParams =
|
|
29
|
-
typeof window !== 'undefined' ? new URLSearchParams(window.location.search) : null;
|
|
30
|
-
if (!searchParams.get('path')) {
|
|
31
|
-
window.location = `${window.location.origin}/preview?path=/`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getData(searchParams);
|
|
35
|
-
// let { hi, bye } = await import('./say.js');
|
|
36
|
-
// getPreview(pageContext.siteName, searchParams.get('path') || '/', pageContext).then(
|
|
37
|
-
// (previewResponse) => {
|
|
38
|
-
// setPreviewContext(previewResponse);
|
|
39
|
-
// setIsLoading(false);
|
|
40
|
-
// }
|
|
41
|
-
// );
|
|
42
|
-
|
|
43
|
-
globalHistory.listen(({ location }) => {
|
|
44
|
-
setIsLoading(true);
|
|
45
|
-
|
|
46
|
-
getData(null, location.search.replace('?path=', ''));
|
|
47
|
-
// getPreview(pageContext.siteName, location.search.replace('?path=', ''), pageContext)
|
|
48
|
-
// .then((previewResponse) => {
|
|
49
|
-
// setPreviewContext(previewResponse);
|
|
50
|
-
// setIsLoading(false);
|
|
51
|
-
// })
|
|
52
|
-
// .catch(() => {
|
|
53
|
-
// alert('failed to load..');
|
|
54
|
-
// });
|
|
55
|
-
});
|
|
56
|
-
// eslint-disable-next-line
|
|
57
|
-
}, [pageContext.siteName]);
|
|
58
|
-
|
|
59
|
-
if (isLoading) {
|
|
60
|
-
return 'Loading...';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<>
|
|
65
|
-
{/* <Head page={previewContext.page} siteInfo={previewContext.siteInfo} />
|
|
66
|
-
<Body pageContext={previewContext} /> */}
|
|
67
|
-
</>
|
|
68
|
-
);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
AppPreview.propTypes = {
|
|
72
|
-
pageContext: PropTypes.shape({
|
|
73
|
-
page: PropTypes.shape({
|
|
74
|
-
id: PropTypes.number,
|
|
75
|
-
}),
|
|
76
|
-
siteName: PropTypes.string,
|
|
77
|
-
siteInfo: PropTypes.shape({
|
|
78
|
-
robots_txt: PropTypes.string,
|
|
79
|
-
site_logo: PropTypes.string,
|
|
80
|
-
site_name: PropTypes.string,
|
|
81
|
-
}),
|
|
82
|
-
}),
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export default AppPreview;
|