mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-03-25 09:25:47 +00:00
show a spinner while publishing/unpublishing
This commit is contained in:
parent
67714c714d
commit
2cb9adf357
1 changed files with 27 additions and 5 deletions
|
|
@ -16,6 +16,8 @@
|
||||||
#import "UIImage+FontAwesome.h"
|
#import "UIImage+FontAwesome.h"
|
||||||
#import "NSString+FontAwesome.h"
|
#import "NSString+FontAwesome.h"
|
||||||
#import "UIColor+Hex.h"
|
#import "UIColor+Hex.h"
|
||||||
|
#import "MBProgressHUD.h"
|
||||||
|
#import "UIFont+FontAwesome.h"
|
||||||
|
|
||||||
@interface EditorViewController () <UITextViewDelegate, UIPopoverPresentationControllerDelegate>
|
@interface EditorViewController () <UITextViewDelegate, UIPopoverPresentationControllerDelegate>
|
||||||
|
|
||||||
|
|
@ -329,26 +331,46 @@ static NSString *const StateRestorationModifiedPostKey = @"modifiedPost";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)publishOrUnpublish:(id)sender {
|
- (IBAction)publishOrUnpublish:(id)sender {
|
||||||
// TODO: prevent changes while publishing
|
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
||||||
|
BOOL isPublish = self.modifiedPost.draft;
|
||||||
|
hud.labelText = isPublish ? @"Publishing" : @"Unpublishing";
|
||||||
__weak typeof(self) welf = self;
|
__weak typeof(self) welf = self;
|
||||||
[self savePostAndWaitForCompilation:NO].then(^{
|
[self savePostAndWaitForCompilation:NO].then(^{
|
||||||
typeof(self) self = welf;
|
typeof(self) self = welf;
|
||||||
PMKPromise *promise = nil;
|
PMKPromise *promise = nil;
|
||||||
Post *post = self.modifiedPost;
|
if (isPublish) {
|
||||||
if (post.draft) {
|
promise = [self.blogController requestPublishDraft:self.modifiedPost];
|
||||||
promise = [self.blogController requestPublishDraft:post];
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
promise = [self.blogController requestUnpublishPost:post];
|
promise = [self.blogController requestUnpublishPost:self.modifiedPost];
|
||||||
}
|
}
|
||||||
promise.then(^(Post *post) {
|
promise.then(^(Post *post) {
|
||||||
|
hud.mode = MBProgressHUDModeCustomView;
|
||||||
|
hud.customView = [self HUDLabelWithText:[NSString fontAwesomeIconStringForEnum:FACheck]];
|
||||||
|
hud.labelText = isPublish ? @"Published" : @"Unpublished";
|
||||||
self.post = post;
|
self.post = post;
|
||||||
self.modifiedPost = post;
|
self.modifiedPost = post;
|
||||||
[self configureView];
|
[self configureView];
|
||||||
|
[hud hide:YES afterDelay:1];
|
||||||
|
}).catch(^(NSError *error) {
|
||||||
|
hud.mode = MBProgressHUDModeCustomView;
|
||||||
|
hud.customView = [self HUDLabelWithText:[NSString fontAwesomeIconStringForEnum:FATimes]];
|
||||||
|
hud.labelText = @"Fail";
|
||||||
|
hud.detailsLabelText = error.localizedDescription;
|
||||||
|
[hud hide:YES afterDelay:3];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (UILabel *)HUDLabelWithText:(NSString *)text {
|
||||||
|
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||||
|
label.textColor = [UIColor whiteColor];
|
||||||
|
label.font = [UIFont fontAwesomeFontOfSize:36];
|
||||||
|
label.text = text;
|
||||||
|
[label sizeToFit];
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
- (IBAction)save:(id)sender {
|
- (IBAction)save:(id)sender {
|
||||||
[self savePostAndWaitForCompilation:NO];
|
[self savePostAndWaitForCompilation:NO];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue