Makes lines a functional component

This commit is contained in:
Franck Royer 2021-04-19 14:57:38 +10:00 committed by Franck Royer
parent 50a2c3777b
commit 7921aa5427
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 25 additions and 22 deletions

View File

@ -3,7 +3,7 @@ import {
Grid,
List,
ListItem,
ListItemText, Paper
ListItemText
} from '@material-ui/core';
import React from 'react';
import MessageInput from './MessageInput';
@ -37,12 +37,12 @@ export default class Room extends React.Component<Props, State> {
<Grid item xs={12}>
<Box height={1080} maxHeight={1080}
style={{ flex: 1, maxHeight: '100%', overflow: 'scroll' }}>
{this.renderLines()}
<Lines messages={this.props.lines} />
</Box>
</Grid>
<Grid item xs={12}>
<Grid container spacing={2} direction="row" alignItems="center">
<Grid container spacing={2} direction='row' alignItems='center'>
<Grid item xs={11}>
<MessageInput messageHandler={this.messageHandler.bind(this)} />
</Grid>
@ -55,23 +55,26 @@ export default class Room extends React.Component<Props, State> {
</Grid>
);
}
// TODO: Make it own component
renderLines() {
const renderedLines = [];
for (const line of this.props.lines) {
renderedLines.push(<ListItem>
<ListItemText
primary={line}
/>
</ListItem>);
}
return (
<List dense={true}>
{renderedLines}
</List>
);
}
}
interface LinesProps {
messages: string[]
}
const Lines = (props: LinesProps) => {
const renderedLines = [];
for (const line of props.messages) {
renderedLines.push(<ListItem>
<ListItemText
primary={line}
/>
</ListItem>);
}
return (
<List dense={true}>
{renderedLines}
</List>
);
};