Skip to content

Commit e73152b

Browse files
committed
fix: made live preview as default option
1 parent 1d380dd commit e73152b

File tree

6 files changed

+32
-22
lines changed

6 files changed

+32
-22
lines changed

pages/about-us.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useEffect } from 'react';
2+
import getConfig from 'next/config';
23
import { onEntryChange } from '../sdk-plugin/index';
34
import Layout from '../components/layout';
45
import RenderComponents from '../components/render-components';
@@ -8,7 +9,7 @@ export default function About(props) {
89
const {
910
header, footer, result, entryUrl,
1011
} = props;
11-
12+
const { CONTENTSTACK_LIVE_PREVIEW } = getConfig().publicRuntimeConfig;
1213
const [getHeader, setHeader] = useState(header);
1314
const [getFooter, setFooter] = useState(footer);
1415
const [getEntry, setEntry] = useState(result);
@@ -28,7 +29,9 @@ export default function About(props) {
2829
}
2930

3031
useEffect(() => {
31-
onEntryChange(() => fetchData());
32+
onEntryChange(() => {
33+
if (CONTENTSTACK_LIVE_PREVIEW === 'true') fetchData();
34+
});
3235
}, []);
3336

3437
return (

pages/blog/[...post].jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2+
import getConfig from 'next/config';
23
import moment from 'moment';
34
import parse from 'html-react-parser';
45
import Layout from '../../components/layout';
@@ -17,7 +18,7 @@ export default function BlogPost(props) {
1718
const {
1819
header, banner, footer, result, entryUrl,
1920
} = props;
20-
21+
const { CONTENTSTACK_LIVE_PREVIEW } = getConfig().publicRuntimeConfig;
2122
const [getHeader, setHeader] = useState(header);
2223
const [getFooter, setFooter] = useState(footer);
2324
const [getEntry, setEntry] = useState(result);
@@ -40,7 +41,9 @@ export default function BlogPost(props) {
4041
}
4142

4243
useEffect(() => {
43-
onEntryChange(() => fetchData());
44+
onEntryChange(() => {
45+
if (CONTENTSTACK_LIVE_PREVIEW === 'true') fetchData();
46+
});
4447
}, []);
4548

4649
return (

pages/blog/index.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useEffect } from 'react';
2+
import getConfig from 'next/config';
23
import moment from 'moment';
34
import Link from 'next/link';
45
import parse from 'html-react-parser';
@@ -19,7 +20,7 @@ export default function Blog(props) {
1920
archived, blog, blogList, header, footer, entryUrl,
2021
} = props;
2122
const list = blogList.concat(archived);
22-
23+
const { CONTENTSTACK_LIVE_PREVIEW } = getConfig().publicRuntimeConfig;
2324
const [getHeader, setHeader] = useState(header);
2425
const [getFooter, setFooter] = useState(footer);
2526
const [getArchived, setArchived] = useState(archived);
@@ -41,7 +42,9 @@ export default function Blog(props) {
4142
}
4243

4344
useEffect(() => {
44-
onEntryChange(() => fetchData());
45+
onEntryChange(() => {
46+
if (CONTENTSTACK_LIVE_PREVIEW === 'true') fetchData();
47+
});
4548
}, []);
4649

4750
return (

pages/contact-us.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useEffect } from 'react';
2+
import getConfig from 'next/config';
23
import { onEntryChange } from '../sdk-plugin/index';
34
import Layout from '../components/layout';
45
import RenderComponents from '../components/render-components';
@@ -8,7 +9,7 @@ export default function Contact(props) {
89
const {
910
header, footer, result, entryUrl,
1011
} = props;
11-
12+
const { CONTENTSTACK_LIVE_PREVIEW } = getConfig().publicRuntimeConfig;
1213
const [getHeader, setHeader] = useState(header);
1314
const [getFooter, setFooter] = useState(footer);
1415
const [getEntry, setEntry] = useState(result);
@@ -28,7 +29,9 @@ export default function Contact(props) {
2829
}
2930

3031
useEffect(() => {
31-
onEntryChange(() => fetchData());
32+
onEntryChange(() => {
33+
if (CONTENTSTACK_LIVE_PREVIEW === 'true') fetchData();
34+
});
3235
}, []);
3336

3437
return (

pages/index.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useEffect } from 'react';
2+
import getConfig from 'next/config';
23
import { onEntryChange } from '../sdk-plugin/index';
34
import Layout from '../components/layout';
45
import RenderComponents from '../components/render-components';
@@ -8,7 +9,7 @@ export default function Home(props) {
89
const {
910
header, footer, result, entryUrl,
1011
} = props;
11-
12+
const { CONTENTSTACK_LIVE_PREVIEW } = getConfig().publicRuntimeConfig;
1213
const [getHeader, setHeader] = useState(header);
1314
const [getFooter, setFooter] = useState(footer);
1415
const [getEntry, setEntry] = useState(result);
@@ -28,7 +29,9 @@ export default function Home(props) {
2829
}
2930

3031
useEffect(() => {
31-
onEntryChange(fetchData);
32+
onEntryChange(() => {
33+
if (CONTENTSTACK_LIVE_PREVIEW === 'true') fetchData();
34+
});
3235
}, []);
3336

3437
return (

sdk-plugin/index.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,19 @@ const Stack = contentstack.Stack({
2020
enable: true,
2121
management_token: envConfig.CONTENTSTACK_MANAGEMENT_TOKEN,
2222
host: envConfig.CONTENTSTACK_API_HOST,
23-
ssr: true,
24-
},
25-
stackDetails: {
26-
apiKey: envConfig.CONTENTSTACK_API_KEY,
27-
environment: envConfig.CONTENTSTACK_ENVIRONMENT,
28-
},
29-
clientUrlParams: {
30-
protocol: 'https',
31-
host: envConfig.CONTENTSTACK_APP_HOST,
32-
port: 443,
3323
},
3424
});
3525

3626
if (envConfig.CONTENTSTACK_API_HOST) {
3727
Stack.setHost(envConfig.CONTENTSTACK_API_HOST);
3828
}
39-
ContentstackLivePreview.init(Stack, {
40-
enable: envConfig.CONTENTSTACK_LIVE_PREVIEW,
29+
30+
ContentstackLivePreview.init({
31+
stackSdk: Stack,
32+
clientUrlParams: {
33+
host: envConfig.CONTENTSTACK_APP_HOST,
34+
},
35+
ssr: false,
4136
});
4237

4338
export const { onEntryChange } = ContentstackLivePreview;

0 commit comments

Comments
 (0)