Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #157 from facebook/feature/preview-issues
Browse files Browse the repository at this point in the history
Handle issue with preview #141 #146
  • Loading branch information
nataliemt authored Feb 26, 2021
2 parents cddef6f + b353ad6 commit f5ff5bf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"react-dom": "^15.6.1",
"react-joyride": "^1.11.4",
"react-sortable-hoc": "^0.6.8",
"semantic-ui-react": "^0.77.2",
"semantic-ui-react": "^0.80.0",
"yargs-parser": "^18.1.3"
},
"devDependencies": {
Expand Down
40 changes: 23 additions & 17 deletions src/js/components/Preview.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Props = BaseProps & { hidden: boolean };
type State = {
previewLoading: boolean,
sourceLoading: boolean,
activeTab: number
activeTab: number,
};

class Preview extends React.Component<Props, State> {
Expand Down Expand Up @@ -53,25 +53,31 @@ class Preview extends React.Component<Props, State> {

reloadPreview = debounce(() => {
if (this.state.activeTab == 0 && this.preview != null) {
const generatedRules = RuleExporter.export(
this.props.rules,
this.props.settings
);
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),
{
postData: [
{
type: 'rawData',
bytes: Buffer.from(
'rules=' +
encodeURIComponent(
JSON.stringify(
RuleExporter.export(this.props.rules, this.props.settings)
)
)
),
},
],
extraHeaders: 'Content-Type: application/x-www-form-urlencoded',
}
hasRequiredField
? {
postData: [
{
type: 'rawData',
bytes: Buffer.from(
'rules=' +
encodeURIComponent(JSON.stringify(generatedRules))
),
},
],
extraHeaders: 'Content-Type: application/x-www-form-urlencoded',
}
: null
);
}
}, 1000);
Expand Down

0 comments on commit f5ff5bf

Please sign in to comment.