Skip to content
Snippets Groups Projects
Commit 691b1951 authored by Johannes Mey's avatar Johannes Mey
Browse files

improved js

parent bde06308
Branches
Tags
No related merge requests found
Pipeline #14114 failed
...@@ -12,12 +12,23 @@ class App extends React.Component { ...@@ -12,12 +12,23 @@ class App extends React.Component {
asts: [], asts: [],
contexts: {} contexts: {}
}; };
}
componentDidMount() {
fetch('http://localhost:7070/asts/')
.then(res => res.json())
.then((asts) => {
this.setState({
asts: asts.reverse(),
contexts: {}
})
})
.catch(console.log)
const ws = new WebSocket("ws://localhost:7070/ast-events"); const ws = new WebSocket("ws://localhost:7070/ast-events");
ws.onopen = (event) => { ws.onopen = (event) => {
ws.send("Web client connected!");
ws.send("Hi");
}; };
ws.onmessage = (event) => { ws.onmessage = (event) => {
...@@ -30,57 +41,30 @@ class App extends React.Component { ...@@ -30,57 +41,30 @@ class App extends React.Component {
asts: [event.data, ...asts], asts: [event.data, ...asts],
contexts: contexts contexts: contexts
}); });
console.log(event.data)
} }
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
ws.send("Got Something, thx");
}; };
} }
componentDidMount() {
fetch('http://localhost:7070/asts/')
.then(res => res.json())
.then((asts) => {
this.setState({
asts: asts.reverse(),
contexts: {}
})
})
.catch(console.log)
}
render() { render() {
const astlist = this.state.asts.map(v => {
const image = v.diagram;
return (
<li key={v.timestamp}>
<p>{v.parseRule}</p>
<p><img src={`data:image/svg+xml;utf8,${encodeURIComponent(image)}`} alt='{v.parseRule}' /></p>
</li>
)
})
const astTimeline = this.state.asts.map(v => { const astTimeline = this.state.asts.map(v => {
const image = v.diagram;
const timestamp = new Date(v.timestamp);
return ( return (
<VerticalTimelineElement <VerticalTimelineElement
className="ast-timeline-event" className="ast-timeline-event"
contentStyle={{ background: 'rgb(33, 150, 243)', color: '#fff' }} contentStyle={{ background: 'rgb(33, 150, 243)', color: '#fff' }}
contentArrowStyle={{ borderRight: '7px solid rgb(33, 150, 243)' }} contentArrowStyle={{ borderRight: '7px solid rgb(33, 150, 243)' }}
date={timestamp.toLocaleTimeString('en-us', { hour12: false })} date={new Date(v.timestamp).toLocaleTimeString('en-us', { hour12: false })}
iconStyle={{ background: 'rgb(33, 150, 243)', color: '#fff' }} iconStyle={{ background: 'rgb(33, 150, 243)', color: '#fff', rotate: '180deg' }}
icon={<GiFamilyTree className='ASTIcon' />} icon={<GiFamilyTree />}
key={v.timestamp} key={v.timestamp}
position={'right'} position={'right'}
> >
<h3 className="vertical-timeline-element-title">{v.parseRule}()</h3> <h3 className="vertical-timeline-element-title">{v.parseRule}()</h3>
<p> <p>
<img className="AstInTimeline" src={`data:image/svg+xml;utf8,${encodeURIComponent(image)}`} alt='{v.parseRule}' /> <img className="AstInTimeline" src={`data:image/svg+xml;utf8,${encodeURIComponent(v.diagram)}`} alt={v.parseRule} />
</p> </p>
</VerticalTimelineElement> </VerticalTimelineElement>
...@@ -95,12 +79,10 @@ class App extends React.Component { ...@@ -95,12 +79,10 @@ class App extends React.Component {
<ControlPanel /> <ControlPanel />
</header> </header>
<main> <main>
<div className="curent-state"> <CurrentState
<img className="CurrentAst" src={`data:image/svg+xml;utf8,${encodeURIComponent(lastImage.diagram)}`} alt='lastImage.parseRule' /> diagram={lastImage.diagram}
</div> label={lastImage.parseRule}
{/* <div className="ast-history"> />
<ol>{astlist}</ol>
</div> */}
<VerticalTimeline <VerticalTimeline
className='MG-Timeline'> className='MG-Timeline'>
{astTimeline} {astTimeline}
...@@ -111,19 +93,19 @@ class App extends React.Component { ...@@ -111,19 +93,19 @@ class App extends React.Component {
} }
} }
class ControlPanel extends React.Component { function CurrentState(props) {
constructor(props) { return (
super(props); <div className="curent-state">
}; <img className="CurrentAst" src={`data:image/svg+xml;utf8,${encodeURIComponent(props.diagram)}`} alt={props.label} />
</div>
sayHello = () => { )
alert('You clicked me!');
} }
class ControlPanel extends React.Component {
render() { render() {
return ( return (
<div className='ControlPanel'> <div className='ControlPanel'>
<button onClick={this.sayHello}>connect</button> <button onClick={() => { alert('You clicked me!'); }}>connect</button>
</div> </div>
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment