Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Fixed an opportunity to publish duplicate posts submitting the Create…
Browse files Browse the repository at this point in the history
…Post form many times
  • Loading branch information
artkravchenko committed Jun 16, 2016
1 parent 8e5d24b commit d5b08dd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/create-post.js
Expand Up @@ -18,6 +18,7 @@
import React, { PropTypes } from 'react';
import ga from 'react-google-analytics';

import Button from './button';
import TagIcon from './tag-icon';
import MoreButton from './more-button';
import { TAG_HASHTAG, TAG_LOCATION, TAG_SCHOOL } from '../consts/tags';
Expand Down Expand Up @@ -64,6 +65,7 @@ export default class CreatePost extends React.Component {
super(props);

this.state = {
isSubmitting: false,
expanded: false,
addTagModalType: null
};
Expand All @@ -88,13 +90,17 @@ export default class CreatePost extends React.Component {

_handleSubmit = async (event) => {
event.preventDefault();
if (this.state.isSubmitting) {
return;
}

const form = this.form;

if (!form.text.value.trim().length) {
return;
}

this.setState({ isSubmitting: true });
const data = {
text: form.text.value,
hashtags: this.props.hashtags.map(hashtag => hashtag.name),
Expand All @@ -111,6 +117,7 @@ export default class CreatePost extends React.Component {

form.text.value = '';
this._addTagModal.reset();
this.setState({ isSubmitting: false });
};

_handleFocus = () => {
Expand Down Expand Up @@ -225,7 +232,12 @@ export default class CreatePost extends React.Component {
{expanded &&
<div className="layout__row layout layout-align_vertical">
<div className="layout__grid_item">
<button className="button button-wide button-red" type="submit">Publish</button>
<Button
className="button button-red"
waiting={this.state.isSubmitting}
title="Publish"
type="submit"
/>
</div>
<div className="layout__grid_item layout__grid_item-wide">
{/*<button className="button button-wide button-transparent" type="button">Go full screen</button>*/}
Expand Down

0 comments on commit d5b08dd

Please sign in to comment.