mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 02:09:41 +00:00
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
import { Box } from './Box';
|
|
import { Component, Fragment } from 'inferno';
|
|
|
|
export class FakeTerminal extends Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.timer = null;
|
|
this.state = {
|
|
currentIndex: 0,
|
|
currentDisplay: [],
|
|
};
|
|
}
|
|
|
|
tick() {
|
|
const { props, state } = this;
|
|
if (state.currentIndex <= props.allMessages.length) {
|
|
this.setState((prevState) => {
|
|
return {
|
|
currentIndex: prevState.currentIndex + 1,
|
|
};
|
|
});
|
|
const { currentDisplay } = state;
|
|
currentDisplay.push(props.allMessages[state.currentIndex]);
|
|
} else {
|
|
clearTimeout(this.timer);
|
|
setTimeout(props.onFinished, props.finishedTimeout);
|
|
}
|
|
}
|
|
|
|
componentDidMount() {
|
|
const { linesPerSecond = 2.5 } = this.props;
|
|
this.timer = setInterval(() => this.tick(), 1000 / linesPerSecond);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
clearTimeout(this.timer);
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<Box m={1}>
|
|
{this.state.currentDisplay.map((value) => (
|
|
<Fragment key={value}>
|
|
{value}
|
|
<br />
|
|
</Fragment>
|
|
))}
|
|
</Box>
|
|
);
|
|
}
|
|
}
|