Reformatting

This commit is contained in:
maciejhirsz
2018-07-06 17:53:42 +02:00
parent 6fe1e47082
commit 538a30ccc3
20 changed files with 1005 additions and 1001 deletions
+50 -50
View File
@@ -3,77 +3,77 @@ import './Tile.css';
import { timestamp, Types } from '@dotstats/common';
export namespace Ago {
export interface Props {
when: Types.Timestamp,
}
export interface Props {
when: Types.Timestamp,
}
export interface State {
now: Types.Timestamp,
}
export interface State {
now: Types.Timestamp,
}
}
const tickers = new Map<Ago, (ts: Types.Timestamp) => void>();
function tick() {
const now = timestamp();
const now = timestamp();
for (const ticker of tickers.values()) {
ticker(now);
}
for (const ticker of tickers.values()) {
ticker(now);
}
setTimeout(tick, 100);
setTimeout(tick, 100);
}
tick();
export namespace Ago {
export interface State {
now: Types.Timestamp
}
export interface State {
now: Types.Timestamp
}
}
export class Ago extends React.Component<Ago.Props, Ago.State> {
public static timeDiff = 0 as Types.Milliseconds;
public static timeDiff = 0 as Types.Milliseconds;
public state: Ago.State;
public state: Ago.State;
constructor(props: Ago.Props) {
super(props);
constructor(props: Ago.Props) {
super(props);
this.state = {
now: (timestamp() + Ago.timeDiff) as Types.Timestamp
};
this.state = {
now: (timestamp() + Ago.timeDiff) as Types.Timestamp
};
}
public componentWillMount() {
tickers.set(this, (now) => {
this.setState({
now: (now + Ago.timeDiff) as Types.Timestamp
});
})
}
public componentWillUnmount() {
tickers.delete(this);
}
public render() {
if (this.props.when === 0) {
return <span>-</span>;
}
public componentWillMount() {
tickers.set(this, (now) => {
this.setState({
now: (now + Ago.timeDiff) as Types.Timestamp
});
})
const ago = Math.max(this.state.now - this.props.when, 0) / 1000;
let agoStr: string;
if (ago < 10) {
agoStr = `${ago.toFixed(1)}s`;
} else if (ago < 60) {
agoStr = `${ago | 0}s`;
} else {
agoStr = `${ ago / 60 | 0}m`;
}
public componentWillUnmount() {
tickers.delete(this);
}
public render() {
if (this.props.when === 0) {
return <span>-</span>;
}
const ago = Math.max(this.state.now - this.props.when, 0) / 1000;
let agoStr: string;
if (ago < 10) {
agoStr = `${ago.toFixed(1)}s`;
} else if (ago < 60) {
agoStr = `${ago | 0}s`;
} else {
agoStr = `${ ago / 60 | 0}m`;
}
return <span title={new Date(this.props.when).toUTCString()}>{agoStr} ago</span>
}
return <span title={new Date(this.props.when).toUTCString()}>{agoStr} ago</span>
}
}
+32 -32
View File
@@ -7,44 +7,44 @@ import chainIcon from '../icons/link.svg';
import './Chains.css';
export namespace Chains {
export interface Props {
chains: Set<Types.ChainLabel>,
subscribed: Maybe<Types.ChainLabel>,
connection: Promise<Connection>
}
export interface Props {
chains: Set<Types.ChainLabel>,
subscribed: Maybe<Types.ChainLabel>,
connection: Promise<Connection>
}
}
export class Chains extends React.Component<Chains.Props, {}> {
public render() {
return (
<div className="Chains">
<Icon src={chainIcon} alt="Observed chain" />
{
this.chains.map((chain) => this.renderChain(chain))
}
</div>
);
}
public render() {
return (
<div className="Chains">
<Icon src={chainIcon} alt="Observed chain" />
{
this.chains.map((chain) => this.renderChain(chain))
}
</div>
);
}
private renderChain(chain: Types.ChainLabel): React.ReactNode {
const className = chain === this.props.subscribed
? 'Chains-chain Chains-chain-selected'
: 'Chains-chain';
private renderChain(chain: Types.ChainLabel): React.ReactNode {
const className = chain === this.props.subscribed
? 'Chains-chain Chains-chain-selected'
: 'Chains-chain';
return (
<a key={chain} className={className} onClick={this.subscribe.bind(this, chain)}>
{chain}
</a>
)
}
return (
<a key={chain} className={className} onClick={this.subscribe.bind(this, chain)}>
{chain}
</a>
)
}
private get chains(): Types.ChainLabel[] {
return Array.from(this.props.chains);
}
private get chains(): Types.ChainLabel[] {
return Array.from(this.props.chains);
}
private async subscribe(chain: Types.ChainLabel) {
const connection = await this.props.connection;
private async subscribe(chain: Types.ChainLabel) {
const connection = await this.props.connection;
connection.subscribe(chain);
}
connection.subscribe(chain);
}
}
+11 -11
View File
@@ -3,21 +3,21 @@ import ReactSVG from 'react-svg';
import './Icon.css';
export interface Props {
src: string,
alt: string,
className?: string,
src: string,
alt: string,
className?: string,
};
export class Icon extends React.Component<{}, Props> {
public props: Props;
public props: Props;
public shouldComponentUpdate() {
return false;
}
public shouldComponentUpdate() {
return false;
}
public render() {
const { alt, className, src } = this.props;
public render() {
const { alt, className, src } = this.props;
return <ReactSVG title={alt} className={`Icon ${ className || '' }`} path={src} />;
}
return <ReactSVG title={alt} className={`Icon ${ className || '' }`} path={src} />;
}
}
+21 -21
View File
@@ -4,29 +4,29 @@ import { Ago } from './Ago';
import { Types } from '@dotstats/common';
export namespace Node {
export interface Props {
id: Types.NodeId,
nodeDetails: Types.NodeDetails,
nodeStats: Types.NodeStats,
blockDetails: Types.BlockDetails,
}
export interface Props {
id: Types.NodeId,
nodeDetails: Types.NodeDetails,
nodeStats: Types.NodeStats,
blockDetails: Types.BlockDetails,
}
}
export function Node(props: Node.Props) {
const [name, implementation, version] = props.nodeDetails;
const [height, hash, blockTime, blockTimestamp] = props.blockDetails;
const [peers, txcount] = props.nodeStats;
const [name, implementation, version] = props.nodeDetails;
const [height, hash, blockTime, blockTimestamp] = props.blockDetails;
const [peers, txcount] = props.nodeStats;
return (
<tr>
<td>{name}</td>
<td>{implementation} v{version}</td>
<td>{peers}</td>
<td>{txcount}</td>
<td>#{formatNumber(height)}</td>
<td><span title={hash}>{trimHash(hash, 16)}</span></td>
<td>{(blockTime / 1000).toFixed(3)}s</td>
<td><Ago when={blockTimestamp} /></td>
</tr>
);
return (
<tr>
<td>{name}</td>
<td>{implementation} v{version}</td>
<td>{peers}</td>
<td>{txcount}</td>
<td>#{formatNumber(height)}</td>
<td><span title={hash}>{trimHash(hash, 16)}</span></td>
<td>{(blockTime / 1000).toFixed(3)}s</td>
<td><Ago when={blockTimestamp} /></td>
</tr>
);
}
+12 -12
View File
@@ -3,19 +3,19 @@ import './Tile.css';
import { Icon } from './Icon';
export namespace Tile {
export interface Props {
title: string,
icon: string,
children?: React.ReactNode,
}
export interface Props {
title: string,
icon: string,
children?: React.ReactNode,
}
}
export function Tile(props: Tile.Props) {
return (
<div className="Tile">
<Icon src={props.icon} alt={props.title} />
<span className="Tile-label">{props.title}</span>
<span className="Tile-content">{props.children}</span>
</div>
);
return (
<div className="Tile">
<Icon src={props.icon} alt={props.title} />
<span className="Tile-label">{props.title}</span>
<span className="Tile-content">{props.children}</span>
</div>
);
}