<commit_before>import * as React from 'react'
import userActions from '../actions/userActions'

let Profile = React.createClass({
	componentWillReceiveProps(nextProps) {
		let email = nextProps.user ? nextProps.user.get('email') : null
		let username = nextProps.user ? nextProps.user.get('username') : null
		let name = nextProps.user ? nextProps.user.get('name') : null

		this.setState({email, username, name})
	},
	componentWillMount() {
		this.componentWillReceiveProps(this.props)
	},
	getInitialState: function() {
		return {
			email: '',
			name: '',
			username: '',
			saving: false,
		}
	},
	onNameChange(ev) {
		this.setState({name: ev.target.value})
	},
	onEmailChange(ev) {
		this.setState({email: ev.target.value})
	},
	onUsernameChange(ev) {
		this.setState({username: ev.target.value})
	},
	saveComplete() {
		this.setState({saving: 'saved'})
		console.log('saved user')
	},
	update(ev) {
		ev.preventDefault()
		this.setState({saving: 'saving'})
		this.props.user.set('username', this.state.username)
		this.props.user.set('name', this.state.name)
		this.props.user.set('password', this.refs.password.getDOMNode().value)
		this.props.user.save()
			.then(this.saveComplete)
	},
	render() {
		let title = React.createElement('h1', {className: 'view-title'}, 'User\'s Profile')

		let fields = [
			React.createElement('label', {key: 'name'}, 'Name: ', React.createElement('input',
				{type: 'text', placeholder: '<NAME>', value: this.state.name, onChange: this.onNameChange})),

			React.createElement('label', {key: 'email'}, 'Email: ', React.createElement('input',
				{type: 'email', placeholder: '<EMAIL>', value: this.state.email, onChange: this.onEmailChange})),

			React.createElement('label', {key: 'username'}, 'Username: ', React.createElement('input',
				{type: 'username', placeholder: 'anne', value: this.state.username, onChange: this.onUsernameChange})),

			React.createElement('label', {key: 'password'}, 'Password: ', React.createElement('input',
				{type: 'password', placeholder: ':::::::', defaultValue: '', ref: 'password'})),
		]

		let profile = JSON.stringify(this.props.user, null, 2);

		return React.createElement('div',
			{id: 'profile'},
			title,
			profile,
			React.createElement('form', {className: 'edit-profile', onSubmit: this.update},
				fields,
				React.createElement('input', {type: 'submit', value: 'Save'}),
				React.createElement('button', {onClick: userActions.willSignOut}, 'Sign Out')))
	},
})

export default Profile<commit_msg>Only change the user's password when the field is not blank<commit_after>import * as React from 'react'
import userActions from '../actions/userActions'

let Profile = React.createClass({
	componentWillReceiveProps(nextProps) {
		let email = nextProps.user ? nextProps.user.get('email') : null
		let username = nextProps.user ? nextProps.user.get('username') : null
		let name = nextProps.user ? nextProps.user.get('name') : null

		this.setState({email, username, name})
	},
	componentWillMount() {
		this.componentWillReceiveProps(this.props)
	},
	getInitialState: function() {
		return {
			email: '',
			name: '',
			username: '',
			saving: false,
		}
	},
	onNameChange(ev) {
		this.setState({name: ev.target.value})
	},
	onEmailChange(ev) {
		this.setState({email: ev.target.value})
	},
	onUsernameChange(ev) {
		this.setState({username: ev.target.value})
	},
	saveComplete() {
		this.setState({saving: 'saved'})
		console.log('saved user')
	},
	update(ev) {
		ev.preventDefault()
		this.setState({saving: 'saving'})
		this.props.user.set('username', this.state.username)
		this.props.user.set('name', this.state.name)
		if (this.refs.password.getDOMNode().value)
			this.props.user.set('password', this.refs.password.getDOMNode().value)
		this.props.user.save()
			.then(this.saveComplete)
	},
	render() {
		let title = React.createElement('h1', {className: 'view-title'}, 'User\'s Profile')

		let fields = [
			React.createElement('label', {key: 'name'}, 'Name: ', React.createElement('input',
				{type: 'text', placeholder: '<NAME>', value: this.state.name, onChange: this.onNameChange})),

			React.createElement('label', {key: 'email'}, 'Email: ', React.createElement('input',
				{type: 'email', placeholder: '<EMAIL>', value: this.state.email, onChange: this.onEmailChange})),

			React.createElement('label', {key: 'username'}, 'Username: ', React.createElement('input',
				{type: 'username', placeholder: 'anne', value: this.state.username, onChange: this.onUsernameChange})),

			React.createElement('label', {key: 'password'}, 'Password: ', React.createElement('input',
				{type: 'password', placeholder: '·······', defaultValue: '', ref: 'password'})),
		]

		let buttons = React.createElement('div', {className: 'buttons'},
			React.createElement('input', {type: 'submit', value: 'Save'}),
			React.createElement('button', {onClick: userActions.willSignOut}, 'Sign Out'))

		let profile = JSON.stringify(this.props.user, null, 2);

		return React.createElement('div',
			{id: 'profile'},
			title,
			profile,
			React.createElement('form', {className: 'edit-profile', onSubmit: this.update},
				fields,
				buttons))
	},
})

export default Profile
{'fraction_non_alphanumeric': 0.18596559056640247, 'fraction_numerical': 0.0007732456988208003, 'mean_word_length': 4.872871736662883, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2840038', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1651, 'n_words': 332}