Skip to content

Commit e94d167

Browse files
authored
Update preview.js to handle draft previews conditionally
1 parent 1848248 commit e94d167

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

js/source/preview.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@ import {ARTICLE_UPDATE_SUBSCRIPTION, PantheonClient, PublishingLevel} from "@pan
22

33
const params = new URLSearchParams(window.location.search);
44
const documentId = drupalSettings.path.currentPath.split('/')[3];
5+
const publishingLevelParam = params.get('publishingLevel');
6+
const explicitVersionId = params.get('versionId');
57

68
const pantheonClient = new PantheonClient({
79
siteId: window.drupalSettings.pantheon_content_publisher.site_id,
810
token: 'pcc_grant ' + params.get('pccGrant')
911
});
1012

13+
pantheonClient.apolloClient.subscribe({
14+
query: ARTICLE_UPDATE_SUBSCRIPTION,
15+
variables: {
16+
id: documentId,
17+
contentType: "TREE_PANTHEON_V2",
18+
publishingLevel: PublishingLevel.REALTIME,
19+
},
20+
})
21+
.subscribe({
22+
next: ({ data }) => {
23+
if (!data) return;
24+
// const entryTitle = document.querySelector('h1');
25+
// entryTitle.innerHTML = article.title;
26+
27+
const previewContentContainer = document.getElementById('pantheon-content-publisher-preview');
28+
previewContentContainer.innerHTML = '';
29+
previewContentContainer.appendChild(generateHTMLFromJSON(JSON.parse(data.article.content)));
30+
},
31+
});
1132

1233
function fetchAndRenderDraftPreview() {
1334
try {
@@ -48,25 +69,10 @@ function fetchAndRenderDraftPreview() {
4869
}
4970
}
5071

51-
pantheonClient.apolloClient.subscribe({
52-
query: ARTICLE_UPDATE_SUBSCRIPTION,
53-
variables: {
54-
id: documentId,
55-
contentType: "TREE_PANTHEON_V2",
56-
publishingLevel: PublishingLevel.REALTIME,
57-
},
58-
})
59-
.subscribe({
60-
next: ({ data }) => {
61-
if (!data) return;
62-
// const entryTitle = document.querySelector('h1');
63-
// entryTitle.innerHTML = article.title;
64-
65-
const previewContentContainer = document.getElementById('pantheon-content-publisher-preview');
66-
previewContentContainer.innerHTML = '';
67-
previewContentContainer.appendChild(generateHTMLFromJSON(JSON.parse(data.article.content)));
68-
},
69-
});
72+
if (publishingLevelParam === 'DRAFT' || VersionId) {
73+
74+
fetchAndRenderDraftPreview();
75+
}
7076

7177
function generateHTMLFromJSON(json, parentElement = null) {
7278
const createElement = (tag, attrs = {}, styles = {}, content = '') => {

0 commit comments

Comments
 (0)