mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-04-30 14:18:01 +00:00
bb8e804567
* prettier * linter * add prettier, and format the code * remove common, merge it with frontend * refactor the app * better lint and code fix * travis for the frontend app * travis build script Signed-off-by: Daniel Maricic <daniel@woss.io> * lint and build * update the README.md Signed-off-by: Daniel Maricic <daniel@woss.io> * change the commands to reflect refactor Signed-off-by: Daniel Maricic <daniel@woss.io> * prettier and tslint are friends Signed-off-by: Daniel Maricic <daniel@woss.io> * code that wasn't linted properly before Signed-off-by: Daniel Maricic <daniel@woss.io> * prettier rc got deleted * workgin on making the travis pass Signed-off-by: Daniel Maricic <daniel@woss.io> * travis build please? Signed-off-by: Daniel Maricic <daniel@woss.io> * update readme.md Signed-off-by: Daniel Maricic <daniel@woss.io> * dockerfile deleted from fronted - out of scope Signed-off-by: Daniel Maricic <daniel@woss.io> * remove Signed-off-by: Daniel Maricic <daniel@woss.io> * tsconfig Signed-off-by: Daniel Maricic <daniel@woss.io> * found the reason why EOL wasn't happening Signed-off-by: Daniel Maricic <daniel@woss.io> * type for the event in the ConnectionInput as suggested * strictnullCheck to true * noImplicitAny * noUnusedParams * AfgHandling * update * fix Location.tsx * Few minor fixes * remove connection input and revert to original * esnext fixes the imports for icons and non default `* as ` * update to the tsconfig.test.json don't use commonjs please * fixed wrong comment for TIMEOUT_BASE * return totem.svg and type decraration of maybe Signed-off-by: Daniel Maricic <daniel@woss.io> Co-authored-by: Will <w.kopp@kigroup.de>
91 lines
1.7 KiB
TypeScript
91 lines
1.7 KiB
TypeScript
import * as React from 'react';
|
|
import './Tile.css';
|
|
import { timestamp, Types } from '../common';
|
|
|
|
export namespace Ago {
|
|
export interface Props {
|
|
when: Types.Timestamp;
|
|
justTime?: boolean;
|
|
}
|
|
|
|
export interface State {
|
|
now: Types.Timestamp;
|
|
}
|
|
}
|
|
|
|
const tickers = new Map<Ago, (ts: Types.Timestamp) => void>();
|
|
|
|
function tick() {
|
|
const now = timestamp();
|
|
|
|
for (const ticker of tickers.values()) {
|
|
ticker(now);
|
|
}
|
|
|
|
setTimeout(tick, 100);
|
|
}
|
|
|
|
tick();
|
|
|
|
export namespace Ago {
|
|
export interface State {
|
|
now: Types.Timestamp;
|
|
}
|
|
}
|
|
|
|
export class Ago extends React.Component<Ago.Props, Ago.State> {
|
|
public static timeDiff = 0 as Types.Milliseconds;
|
|
|
|
public state: Ago.State;
|
|
|
|
constructor(props: Ago.Props) {
|
|
super(props);
|
|
|
|
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>;
|
|
}
|
|
|
|
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 if (ago < 3600) {
|
|
agoStr = `${(ago / 60) | 0}m`;
|
|
} else if (ago < 3600 * 24) {
|
|
agoStr = `${(ago / 3600) | 0}h`;
|
|
} else {
|
|
agoStr = `${(ago / (3600 * 24)) | 0}d`;
|
|
}
|
|
|
|
if (this.props.justTime !== true) {
|
|
agoStr += ' ago';
|
|
}
|
|
|
|
return (
|
|
<span title={new Date(this.props.when).toUTCString()}>{agoStr}</span>
|
|
);
|
|
}
|
|
}
|