@@ -2,12 +2,33 @@ import {ARTICLE_UPDATE_SUBSCRIPTION, PantheonClient, PublishingLevel} from "@pan
22
33const params = new URLSearchParams ( window . location . search ) ;
44const documentId = drupalSettings . path . currentPath . split ( '/' ) [ 3 ] ;
5+ const publishingLevelParam = params . get ( 'publishingLevel' ) ;
6+ const explicitVersionId = params . get ( 'versionId' ) ;
57
68const 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
1233function 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
7177function generateHTMLFromJSON ( json , parentElement = null ) {
7278 const createElement = ( tag , attrs = { } , styles = { } , content = '' ) => {
0 commit comments