Map toggle, fix selecting chain

This commit is contained in:
maciejhirsz
2018-07-16 16:39:18 +02:00
parent f6fabfe340
commit efff299113
4 changed files with 44 additions and 10 deletions
+2 -2
View File
@@ -188,7 +188,6 @@ export class Connection {
case Actions.AddedChain: { case Actions.AddedChain: {
const [label, nodeCount] = message.payload; const [label, nodeCount] = message.payload;
chains.set(label, nodeCount); chains.set(label, nodeCount);
this.autoSubscribe();
break; break;
} }
@@ -200,7 +199,6 @@ export class Connection {
nodes.clear(); nodes.clear();
this.state = this.update({ subscribed: null, nodes, chains }); this.state = this.update({ subscribed: null, nodes, chains });
this.autoSubscribe();
continue messages; continue messages;
} }
@@ -230,6 +228,8 @@ export class Connection {
} }
this.state = this.update(changes); this.state = this.update(changes);
this.autoSubscribe();
} }
private autoSubscribe() { private autoSubscribe() {
@@ -8,6 +8,23 @@
position: relative; position: relative;
} }
.Chain-map-toggle {
position: absolute;
right: 20px;
bottom: 0;
font-size: 32px;
padding: 6px;
background: #222;
color: #aaa;
cursor: pointer;
border-top: 2px solid #5e5e5e;
border-radius: 4px 4px 0 0;
}
.Chain-map-toggle-on {
color: #fff;
}
.Chain-content-container { .Chain-content-container {
position: absolute; position: absolute;
left: 0; left: 0;
+19 -3
View File
@@ -13,6 +13,7 @@ import blockHashIcon from '../icons/file-binary.svg';
import blockTimeIcon from '../icons/history.svg'; import blockTimeIcon from '../icons/history.svg';
import propagationTimeIcon from '../icons/dashboard.svg'; import propagationTimeIcon from '../icons/dashboard.svg';
import lastTimeIcon from '../icons/watch.svg'; import lastTimeIcon from '../icons/watch.svg';
import worldIcon from '../icons/globe.svg';
const MAP_RATIO = 495 / 266; // width / height const MAP_RATIO = 495 / 266; // width / height
const HEADER = 148; const HEADER = 148;
@@ -53,7 +54,7 @@ export class Chain extends React.Component<Chain.Props, Chain.State> {
super(props); super(props);
this.state = { this.state = {
display: window.location.hash === '#map' ? 'map' : 'table', display: 'table',
map: { map: {
width: 0, width: 0,
height: 0, height: 0,
@@ -94,6 +95,13 @@ export class Chain extends React.Component<Chain.Props, Chain.State> {
public render() { public render() {
const { best, blockTimestamp, blockAverage } = this.props.appState; const { best, blockTimestamp, blockAverage } = this.props.appState;
const { display } = this.state;
const toggleClass = ['Chain-map-toggle'];
if (display === 'map') {
toggleClass.push('Chain-map-toggle-on');
}
return ( return (
<div className="Chain"> <div className="Chain">
@@ -101,11 +109,12 @@ export class Chain extends React.Component<Chain.Props, Chain.State> {
<Tile icon={blockIcon} title="Best Block">#{formatNumber(best)}</Tile> <Tile icon={blockIcon} title="Best Block">#{formatNumber(best)}</Tile>
<Tile icon={blockTimeIcon} title="Avgerage Time">{ blockAverage == null ? '-' : secondsWithPrecision(blockAverage / 1000) }</Tile> <Tile icon={blockTimeIcon} title="Avgerage Time">{ blockAverage == null ? '-' : secondsWithPrecision(blockAverage / 1000) }</Tile>
<Tile icon={lastTimeIcon} title="Last Block"><Ago when={blockTimestamp} /></Tile> <Tile icon={lastTimeIcon} title="Last Block"><Ago when={blockTimestamp} /></Tile>
<Icon src={worldIcon} alt="Toggle Map" className={toggleClass.join(' ')} onClick={this.toggleMap} />
</div> </div>
<div className="Chain-content-container"> <div className="Chain-content-container">
<div className="Chain-content"> <div className="Chain-content">
{ {
this.state.display === 'table' display === 'table'
? this.renderTable() ? this.renderTable()
: this.renderMap() : this.renderMap()
} }
@@ -115,8 +124,15 @@ export class Chain extends React.Component<Chain.Props, Chain.State> {
); );
} }
private toggleMap = () => {
if (this.state.display === 'map') {
this.setState({ display: 'table' });
} else {
this.setState({ display: 'map' });
}
}
private renderMap() { private renderMap() {
// return <ReactSVG path={worldMap} className="Chain-map" />;
return ( return (
<div className="Chain-map"> <div className="Chain-map">
{ {
+6 -5
View File
@@ -3,9 +3,10 @@ import ReactSVG from 'react-svg';
import './Icon.css'; import './Icon.css';
export interface Props { export interface Props {
src: string, src: string;
alt: string, alt: string;
className?: string, className?: string;
onClick?: () => void;
}; };
export class Icon extends React.Component<{}, Props> { export class Icon extends React.Component<{}, Props> {
@@ -16,8 +17,8 @@ export class Icon extends React.Component<{}, Props> {
} }
public render() { public render() {
const { alt, className, src } = this.props; const { alt, className, onClick, src } = this.props;
return <ReactSVG title={alt} className={`Icon ${ className || '' }`} path={src} />; return <ReactSVG title={alt} className={`Icon ${ className || '' }`} path={src} onClick={onClick} />;
} }
} }