<commit_before>var React = require('react/addons');
var request = require('superagent');
var RSVPStore = require('../stores/RSVPStore');

var HeroApp = React.createClass({

	getInitialState: function() {
		return {
			user: SydJS.user,
			isReady: RSVPStore.isLoaded(),
			meetup: RSVPStore.getMeetup(),
			rsvp: RSVPStore.getRSVP()
		};
	},

	componentDidMount: function() {
		RSVPStore.addChangeListener(this.updateStateFromStore);
	},

	componentWillUnmount: function() {
		RSVPStore.removeChangeListener(this.updateStoreFromState);
	},

	updateStateFromStore: function() {
		this.setState({
			isReady: RSVPStore.isLoaded(),
			meetup: RSVPStore.getMeetup(),
			rsvp: RSVPStore.getRSVP()
		});
	},

	sendRSVP: function(attending) {
		var self = this;
		RSVPStore.rsvp({
			meetup: this.state.meetup._id,
			attending: attending
		}, function(data) {
			self.setState(data);
		});
	},

	renderWelcome: function() {
		if (this.state.rsvp.attending) {
			return <h4 className="hero-button-title"><span className = "welcome-message">See you there!</span></h4>
		} else {
			return <h4 className="hero-button-title">Are you coming? <br /> <span className="spots-left">{this.state.meetup.remainingRSVPs}<span className="text-thin"> spots left</span></span><br /></h4>
		}
	},

	renderLoading: function() {
		return (
			<div className="hero-button">
				<div className="alert alert-success mb-0 text-center">loading...</div>
			</div>
		);
	},

	renderSignedIn: function() {
		var attending = this.state.rsvp.attending ?  ' btn-success btn-default active' : null;
		var notAttending = this.state.rsvp.attending ? null : ' btn-danger btn-default active';
		if(this.state.meetup.rsvpsAvailable || this.state.rsvp.rsvped && this.state.rsvp.attending) {
			return (
				<div>
					{this.renderWelcome()}
					<div className="hero-button">
						<div id="next-meetup" data-id={this.state.meetup._id} className="form-row meetup-toggle">
							<div className="col-xs-6">
								<button type="button" onClick={this.sendRSVP.bind(this, true)} className={"btn btn-lg btn-block btn-default js-rsvp-attending" + attending}>Yes</button>
							</div>
							<div className="col-xs-6">
								<button type="button" onClick={this.sendRSVP.bind(this, false)} className={"btn btn-lg btn-block btn-default js-rsvp-decline" + notAttending}>No</button>
							</div>
						</div>
					</div>
				</div>
			);
		} else {
			return (
				<div className="hero-button">
					<div className="alert alert-success mb-0 text-center">No more tickets...</div>
				</div>
			);
		}
	},

	renderSignedOut: function() {
		if (this.state.meetup.rsvpsAvailable) {
			return (
				<div className="hero-button">
					<a className="btn btn-primary btn-lg btn-block js-auth-trigger">RSVP Now (<span class="text-thin">{this.state.meetup.remainingRSVPs} spots left</span>)</a>
				</div>
			)
		} else {
			return (
				<div className="hero-button">
					<div className="alert alert-success mb-0 text-center">No more tickets...</div>
				</div>
			);
		}
	},

	render: function() {
		if (!this.state.isReady) {
			return this.renderLoading();
		}
		return this.state.user ? this.renderSignedIn() : this.renderSignedOut();
	},
});

module.exports = HeroApp;<commit_msg>Getting the RSVP Button responding correctly to the current state<commit_after>var React = require('react/addons');
var request = require('superagent');
var RSVPStore = require('../stores/RSVPStore');

var HeroApp = React.createClass({

	getInitialState: function() {
		return {
			user: SydJS.user,
			isReady: RSVPStore.isLoaded(),
			meetup: RSVPStore.getMeetup(),
			rsvp: RSVPStore.getRSVP()
		};
	},

	componentDidMount: function() {
		RSVPStore.addChangeListener(this.updateStateFromStore);
	},

	componentWillUnmount: function() {
		RSVPStore.removeChangeListener(this.updateStoreFromState);
	},

	updateStateFromStore: function() {
		this.setState({
			isReady: RSVPStore.isLoaded(),
			meetup: RSVPStore.getMeetup(),
			rsvp: RSVPStore.getRSVP()
		});
	},

	sendRSVP: function(attending) {
		var self = this;
		RSVPStore.rsvp({
			meetup: this.state.meetup._id,
			attending: attending
		}, function(data) {
			self.setState(data);
		});
	},

	renderWelcome: function() {
		if (this.state.rsvp.attending) {
			return <h4 className="hero-button-title"><span className = "welcome-message">See you there!</span></h4>
		} else {
			return <h4 className="hero-button-title">Are you coming? <br /> <span className="spots-left">{this.state.meetup.remainingRSVPs}<span className="text-thin"> spots left</span></span><br /></h4>
		}
	},

	renderLoading: function() {
		return (
			<div className="hero-button">
				<div className="alert alert-success mb-0 text-center">loading...</div>
			</div>
		);
	},

	renderRSVPButton: function() {
		return (
			<div className="hero-button">
				<a className="btn btn-primary btn-lg btn-block">
					RSVP Now (<span className="text-thin">{this.state.meetup.remainingRSVPs} spots left</span>)
				</a>
			</div>
		);
	},

	renderRSVPToggle: function() {
		var attending = this.state.rsvp.attending ?  ' btn-success btn-default active' : null;
		var notAttending = this.state.rsvp.attending ? null : ' btn-danger btn-default active';
		return (
			<div>
				{this.renderWelcome()}
				<div className="hero-button">
					<div id="next-meetup" data-id={this.state.meetup._id} className="form-row meetup-toggle">
						<div className="col-xs-6">
							<button type="button" onClick={this.sendRSVP.bind(this, true)} className={"btn btn-lg btn-block btn-default js-rsvp-attending" + attending}>Yes</button>
						</div>
						<div className="col-xs-6">
							<button type="button" onClick={this.sendRSVP.bind(this, false)} className={"btn btn-lg btn-block btn-default js-rsvp-decline" + notAttending}>No</button>
						</div>
					</div>
				</div>
			</div>
		);
	},

	renderRSVPSignin: function() {
		return (
			<div className="hero-button">
				<a className="btn btn-primary btn-lg btn-block js-auth-trigger">RSVP Now <span class="text-thin">({this.state.meetup.remainingRSVPs} spots left)</span></a>
			</div>
		);
	},

	renderNoMoreTickets: function() {
		return (
			<div className="hero-button">
				<div className="alert alert-success mb-0 text-center">No more tickets...</div>
			</div>
		);
	},

	render: function() {
		if (!this.state.isReady) {
			return this.renderLoading();
		}
		if (this.state.user) {
			if (this.state.meetup.rsvpsAvailable) {
				if (this.state.rsvp.exists) {
					return this.renderRSVPToggle();
				} else {
					return this.renderRSVPButton();
				}
			} else {
				return this.renderNoMoreTickets();
			}
		} else {
			return this.state.meetup.rsvpsAvailable ? this.renderRSVPSignin() : this.renderNoMoreTickets();
		}
	},
});

module.exports = HeroApp;
{'fraction_non_alphanumeric': 0.16678999556015983, 'fraction_numerical': 0.0025159094272606186, 'mean_word_length': 3.7061281337047354, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 93, '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': '2946633', 'n_tokens_mistral': 2722, 'n_tokens_neox': 2306, 'n_words': 421}