<commit_before>// - Import react components
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { NavLink } from 'react-router-dom'
import { push } from 'react-router-redux'
import SvgClose from 'material-ui/svg-icons/navigation/close'
import { grey400 } from 'material-ui/styles/colors'

// - Import app components
import UserAvatar from 'UserAvatar'

// - Import API

// - Import actions
import * as notifyActions from 'notifyActions'

/**
 * Create component class
 */
export class NotifyItem extends Component {

    static propTypes = {
        /**
         * Notification description
         */
        description: PropTypes.string,
        /**
         * Which user relates to the notification item
         */
        fullName: PropTypes.string,
        /**
         * Avatar of the user who relate to the notification item
         */
        avatar: PropTypes.string,
        /**
         * Notification identifier
         */
        id: PropTypes.string,
        /**
         * If user's seen the notification or not (true/false)
         */
        isSeen: PropTypes.bool,
        /**
         * Which address notification refers
         */
        url: PropTypes.string,
        /**
         * The notifier user identifier
         */
        notifierUserId: PropTypes.string,
        /**
         * Close notification popover
         */
        closeNotify: PropTypes.func
    }

    /**
     * Component constructor
     * @param  {object} props is an object properties of component
     */
    constructor(props) {
        super(props)

        //Defaul state
        this.state = {
        }

        // Binding functions to `this`
        this.handleSeenNotify = this.handleSeenNotify.bind(this)
    }

    handleSeenNotify = (evt) => {
        evt.preventDefault()
        const { seenNotify, id, url, goTo, isSeen, closeNotify } = this.props
        if (id) {
            if (!isSeen)
                seenNotify(id)

            closeNotify()
            goTo(url)
        }
    }

    /**
     * Reneder component DOM
     * @return {react element} return the DOM which rendered by component
     */
    render() {
        let { description, fullName, avatar, isSeen, id, goTo,closeNotify, notifierUserId, url, deleteNotiy } = this.props

        return (

            <div className='item' style={isSeen ? { opacity: 0.6 } : {}} key={id}>
                <div className='avatar'>
                    <NavLink
                        to={`/${notifierUserId}`}
                        onClick={(evt) => {
                            evt.preventDefault()
                            closeNotify()
                            goTo(`/${notifierUserId}`)
                        }}
                    >
                        <UserAvatar fullName={fullName} fileName={avatar} />
                    </NavLink>
                </div>
                <div className='info'>
                    <NavLink to={url} onClick={this.handleSeenNotify}>
                        <div className='user-name'>
                            {fullName}
                        </div>
                        <div className='description'>
                            {description}
                        </div>
                    </NavLink>
                </div>
                <div className='close' onClick={() => deleteNotiy(id)}>
                    <SvgClose hoverColor={grey400} style={{ cursor: 'pointer' }} />
                </div>
            </div>

        )
    }
}



/**
 * Map dispatch to props
 * @param  {func} dispatch is the function to dispatch action to reducers
 * @param  {object} ownProps is the props belong to component
 * @return {object}          props of component
 */
const mapDispatchToProps = (dispatch, ownProps) => {
    return {
        goTo: (url) => dispatch(push(url)),
        seenNotify: (id) => dispatch(notifyActions.dbSeenNotify(id)),
        deleteNotiy: (id) => dispatch(notifyActions.dbDeleteNotify(id))
    }
}

/**
 * Map state to props
 * @param  {object} state is the obeject from redux store
 * @param  {object} ownProps is the props belong to component
 * @return {object}          props of component
 */
const mapStateToProps = (state, ownProps) => {
    return {

    }
}

// - Connect component to redux store
export default connect(mapStateToProps, mapDispatchToProps)(NotifyItem)<commit_msg>Solved Can not close notifications from popup #29<commit_after>// - Import react components
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { NavLink } from 'react-router-dom'
import { push } from 'react-router-redux'
import SvgClose from 'material-ui/svg-icons/navigation/close'
import { grey400 } from 'material-ui/styles/colors'

// - Import app components
import UserAvatar from 'UserAvatar'

// - Import API

// - Import actions
import * as notifyActions from 'notifyActions'

/**
 * Create component class
 */
export class NotifyItem extends Component {

    static propTypes = {
        /**
         * Notification description
         */
        description: PropTypes.string,
        /**
         * Which user relates to the notification item
         */
        fullName: PropTypes.string,
        /**
         * Avatar of the user who relate to the notification item
         */
        avatar: PropTypes.string,
        /**
         * Notification identifier
         */
        id: PropTypes.string,
        /**
         * If user's seen the notification or not (true/false)
         */
        isSeen: PropTypes.bool,
        /**
         * Which address notification refers
         */
        url: PropTypes.string,
        /**
         * The notifier user identifier
         */
        notifierUserId: PropTypes.string,
        /**
         * Close notification popover
         */
        closeNotify: PropTypes.func
    }

    /**
     * Component constructor
     * @param  {object} props is an object properties of component
     */
    constructor(props) {
        super(props)

        //Defaul state
        this.state = {
        }

        // Binding functions to `this`
        this.handleSeenNotify = this.handleSeenNotify.bind(this)
    }

    handleSeenNotify = (evt) => {
        evt.preventDefault()
        const { seenNotify, id, url, goTo, isSeen, closeNotify } = this.props
        if (id) {
            if (!isSeen)
                seenNotify(id)

            closeNotify()
            goTo(url)
        }
    }

    /**
     * Reneder component DOM
     * @return {react element} return the DOM which rendered by component
     */
    render() {
        let { description, fullName, avatar, isSeen, id, goTo,closeNotify, notifierUserId, url, deleteNotiy } = this.props

        return (

            <div className='item' style={isSeen ? { opacity: 0.6 } : {}} key={id}>
                <div className='avatar'>
                    <NavLink
                        to={`/${notifierUserId}`}
                        onClick={(evt) => {
                            evt.preventDefault()
                            closeNotify()
                            goTo(`/${notifierUserId}`)
                        }}
                    >
                        <UserAvatar fullName={fullName} fileName={avatar} />
                    </NavLink>
                </div>
                <div className='info'>
                    <NavLink to={url} onClick={this.handleSeenNotify}>
                        <div className='user-name'>
                            {fullName}
                        </div>
                        <div className='description'>
                            {description}
                        </div>
                    </NavLink>
                </div>
                <div className='close' onClick={() => deleteNotiy(id)}>
                    <SvgClose hoverColor={grey400} style={{ cursor: 'pointer' }} />
                </div>
            </div>

        )
    }
}



/**
 * Map dispatch to props
 * @param  {func} dispatch is the function to dispatch action to reducers
 * @param  {object} ownProps is the props belong to component
 * @return {object}          props of component
 */
const mapDispatchToProps = (dispatch, ownProps) => {
    return {
        goTo: (url) => dispatch(push(url)),
        seenNotify: (id) => dispatch(notifyActions.dbSeenNotification(id)),
        deleteNotiy: (id) => dispatch(notifyActions.dbDeleteNotification(id))
    }
}

/**
 * Map state to props
 * @param  {object} state is the obeject from redux store
 * @param  {object} ownProps is the props belong to component
 * @return {object}          props of component
 */
const mapStateToProps = (state, ownProps) => {
    return {

    }
}

// - Connect component to redux store
export default connect(mapStateToProps, mapDispatchToProps)(NotifyItem)
{'fraction_non_alphanumeric': 0.10800179815688919, 'fraction_numerical': 0.0020229265003371545, 'mean_word_length': 1.6266233766233766, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 55, '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': '6248001', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2294, 'n_words': 626}