Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow votes from the user frontend #283

Merged
merged 39 commits into from
May 8, 2017
Merged

Conversation

kleingeist
Copy link
Contributor

@kleingeist kleingeist commented May 3, 2017

This PR includes the changes from #273
API changes depend on liqd/adhocracy4#89

It is missing

  • Changes to the api.js in core
  • logic for the AJAX request
    • what to show during the request
    • how to handle/show errors/success
  • Layout for the management form

@2e2a
Copy link
Contributor

2e2a commented May 4, 2017

api and serializer lgtm

vellip and others added 4 commits May 4, 2017 16:43
Copy link
Collaborator

@vellip vellip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a lot of stuff, but most is just small things. I wanted to be thorough since you were eager to learn React. I think there still are a few anti patterns (I spent a few hours figuring out how to reduce the 11 props to QuestionForm) but was only partially convinced of any approach to that.
We can go through the points together too, or through some of them, if you'd like.

Still, nice work for a first shot!

MISSING FORM
{% react_poll_form object %}

</form>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover

@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to name the migrations with -n [name], but I've seen other automagically named migrations, so that's fine too, I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll leave the generated title this time but will name it manually next time.
maybe we could also squash them when the feature is ready


getNewQuestion: function (label) {
var newQuestion = {}
newQuestion['label'] = label
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this

return {
  label: label,
  key: this.getNextQuestionKey(),
  choices: []
}

*/
var questionKey = 'local_' + (this.state.maxQuestionKey + 1)
this.setState({maxQuestionKey: this.state.maxQuestionKey + 1})
return questionKey
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be in state? Should changes to the maxQuestionKey cause a render?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, i changed it to be a class variable. the changes should be reflected in documents, too

var newChoice = {}
newChoice['label'] = label
newChoice['key'] = this.getNextChoiceKey()
return newChoice
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return {
  label: label,
  key: this.getNextChoiceKey()
}

{django.gettext('Question:')}
</label>
<input
className="form-control"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.form-control is of no importance anymore, we removed it. I know, theoretically the same goes for documents.

promise
.done(function (data) {
this.setState({
successMessage: django.gettext('The poll has been updated.')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to reset previous errors here.

}.bind(this))
.fail(function (xhr, status, err) {
this.setState({
errors: xhr.responseJSON.questions || []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a fallback? If there are no errors to set (which errors: [] would mean) you don't want to call setState.

successMessage: ''
})
}.bind(this), 1500)
}.bind(this))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using fat arrow functions to get rid of all the .binds

choice: this.props.question.choices[newChoice].id
}

return api.poll.vote(submitData, this.props.question.id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to return the promise.

@vellip vellip merged commit ef8c037 into master May 8, 2017
@vellip vellip deleted the 2017-05-jd-polls-frontend branch May 8, 2017 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants