Skip to content

Commit ffe1f6a

Browse files
Merge pull request #30 from visual-heuristics/feat_plugin
Feat plugin
2 parents 83a2611 + bd5a0f9 commit ffe1f6a

File tree

7 files changed

+467
-16
lines changed

7 files changed

+467
-16
lines changed

src/components/navigationBar/navigationBar.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const nav = {
3939
problem: '/problem',
4040
vfg: '/vfg',
4141
manual: 'https://planimation.github.io/documentation/ ',
42-
demo: '/demo',
42+
demo: 'https://www.youtube.com/watch?v=Cj2rWdt1YQU',
4343
home: '/'
4444
};
4545

@@ -51,8 +51,11 @@ function NavigationBar() {
5151
const handleClick = (url) => {
5252
setUrl(url);
5353
if(url==='manual'){
54-
window.location.href(nav[url])
55-
}else{
54+
// window.location.href(nav[url])
55+
}else if(url==='demo'){
56+
// window.location.href(nav[url])
57+
}
58+
else{
5659
history.push(nav[url]);
5760

5861
}
@@ -75,7 +78,7 @@ function NavigationBar() {
7578
<a href={'https://planimation.github.io/documentation/'} target='_blank' rel="noreferrer" className={classes.alink}>User Manual</a>
7679
</Link>
7780
<Link variant="button" color="inherit" onClick={()=>handleClick('demo')} className={classes.link}>
78-
Demo
81+
<a href={'https://www.youtube.com/watch?v=Cj2rWdt1YQU'} target='_blank' rel="noreferrer" className={classes.alink}>Demo</a>
7982
</Link>
8083
</nav>
8184
<Button color="inherit" variant="outlined"onClick={()=>handleClick('home')} className={classes.link} >

src/pages/HomePage/home.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export default function Home() {
150150
window.open('https://planimation.github.io/documentation/')
151151
break;
152152
case 4:
153-
history.push('/demo');
153+
window.open('https://www.youtube.com/watch?v=Cj2rWdt1YQU')
154154
break;
155155
default: return;
156156
}
@@ -199,7 +199,7 @@ export default function Home() {
199199
</div> */}
200200
<ul className={classes.itemTitle}>
201201
{tier.description.map((line) => (
202-
<Typography component="li" variant="subtitle1" align="center" key={line}>
202+
<Typography variant="subtitle1" align="center" key={line}>
203203
{line}
204204
</Typography>
205205
))}

src/pages/PageFour/dataUtils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ if(content) {
55
contentObject = JSON.parse(content);
66
}
77

8-
function getAllStages() {
8+
export function getAllStages() {
99
const visualStages = contentObject.visualStages || [];
1010
const stages = visualStages.map(stage => {
1111
return stage.visualSprites;
1212
})
1313
return stages;
1414
}
1515

16-
function getSteps() {
16+
export function getSteps() {
1717
return contentObject.visualStages ? contentObject.visualStages.map((s =>s.stageName)) : [];
1818
}
1919

20-
function getStepInfo() {
20+
export function getStepInfo() {
2121
return contentObject.visualStages ? contentObject.visualStages.map((s =>s.stageInfo)) : [];
2222
}
2323

2424

25-
function getSubGoal() {
25+
export function getSubGoal() {
2626
if( !contentObject.subgoalMap) {
2727
return {};
2828
}
@@ -46,7 +46,7 @@ function getSubGoal() {
4646
return map;
4747
}
4848

49-
function getStepSubgoalMap() {
49+
export function getStepSubgoalMap() {
5050
if( !contentObject.subgoalMap) {
5151
return {};
5252
}

src/pages/PageFour/index.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from "react";
22
import {Stage, Text, Sprite} from '@inlet/react-pixi';
33
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';
56
import Button from '@material-ui/core/Button';
67
import IconButton from '@material-ui/core/IconButton';
78
import PlayCircleFilledIcon from '@material-ui/icons/PlayCircleFilled';
@@ -51,6 +52,7 @@ class PageFour extends React.Component {
5152
// in this class needs to bind like this:
5253
this.handleOnClick = this.handleOnClick.bind(this);
5354
this.updateWindowDimensions = this.updateWindowDimensions.bind(this);
55+
this.receiveMessageFromPlugin = this.receiveMessageFromPlugin.bind(this);
5456
}
5557

5658
updateWindowDimensions() {
@@ -82,7 +84,38 @@ class PageFour extends React.Component {
8284

8385
componentDidMount() {
8486
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+
}
86119
}
87120

88121
highlight(index) {
@@ -380,6 +413,7 @@ class PageFour extends React.Component {
380413
clearInterval(this.handlerPlay);
381414
}
382415
this.refDom.removeEventListener('resize', this.updateWindowDimensions);
416+
// window.removeEventListener("message", this.receiveMessageFromPlugin, false);
383417
}
384418

385419
render() {

src/pages/PageFour/index.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
.left {
1212
// flex-grow: 1;
13-
max-width: 300px;
13+
width: 300px;
1414
}
1515

1616
.left_upper {
@@ -29,7 +29,7 @@
2929

3030
.right {
3131
// flex-grow: 1;
32-
width: 250px;
32+
width: 220px;
3333
}
3434

3535
.stage_item {

src/pages/PageOne/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class PageOne extends React.Component {
1212
super(props);
1313
this.state = {url:'',fineUrl:'',alertURL:false, alertMessage: ''};
1414
this.handleOnClick = this.handleOnClick.bind(this);
15+
this.handleSendURL = this.handleSendURL.bind(this);
1516
}
1617

1718
handleOnClick() {
@@ -32,7 +33,8 @@ class PageOne extends React.Component {
3233
handleSendURL = () => {
3334
const state = {...this.state};
3435
const url = state.url;
35-
const pattern = new RegExp('^(https?:\\/\\/)?','i');
36+
const pattern = /^((http|https):\/\/)?(([A-Za-z0-9]+-[A-Za-z0-9]+|[A-Za-z0-9]+)\.)+([A-Za-z]+)[/\?\:]?.*$/;
37+
3638
if (!!pattern.test(url)){
3739
state['fineUrl'] = url;
3840
this.setState(state);

0 commit comments

Comments
 (0)