Skip to content

Commit

Permalink
Fix inserting new surveys on home and profile screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
brung committed Feb 26, 2015
1 parent e722b3a commit f3111fa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions unnamed/AnswerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ - (id)initWithCoder:(NSCoder *)aDecoder {

- (void)setAnswer:(Answer *)answer {
_answer = answer;
if (!answer.text) {
return;
}
self.answerLabel.text = [NSString stringWithFormat:@"%ld. %@", self.index, answer.text];
CGFloat percentage = self.total <= 0 ? 0.0 : 1.0f * answer.count / self.total;
self.percentLabel.text = [NSString stringWithFormat:@"%.1f%%", percentage * 100.0];
Expand Down
18 changes: 12 additions & 6 deletions unnamed/ComposeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ - (void)onSubmitButton {
for (Answer *answer in self.answers) {
if ((self.isShowingTextAnswers && [answer.text length] >= 1) ||
(!self.isShowingTextAnswers && answer.photo)) {
[validAnswers addObject:answer];
[validAnswers addObject:answer];
}
}
if ([self.questionText.text length] >= 8 && validAnswers.count >= 2) {
Expand All @@ -215,10 +215,13 @@ - (void)onSubmitButton {
survey.question.isTextSurvey = self.isShowingTextAnswers;

if (self.isShowingTextAnswers) {
survey.question.isTextSurvey = YES;
survey.question.createdAt = [NSDate date] ;
[ParseClient saveTextSurvey:survey withCompletion:^(BOOL succeeded, NSError *error) {
[self onPostSurvey:survey completionStatus:succeeded error:error];
}];
} else {
survey.question.isTextSurvey = NO;
[ParseClient savePhotoSurvey:survey withCompletion:^(BOOL succeeded, NSError *error) {
[self onPostSurvey:survey completionStatus:succeeded error:error];
}];
Expand All @@ -242,17 +245,18 @@ - (void)onPostSurvey:(Survey *)survey completionStatus:(BOOL) succeeded error:(N
- (void)onSuccessfulPostSurvey:(Survey *)survey {
NSDictionary *dict = [NSDictionary dictionaryWithObject:survey forKey:@"survey"];
[[NSNotificationCenter defaultCenter] postNotificationName:UserDidPostNewSurveyNotification object:nil userInfo:dict];
[self onCancelButton];
[self resetForm];
}

- (void)onErrorPost {
[[[UIAlertView alloc] initWithTitle:@"Save Failed" message:@"Unable to save at this time. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}

- (void)onCancelButton {
[self resetForm];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
//- (void)onCancelButton {
// [self resetForm];
// [self dismissViewControllerAnimated:YES completion:nil];
//// [self.navigationController dismissViewControllerAnimated:YES completion:nil];
//}

- (void)resetForm {
self.answers = [NSMutableArray arrayWithObject:[[Answer alloc] init]];
Expand All @@ -268,6 +272,8 @@ - (void)resetForm {
self.questionText.text = @"";
self.questionTextCountLabel.text = [NSString stringWithFormat:@"%ld", maxCount];
self.questionText.alpha = 1;
[self.navigationController popViewControllerAnimated:YES];
// [self dismissViewControllerAnimated:YES completion:nil];
}];

}
Expand Down
2 changes: 0 additions & 2 deletions unnamed/ParseClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ + (void)saveTextSurvey:(Survey *)survey withCompletion:(void(^)(BOOL succeeded,
survey.question.anonymous = NO;
survey.question.complete = NO;
survey.question.numAnswers = validAnswers.count;
survey.answers = validAnswers;
NSMutableArray *counts = [NSMutableArray array];
for (int i = 0; i < validAnswers.count; i++) {
[counts addObject:@(0)];
Expand Down Expand Up @@ -153,7 +152,6 @@ + (void)savePhotoSurvey:(Survey *)survey withCompletion:(void(^)(BOOL succeeded,
survey.question.anonymous = NO;
survey.question.complete = NO;
survey.question.numAnswers = validAnswers.count;
survey.answers = validAnswers;
NSMutableArray *counts = [NSMutableArray array];
for (int i = 0; i < validAnswers.count; i++) {
[counts addObject:@(0)];
Expand Down
2 changes: 1 addition & 1 deletion unnamed/Question.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@property (nonatomic, strong) NSArray *answerVoteCounts;
@property (nonatomic, assign) BOOL anonymous;
@property (nonatomic, assign) BOOL complete;
@property (nonatomic, readonly) NSDate *createdAt;
@property (nonatomic, assign) NSDate *createdAt;
@property (nonatomic, assign) BOOL isTextSurvey;
@property (nonatomic, strong) QuestionPhotos *questionPhotos;

Expand Down

0 comments on commit f3111fa

Please sign in to comment.