gatsby-core-theme 40.0.2 → 40.0.3

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 CHANGED
@@ -1,3 +1,26 @@
1
+ ## [40.0.3](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v40.0.2...v40.0.3) (2024-10-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * added tests for game.mjs ([4d3848c](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/4d3848c7a55c3bbdc2d603ce3f08ec7e665bff09))
7
+ * admin bar ([e9f3430](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/e9f3430a9cded767cef9647baf37df9151c34be7))
8
+ * clean up ([8a413b0](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/8a413b09fa3ab645511d4ca20a65175ba3d9cc77))
9
+ * fix prevview ([fe5a7e8](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/fe5a7e88edda1f6fe99994e298f0c263cd79f6fb))
10
+ * game sanitization ([502e6fd](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/502e6fd020ab3f4cc5b80e029be9d5741d6d058d))
11
+ * premain ([c06770c](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/c06770c3064f1c49fcf1b595bfddbb97b2be97b1))
12
+ * preview logic ([ddc883d](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/ddc883d8261484eb3c6bc4137206aefd3cc18f22))
13
+ * sitemap changes ([1198642](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/11986422dcf9930d1a199213c49e8e7182d053d0))
14
+ * sitemap changes ([600b0bc](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/600b0bcf8aad82f403ffa6991ca531261cb29565))
15
+ * sitemap changes ([1dd5f66](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/1dd5f6639b3493711676f7b5b79fae001b681bc0))
16
+ * update relations mjs ([c3c6cc8](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/c3c6cc8dd924f68ab640a63629a329755ec65be0))
17
+
18
+
19
+ * Merge branch 'tm-4857-sitemap-changes' into 'master' ([6924cb1](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/6924cb19082dc397f22975d1a5d87064e555bc5c))
20
+ * Merge branch 'tm-4682-previewLogic' into 'master' ([b3f573c](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/b3f573ce4153cae6a087b1b1b89b0017b900ea70))
21
+ * Merge branch 'merge-market-values-before' into 'master' ([7feb898](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/7feb8981db130d7b18d69e4ec8d42a3716d53657))
22
+ * Merge branch 'master' into tm-4682-previewLogic ([cd7d01f](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/cd7d01f9e77158712c2a18a7deac564349eea4a6))
23
+
1
24
  ## [40.0.2](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v40.0.1...v40.0.2) (2024-10-11)
2
25
 
3
26
 
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, getSiteSettings, getRibbons, getResponsableGamings, getToplists, getContent } from './src/helpers/api.mjs';
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;
@@ -430,7 +431,7 @@ export const createPages = async ({ actions: { createPage } }, themeOptions) =>
430
431
 
431
432
  export const onCreatePage = async ({ page, actions }) => {
432
433
  const { createPage, deletePage } = actions;
433
-
434
+
434
435
  if (is404Page(allMarketPrefixes, page.path)) {
435
436
  const oldPage = { ...page };
436
437
  const pathPrefix = page.path.split(`/`)[1];
@@ -463,7 +464,13 @@ export const onCreatePage = async ({ page, actions }) => {
463
464
  component: `${__dirname}/src/components/app.js`,
464
465
  context: context404,
465
466
  });
466
- } else {
467
+ }
468
+ else if (page.path.includes('preview')) {
469
+ createPage({
470
+ ...page
471
+ });
472
+ }
473
+ else {
467
474
  createPage({
468
475
  path: page.path,
469
476
  component: `${__dirname}/src/components/app.js`,
@@ -474,21 +481,18 @@ export const onCreatePage = async ({ page, actions }) => {
474
481
 
475
482
  export const onPreBootstrap = async () => {
476
483
  // Get Data from Hercules
477
- siteSettingsData = await getSiteSettings(process.env.GATSBY_SITE_NAME);
478
- ribbonsData = await getRibbons(`site=${process.env.GATSBY_SITE_NAME}`);
479
- const siteId = Object.keys(siteSettingsData.general)[0];
480
- responsableGamingData = await getResponsableGamings(process.env.GATSBY_SITE_NAME, siteId);
481
- toplistData = await getToplists(process.env.GATSBY_SITE_NAME);
482
- contentData = await getContent(process.env.GATSBY_SITE_NAME);
483
-
484
- siteGeneralData = siteSettingsData.general[siteId]
485
- allMarketsData = siteSettingsData.site_markets;
486
- allMarketPrefixes = Object.keys(allMarketsData).map(
487
- (key) => allMarketsData[key].path_prefix
488
- ).filter(item => !!item);
489
- schemaData = siteSettingsData.schema;
490
- templatesData = siteSettingsData.templates;
491
- allMarketSectionsData = siteSettingsData.market_sections;
484
+ ({siteSettingsData,
485
+ siteGeneralData,
486
+ allMarketsData,
487
+ allMarketPrefixes,
488
+ schemaData,
489
+ templatesData,
490
+ allMarketSectionsData,
491
+ ribbonsData,
492
+ responsableGamingData,
493
+ toplistData,
494
+ contentData,
495
+ pagesData } = await fetchSiteSettings(process.env.GATSBY_SITE_NAME));
492
496
  }
493
497
 
494
498
  export const sourceNodes = async ({ actions, createNodeId, createContentDigest }) => {
@@ -533,6 +537,35 @@ export const sourceNodes = async ({ actions, createNodeId, createContentDigest }
533
537
  createNode(node)
534
538
  });
535
539
  });
540
+
541
+ // eslint-disable-next-line array-callback-return
542
+ Object.keys(pagesData).map((pageId) => {
543
+ const page = pagesData[pageId]
544
+ if(page && page.robot_options && page.robot_options.page_index) {
545
+ const pageSitemap = {
546
+ 'path': page.path,
547
+ 'updated_at': page.updated_at,
548
+ 'market': page.market,
549
+ 'language': page.language
550
+ }
551
+
552
+ const nodeMeta = {
553
+ id: createNodeId(keygen()),
554
+ parent: null,
555
+ children: [],
556
+ internal: {
557
+ type: `Sitemap`,
558
+ mediaType: `text/html`,
559
+ contentDigest: createContentDigest(pageId),
560
+ },
561
+ };
562
+ const node = { ...pageSitemap, ...nodeMeta}
563
+ createNode(node)
564
+ }
565
+
566
+
567
+ })
568
+
536
569
  };
537
570
 
538
571
  export const onCreateWebpackConfig = ({ actions, stage, getConfig }) => {
@@ -566,4 +599,4 @@ export const onCreateWebpackConfig = ({ actions, stage, getConfig }) => {
566
599
  },
567
600
  },
568
601
  });
569
- };
602
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-core-theme",
3
- "version": "40.0.2",
3
+ "version": "40.0.3",
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": "^5.10.2",
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
- if (isPreview) {
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={isPreview ? previewContext : pageContext} serverData={serverData} />
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
+ }
@@ -9,9 +9,7 @@ import Body from '~pages/body';
9
9
  import HeadData from '~organisms/head';
10
10
 
11
11
  const App = ({ pageContext }) => {
12
- const { isPreview } = pageContext;
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
- (isPreview ? previewContext.page?.language === 'ar' : pageContext.page?.language === 'ar')
44
+ (pageContext.page?.language === 'ar')
80
45
  ? 'rtl'
81
46
  : 'ltr'
82
47
  }
83
48
  id="container-modules"
84
49
  >
85
- <Body pageContext={isPreview ? previewContext : 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>|</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
- <MdArtTrack /> Navigation Section
147
+ <FaEdit /> Page
118
148
  </span>
119
149
  <ul className={styles.subMenuList}>
120
- {menuObj && (
150
+ <li>
121
151
  <a
122
152
  className={styles.menuItem}
123
153
  target="_blank"
124
- href={`${process.env.HERCULES_BACKEND_URL}site-menus/${menuObj.menu_id}/items`}
154
+ href={`${process.env.HERCULES_BACKEND_URL}site-pages/${page.id}`}
125
155
  rel="noreferrer"
126
156
  >
127
- <FaLayerGroup /> Edit Main Menu
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
- <ul className={styles.subMenuList}>
139
- {getFooterLinks(footerExtraFields)}
140
- </ul>
141
- </li>
142
- )}
164
+ {!preview && <li>|</li>}
165
+
143
166
  <li>
144
167
  <a
145
- className={styles.menuItem}
146
- target="_blank"
147
- href={`${process.env.HERCULES_BACKEND_URL}site-pages/${page.id}`}
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
- <FaEdit /> Edit Page
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({}),
@@ -102,7 +102,6 @@ export const pickRelationKeys = {
102
102
  'thumbnail_filename_object',
103
103
  'name',
104
104
  'iframe',
105
- 'markets',
106
105
  'average_rating',
107
106
  'maximum_bet',
108
107
  'volatility',
@@ -12,6 +12,7 @@ export default (props) => {
12
12
  <Context.Provider
13
13
  value={{
14
14
  translations: value.translations,
15
+ preview: value.isPreview,
15
16
  language: value.language,
16
17
  admin: value.admin,
17
18
  showTranslationKeys,
@@ -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
- const { market } = pagesMappedById[pageId];
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
- export async function getAPIData(page, url) {
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, 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,95 @@
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
+
41
+ return (
42
+ <>
43
+ <MainProvider
44
+ value={{
45
+ admin: isAdmin ,
46
+ translations: data.translations,
47
+ language: serverData.page.language,
48
+ isPreview: true
49
+ }}
50
+ >
51
+ <Body
52
+ pageContext={serverData}
53
+ />
54
+ </MainProvider>
55
+ </>
56
+ );
57
+ };
58
+
59
+ export const Head = ({ serverData }) => (
60
+ <HeadData page={serverData.page} siteInfo={serverData.siteInfo} />
61
+ );
62
+
63
+ AppSSR.propTypes = {
64
+ pageContext: PropTypes.shape({
65
+ siteName: PropTypes.string,
66
+ isTracker: PropTypes.bool,
67
+ isPreview: PropTypes.bool,
68
+ page: PropTypes.shape({
69
+ id: PropTypes.number,
70
+ path: PropTypes.string,
71
+ }),
72
+ translations: PropTypes.object,
73
+ siteInfo: PropTypes.shape({
74
+ robots_txt: PropTypes.string,
75
+ site_logo: PropTypes.string,
76
+ site_name: PropTypes.string,
77
+ }),
78
+ siteSchema: PropTypes.shape({
79
+ site_name: PropTypes.string,
80
+ }),
81
+ }),
82
+ serverData: PropTypes.any,
83
+ };
84
+
85
+ export default AppSSR;
86
+
87
+ export async function getServerData(props) {
88
+ // eslint-disable-next-line no-shadow
89
+ const { pageContext, url, headers } = props;
90
+ let res = "";
91
+ const preview = pageContext.isPreview;
92
+ res = await getAPIData(pageContext.page, url, headers, preview);
93
+
94
+ return res;
95
+ }
@@ -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;