|
1 | 1 | import React from "react";
|
2 | 2 | import {Stage, Text, Sprite} from '@inlet/react-pixi';
|
3 | 3 | import {utils} from 'pixi.js';
|
4 |
| -import {subGoal, stepInfo, allStages, steps, stepSubgoalMap, vfg, textContent} from './dataUtils'; |
| 4 | +import {subGoal, stepInfo, allStages, steps, stepSubgoalMap, vfg, textContent, |
| 5 | + getAllStages, getSteps, getStepInfo, getSubGoal, getStepSubgoalMap} from './dataUtils'; |
5 | 6 | import Button from '@material-ui/core/Button';
|
6 | 7 | import IconButton from '@material-ui/core/IconButton';
|
7 | 8 | import PlayCircleFilledIcon from '@material-ui/icons/PlayCircleFilled';
|
@@ -51,6 +52,7 @@ class PageFour extends React.Component {
|
51 | 52 | // in this class needs to bind like this:
|
52 | 53 | this.handleOnClick = this.handleOnClick.bind(this);
|
53 | 54 | this.updateWindowDimensions = this.updateWindowDimensions.bind(this);
|
| 55 | + this.receiveMessageFromPlugin = this.receiveMessageFromPlugin.bind(this); |
54 | 56 | }
|
55 | 57 |
|
56 | 58 | updateWindowDimensions() {
|
@@ -82,7 +84,38 @@ class PageFour extends React.Component {
|
82 | 84 |
|
83 | 85 | componentDidMount() {
|
84 | 86 | this.updateWindowDimensions();
|
85 |
| - window.addEventListener('resize', this.updateWindowDimensions); |
| 87 | + this.refDom.addEventListener('resize', this.updateWindowDimensions); |
| 88 | + // this.data = { |
| 89 | + // action: 'loadfile' |
| 90 | + // } |
| 91 | + // window.parent && window.parent.postMessage(this.data, '*') |
| 92 | + // window.addEventListener("message", this.receiveMessageFromPlugin, false) |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + receiveMessageFromPlugin ( event ) { |
| 97 | + if(event.origin!= "http://localhost:3000"){ |
| 98 | + console.log( 'iframe is working:', event.origin ); |
| 99 | + let contentObject = {}; |
| 100 | + |
| 101 | + const content = localStorage.getItem('fileContent'); |
| 102 | + if(content) { |
| 103 | + contentObject = JSON.parse(content); |
| 104 | + allStages = getAllStages(); |
| 105 | + steps = getSteps(); |
| 106 | + stepInfo = getStepInfo(); |
| 107 | + subGoal = getSubGoal(); |
| 108 | + stepSubgoalMap = getStepSubgoalMap(); |
| 109 | + vfg = contentObject; |
| 110 | + textContent = content |
| 111 | + |
| 112 | + this.stepItem = {}; |
| 113 | + steps.forEach((step, i) => { |
| 114 | + this.stepItem[i] = React.createRef(); |
| 115 | + }) |
| 116 | + this.setState({drawSprites: allStages[0]}) |
| 117 | + } |
| 118 | + } |
86 | 119 | }
|
87 | 120 |
|
88 | 121 | highlight(index) {
|
@@ -380,6 +413,7 @@ class PageFour extends React.Component {
|
380 | 413 | clearInterval(this.handlerPlay);
|
381 | 414 | }
|
382 | 415 | this.refDom.removeEventListener('resize', this.updateWindowDimensions);
|
| 416 | + // window.removeEventListener("message", this.receiveMessageFromPlugin, false); |
383 | 417 | }
|
384 | 418 |
|
385 | 419 | render() {
|
|
0 commit comments