From 99e0ced07a7cc080e7a2047d2e32b954f126ae96 Mon Sep 17 00:00:00 2001 From: Natalie Takahashi Date: Wed, 24 Feb 2021 18:24:38 -0300 Subject: [PATCH] Handle issue with preview #146 --- src/js/components/Preview.react.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/js/components/Preview.react.js b/src/js/components/Preview.react.js index eca61aa..db00255 100644 --- a/src/js/components/Preview.react.js +++ b/src/js/components/Preview.react.js @@ -58,31 +58,28 @@ class Preview extends React.Component { this.props.rules, this.props.settings ); - if ( + const hasRequiredField = !!( generatedRules && generatedRules.rules.find(rule => rule.class === 'GlobalRule') - ) { - this.preview.loadURL( - 'http://127.0.0.1:8105/preview.php?url=' + - encodeURIComponent(this.props.editor.url), - { + ); + this.preview.loadURL( + 'http://127.0.0.1:8105/preview.php?url=' + + encodeURIComponent(this.props.editor.url), + hasRequiredField + ? { postData: [ { type: 'rawData', bytes: Buffer.from( - 'rules=' + encodeURIComponent(JSON.stringify(generatedRules)) + 'rules=' + + encodeURIComponent(JSON.stringify(generatedRules)) ), }, ], extraHeaders: 'Content-Type: application/x-www-form-urlencoded', } - ); - } else { - this.preview.loadURL( - 'http://127.0.0.1:8105/preview.php?url=' + - encodeURIComponent(this.props.editor.url) - ); - } + : null + ); } }, 1000);