import * as React from "react"; import { GlobalState } from '../../globalState'; import * as ReactDOM from 'react-dom'; require("./log.scss"); interface ILogComponentProps { globalState: GlobalState; } export class LogEntry { constructor(public message: string, public isError: boolean) { } } export class LogComponent extends React.Component { constructor(props: ILogComponentProps) { super(props); this.state = { logs: [] }; } componentWillMount() { this.props.globalState.onLogRequiredObservable.add(log => { let currentLogs = this.state.logs; currentLogs.push(log); this.setState({ logs: currentLogs }); }); } componentDidUpdate() { const logConsole = ReactDOM.findDOMNode(this.refs["log-console"]) as HTMLElement; if (!logConsole) { return; } logConsole.scrollTop = logConsole.scrollHeight; } render() { return (
{ this.state.logs.map((l, i) => { return (
{l.message}
) }) }
); } }