js-waku/web-chat/src/Room.tsx

50 lines
904 B
TypeScript
Raw Normal View History

2021-04-14 15:13:55 +10:00
import React from 'react';
2021-04-19 12:55:33 +10:00
import Input from './Input';
2021-04-19 11:34:13 +10:00
import Send from './Send';
2021-04-14 15:13:55 +10:00
interface Props {
2021-04-19 12:55:33 +10:00
lines: string[],
2021-04-14 15:13:55 +10:00
}
interface State {
2021-04-19 12:55:33 +10:00
messageToSend: string
2021-04-14 15:13:55 +10:00
}
2021-04-19 11:34:13 +10:00
2021-04-16 11:32:00 +10:00
export default class Room extends React.Component<Props, State> {
2021-04-19 12:55:33 +10:00
constructor(props: Props) {
super(props);
this.state = { messageToSend: '' };
}
2021-04-14 15:13:55 +10:00
render() {
return (
2021-04-19 11:34:13 +10:00
<div>
2021-04-19 12:55:33 +10:00
<Input messageHandler={(msg: string) => {
this.setState({ messageToSend: msg });
}
} />
<Send message={this.state.messageToSend} />
2021-04-19 11:34:13 +10:00
<div className='room'>
{this.renderLines(this.props.lines)}
</div>
2021-04-14 15:13:55 +10:00
</div>
);
}
2021-04-14 15:23:00 +10:00
renderLines(lines: string[]) {
2021-04-14 15:13:55 +10:00
2021-04-14 15:23:00 +10:00
const renderedLines = [];
for (const line of lines) {
2021-04-16 11:32:00 +10:00
renderedLines.push(<div className='room-row'>{line}</div>);
2021-04-14 15:13:55 +10:00
}
return (
<div>
2021-04-14 15:23:00 +10:00
{renderedLines}
2021-04-14 15:13:55 +10:00
</div>
);
}
}