Skip to content
Snippets Groups Projects
Commit 0e83fbe1 authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: optimized log

parent 8d411f77
No related branches found
No related tags found
No related merge requests found
...@@ -117,14 +117,14 @@ export class Log extends PluginComponent<{}, { entries: List<LogEntry> }> { ...@@ -117,14 +117,14 @@ export class Log extends PluginComponent<{}, { entries: List<LogEntry> }> {
private wrapper = React.createRef<HTMLDivElement>(); private wrapper = React.createRef<HTMLDivElement>();
componentDidMount() { componentDidMount() {
this.subscribe(this.plugin.events.log, () => this.setState({ entries: this.plugin.log.entries.takeLast(100).toList() })); this.subscribe(this.plugin.events.log, () => this.setState({ entries: this.plugin.log.entries }));
} }
componentDidUpdate() { componentDidUpdate() {
this.scrollToBottom(); this.scrollToBottom();
} }
state = { entries: this.plugin.log.entries.takeLast(100).toList() }; state = { entries: this.plugin.log.entries };
private scrollToBottom() { private scrollToBottom() {
const log = this.wrapper.current; const log = this.wrapper.current;
...@@ -132,14 +132,21 @@ export class Log extends PluginComponent<{}, { entries: List<LogEntry> }> { ...@@ -132,14 +132,21 @@ export class Log extends PluginComponent<{}, { entries: List<LogEntry> }> {
} }
render() { render() {
// TODO: ability to show full log
// showing more entries dramatically slows animations.
const maxEntries = 10;
const xs = this.state.entries, l = xs.size;
const entries: JSX.Element[] = [];
for (let i = Math.max(0, l - maxEntries), o = 0; i < l; i++) {
const e = xs.get(i);
entries.push(<li key={o++}>
<div className={'msp-log-entry-badge msp-log-entry-' + e!.type} />
<div className='msp-log-timestamp'>{formatTime(e!.timestamp)}</div>
<div className='msp-log-entry'>{e!.message}</div>
</li>);
}
return <div ref={this.wrapper} className='msp-log' style={{ position: 'absolute', top: '0', right: '0', bottom: '0', left: '0', overflowY: 'auto' }}> return <div ref={this.wrapper} className='msp-log' style={{ position: 'absolute', top: '0', right: '0', bottom: '0', left: '0', overflowY: 'auto' }}>
<ul className='msp-list-unstyled'> <ul className='msp-list-unstyled'>{entries}</ul>
{this.state.entries.map((e, i) => <li key={i}>
<div className={'msp-log-entry-badge msp-log-entry-' + e!.type} />
<div className='msp-log-timestamp'>{formatTime(e!.timestamp)}</div>
<div className='msp-log-entry'>{e!.message}</div>
</li>)}
</ul>
</div>; </div>;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment