<commit_before>import React from 'react'
import {connect} from 'react-redux'
import { withState, withHandlers, compose } from 'recompose'

import Card, { CardHeader, CardContent, CardActions } from 'material-ui/Card'
import IconButton from 'material-ui/IconButton'
import DeleteIcon from 'material-ui-icons/Delete'
import Divider from 'material-ui/Divider'
import TextField from 'material-ui/TextField'
import Balloon from './Balloon'

import { KEY_ENTER } from '../keyCodes.js'
import { chatActionCreator } from '../actions'

export const withCurrentText = withState('curText', 'setCurText', '')

export const withMessageWindowHandlers = withHandlers({
    handleKeyPress: ( { setCurText, curText, currentRoomId, sendMessage, session }) => event => {
        switch  (event.which) {
            case KEY_ENTER:
                sendMessage({
                    userId: session.user.id,
                    roomId: currentRoomId,
                    body: curText,
                })
                setCurText('')
                break
            default:
                break
        }
    },
    handleChange: ( {setCurText} ) => event => {
        setCurText(event.target.value)
    },
})

export const MessageWindow = ( { currentRoomId, session, entities, deleteRoom, handleChange, handleKeyPress, curText, } ) => {

    if(currentRoomId === null){
        return (
            <Card>
                <CardContent>
                    <div>Lets start chatting with your friends!!</div>
                </CardContent>
            </Card>
        );
    }

    const { messages, rooms, users } = entities
    const currentRoom = rooms.byId[currentRoomId]
    const me = session.user

    const roomMessages = !messages.byRoomId.hasOwnProperty(currentRoomId) ? null : messages.byRoomId[currentRoomId].map(messageId => messages.byId[messageId] );
    const messagesDOM = roomMessages ?
        roomMessages.map((message, index) => {
            const direction = ( message.userId === me.id ) ? "right" : "left"
            const username = users.byId.hasOwnProperty(message.userId) ? users.byId[message.userId].username : ""

            return (
                    <Balloon key={index} text={message.text} username={username} direction={direction} createdAt={message.createdAt} />
                        
            )
    }):
    (<span>There is no conversation yet</span>);
    
    return (
        <div>
            <Card>
                <CardHeader title={currentRoom.name} />
                <Divider/>
                <CardContent>
                    {messagesDOM}
                    <TextField
                        id="post-text-field"
                        InputProps={{ placeholder: 'Press enter to send message!' }}
                        fullWidth
                        autoFocus={true}
                        onChange={handleChange}
                        onKeyPress={handleKeyPress}
                        value={curText}
                        margin="normal"
                    />
                </CardContent>
                <CardActions>
                    { currentRoom.createdBy === me.id && ( 
                        <IconButton aria-label="Delete" onClick={()=>{deleteRoom(currentRoomId)}}>
                            <DeleteIcon />
                        </IconButton>)
                    }

                </CardActions>
            </Card>

        </div>
    )
}

const mapStateToProps = ({currentRoomId, session, entities}) => ({
    currentRoomId,
    session,
    entities,
});

const mapDispatchToProps = (dispatch) => ({
    sendMessage: (message) => {
        dispatch(chatActionCreator.sendMessage(message));
    },
    deleteRoom: roomId => {
        dispatch(chatActionCreator.deleteRoom(roomId))
    }, 
});

export const enhancer = compose(
    connect(mapStateToProps, mapDispatchToProps),
    withCurrentText,
    withMessageWindowHandlers,
)
<commit_msg>onMessage conditionalizes on event type<commit_after>import React from 'react'
import { connect } from 'react-redux'
import { withState, withHandlers, compose } from 'recompose'

import Card, { CardHeader, CardContent, CardActions } from 'material-ui/Card'
import IconButton from 'material-ui/IconButton'
import DeleteIcon from 'material-ui-icons/Delete'
import Divider from 'material-ui/Divider'
import TextField from 'material-ui/TextField'
import Balloon from './Balloon'
import { withStyles } from 'material-ui/styles'

import { KEY_ENTER } from '../keyCodes.js'
import { chatActionCreator } from '../actions'

const styleSheet = theme => ({
    cardContent: {
        overflowX: "hidden",
        overflowY: "scroll",
        height: "50vh" // TODO: make this responsive
    },
})

export const withCurrentText = withState('curText', 'setCurText', '')

export const withMessageWindowHandlers = withHandlers({
    handleKeyPress: ( { setCurText, curText, currentRoomId, sendMessage, session }) => event => {
        switch  (event.which) {
            case KEY_ENTER:
                sendMessage({
                    userId: session.user.id,
                    roomId: currentRoomId,
                    body: curText,
                })
                setCurText('')
                break
            default:
                break
        }
    },
    handleChange: ( {setCurText} ) => event => {
        setCurText(event.target.value)
    },
})

export const MessageWindow = ( { currentRoomId, session, entities, deleteRoom, handleChange, handleKeyPress, curText, classes} ) => {

    if(currentRoomId === null){
        return (
            <Card>
                <CardContent>
                    <div>Lets start chatting with your friends!!</div>
                </CardContent>
            </Card>
        );
    }

    const { messages, rooms, users } = entities
    const currentRoom = rooms.byId[currentRoomId]
    const me = session.user

    const roomMessages = !messages.byRoomId.hasOwnProperty(currentRoomId) ? null : messages.byRoomId[currentRoomId].map(messageId => messages.byId[messageId] );
    const messagesDOM = roomMessages ?
        roomMessages.map((message, index) => {
            const direction = ( message.userId === me.id ) ? "right" : "left"
            const username = users.byId.hasOwnProperty(message.userId) ? users.byId[message.userId].username : ""

            return (
                    <Balloon key={index} text={message.text} username={username} direction={direction} createdAt={message.createdAt} />
                        
            )
    }):
    (<span>There is no conversation yet</span>);
    
    return (
        <div>
            <Card>
                <CardHeader title={currentRoom.name} />
                <Divider/>
                <CardContent className={classes.cardContent}>
                    {messagesDOM}
                    <TextField
                        id="post-text-field"
                        InputProps={{ placeholder: 'Press enter to send message!' }}
                        fullWidth
                        autoFocus={true}
                        onChange={handleChange}
                        onKeyPress={handleKeyPress}
                        value={curText}
                        margin="normal"
                    />
                </CardContent>
                <CardActions>
                    { currentRoom.createdBy === me.id && ( 
                        <IconButton aria-label="Delete" onClick={()=>{deleteRoom(currentRoomId)}}>
                            <DeleteIcon />
                        </IconButton>)
                    }

                </CardActions>
            </Card>

        </div>
    )
}

const mapStateToProps = ({currentRoomId, session, entities}) => ({
    currentRoomId,
    session,
    entities,
});

const mapDispatchToProps = (dispatch) => ({
    sendMessage: (message) => {
        dispatch(chatActionCreator.sendMessage(message));
    },
    deleteRoom: roomId => {
        dispatch(chatActionCreator.deleteRoom(roomId))
    }, 
});

export const enhancer = compose(
    withStyles(styleSheet),
    connect(mapStateToProps, mapDispatchToProps),
    withCurrentText,
    withMessageWindowHandlers,
)

{'fraction_non_alphanumeric': 0.11221364694352566, 'fraction_numerical': 0.0002450079627587897, 'mean_word_length': 1.8465829846582984, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5914599', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2071, 'n_words': 447}