mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-04-23 14:15:53 +00:00
show a spinner while publishing the site
This commit is contained in:
parent
abe7a1b1c6
commit
91441fdaa8
6 changed files with 51 additions and 32 deletions
|
|
@ -12,6 +12,7 @@
|
|||
1BCFC349E4959199EB3872DA /* MuseoSans-300-Italic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 1BCFCD0E9504E1E8AB8C0275 /* MuseoSans-300-Italic.otf */; };
|
||||
1BCFC56B50FFDC7782B79B7C /* MuseoSans-500-Italic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 1BCFCF38F59820D581E057A3 /* MuseoSans-500-Italic.otf */; };
|
||||
1BCFC681892C7A6DF96DB65E /* MuseoSans-900.otf in Resources */ = {isa = PBXBuildFile; fileRef = 1BCFC40D1BFCFBF04BC79A35 /* MuseoSans-900.otf */; };
|
||||
1BCFC7C3FCBF364F3239C3D4 /* CommonUI.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BCFC32EC1E5AE196D194D21 /* CommonUI.m */; };
|
||||
1BCFCA0CE51B511304182C62 /* MuseoSans-300.otf in Resources */ = {isa = PBXBuildFile; fileRef = 1BCFCEC8D56D29C6C3AE4380 /* MuseoSans-300.otf */; };
|
||||
1BCFCB7B50DAE4885AE55B80 /* MuseoSans-100.otf in Resources */ = {isa = PBXBuildFile; fileRef = 1BCFCC3154DB1D3B3C025211 /* MuseoSans-100.otf */; };
|
||||
1BCFCC3709A3C3783E180815 /* ChangeTitleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BCFCE26B630D546311BB715 /* ChangeTitleViewController.m */; };
|
||||
|
|
@ -94,10 +95,12 @@
|
|||
/* Begin PBXFileReference section */
|
||||
1613DC56A86AFA7E50460A37 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
1BCFC23988387A5CAE551C90 /* UIColor+Hex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Hex.m"; sourceTree = "<group>"; };
|
||||
1BCFC32EC1E5AE196D194D21 /* CommonUI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommonUI.m; sourceTree = "<group>"; };
|
||||
1BCFC3B62AA92DB07923F7C1 /* PostCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PostCollection.m; sourceTree = "<group>"; };
|
||||
1BCFC40D1BFCFBF04BC79A35 /* MuseoSans-900.otf */ = {isa = PBXFileReference; lastKnownFileType = file.otf; path = "MuseoSans-900.otf"; sourceTree = "<group>"; };
|
||||
1BCFC462F5540C67B9D97299 /* MuseoSans-700.otf */ = {isa = PBXFileReference; lastKnownFileType = file.otf; path = "MuseoSans-700.otf"; sourceTree = "<group>"; };
|
||||
1BCFC7FD826AC4789F946BC9 /* MuseoSans-900-Italic.otf */ = {isa = PBXFileReference; lastKnownFileType = file.otf; path = "MuseoSans-900-Italic.otf"; sourceTree = "<group>"; };
|
||||
1BCFCA73B716677EFBCEC417 /* CommonUI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonUI.h; sourceTree = "<group>"; };
|
||||
1BCFCB18C8C8304D67E6462E /* PostCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostCollection.h; sourceTree = "<group>"; };
|
||||
1BCFCB5C36F301B2B93F8069 /* PostCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PostCell.m; sourceTree = "<group>"; };
|
||||
1BCFCB67571197A762B88624 /* MuseoSans-100-Italic.otf */ = {isa = PBXFileReference; lastKnownFileType = file.otf; path = "MuseoSans-100-Italic.otf"; sourceTree = "<group>"; };
|
||||
|
|
@ -298,6 +301,8 @@
|
|||
1BCFC29A0845EAB04BFDAD67 /* Fonts */,
|
||||
7B2B434F1AED5BA500BAC4E2 /* Functions.h */,
|
||||
7B2B43501AED5BA500BAC4E2 /* Functions.m */,
|
||||
1BCFC32EC1E5AE196D194D21 /* CommonUI.m */,
|
||||
1BCFCA73B716677EFBCEC417 /* CommonUI.h */,
|
||||
);
|
||||
path = Blog;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -663,6 +668,7 @@
|
|||
1BCFCD7E8EEBFAA97226B0BF /* UIColor+Hex.m in Sources */,
|
||||
1BCFCF6DB93786CC2EDB8F69 /* PostCollection.m in Sources */,
|
||||
1BCFCC3709A3C3783E180815 /* ChangeTitleViewController.m in Sources */,
|
||||
1BCFC7C3FCBF364F3239C3D4 /* CommonUI.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
7
Blog/CommonUI.h
Normal file
7
Blog/CommonUI.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
//
|
||||
// Created by Sami Samhuri on 15-05-15.
|
||||
// Copyright (c) 2015 Guru Logic Inc. All rights reserved.
|
||||
//
|
||||
@import UIKit;
|
||||
|
||||
extern UIView *NewFontAwesomeHUDView(NSString *text);
|
||||
15
Blog/CommonUI.m
Normal file
15
Blog/CommonUI.m
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// Created by Sami Samhuri on 15-05-15.
|
||||
// Copyright (c) 2015 Guru Logic Inc. All rights reserved.
|
||||
//
|
||||
#import "CommonUI.h"
|
||||
#import <FontAwesome+iOS/UIFont+FontAwesome.h>
|
||||
|
||||
UIView *NewFontAwesomeHUDView(NSString *text) {
|
||||
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
label.textColor = [UIColor whiteColor];
|
||||
label.font = [UIFont fontAwesomeFontOfSize:36];
|
||||
label.text = text;
|
||||
[label sizeToFit];
|
||||
return label;
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
#import "NSString+FontAwesome.h"
|
||||
#import "UIColor+Hex.h"
|
||||
#import "MBProgressHUD.h"
|
||||
#import "UIFont+FontAwesome.h"
|
||||
#import "CommonUI.h"
|
||||
|
||||
@interface EditorViewController () <UITextViewDelegate, UIPopoverPresentationControllerDelegate>
|
||||
|
||||
|
|
@ -346,7 +346,7 @@ static NSString *const StateRestorationModifiedPostKey = @"modifiedPost";
|
|||
}
|
||||
promise.then(^(Post *post) {
|
||||
hud.mode = MBProgressHUDModeCustomView;
|
||||
hud.customView = [self HUDLabelWithText:[NSString fontAwesomeIconStringForEnum:FACheck]];
|
||||
hud.customView = NewFontAwesomeHUDView([NSString fontAwesomeIconStringForEnum:FACheck]);
|
||||
hud.labelText = isPublish ? @"Published" : @"Unpublished";
|
||||
self.post = post;
|
||||
self.modifiedPost = post;
|
||||
|
|
@ -354,23 +354,15 @@ static NSString *const StateRestorationModifiedPostKey = @"modifiedPost";
|
|||
[hud hide:YES afterDelay:1];
|
||||
}).catch(^(NSError *error) {
|
||||
hud.mode = MBProgressHUDModeCustomView;
|
||||
hud.customView = [self HUDLabelWithText:[NSString fontAwesomeIconStringForEnum:FATimes]];
|
||||
hud.customView = NewFontAwesomeHUDView([NSString fontAwesomeIconStringForEnum:FATimes]);
|
||||
hud.labelText = @"Fail";
|
||||
hud.detailsLabelText = error.localizedDescription;
|
||||
[hud hide:YES afterDelay:3];
|
||||
NSLog(@"fail %@ %@", error, error.userInfo);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
- (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 {
|
||||
[self savePostAndWaitForCompilation:NO];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,3 @@
|
|||
@property (nonatomic, strong) BlogController *blogController;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#import <PromiseKit/Promise.h>
|
||||
#import <ObjectiveSugar/NSArray+ObjectiveSugar.h>
|
||||
#import <FontAwesome+iOS/NSString+FontAwesome.h>
|
||||
#import "PostsViewController.h"
|
||||
#import "EditorViewController.h"
|
||||
#import "Post.h"
|
||||
|
|
@ -20,6 +21,8 @@
|
|||
#import "ModelStore.h"
|
||||
#import "UIImage+FontAwesome.h"
|
||||
#import "NSString+marshmallows.h"
|
||||
#import "MBProgressHUD.h"
|
||||
#import "CommonUI.h"
|
||||
|
||||
@interface PostsViewController ()
|
||||
|
||||
|
|
@ -268,11 +271,6 @@ static const NSUInteger SectionPublished = 1;
|
|||
return [self postCollectionForSection:SectionPublished].posts;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
- (IBAction)insertNewObject:(id)sender {
|
||||
NSURL *url = [UIPasteboard generalPasteboard].URL;
|
||||
NSString *title = [[UIPasteboard generalPasteboard].string mm_stringByTrimmingWhitespace];
|
||||
|
|
@ -293,38 +291,40 @@ static const NSUInteger SectionPublished = 1;
|
|||
- (IBAction)publish:(id)sender {
|
||||
// TODO: activity indicator
|
||||
__weak typeof(self) welf = self;
|
||||
void (^publish)(PMKPromise *) = ^(PMKPromise *promise) {
|
||||
self.publishButton.enabled = NO;
|
||||
void (^publish)(NSString *, PMKPromise *) = ^(NSString *message, PMKPromise *promise) {
|
||||
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
||||
hud.labelText = message;
|
||||
typeof(self) self = welf;
|
||||
promise.then(^{
|
||||
[self requestStatusWithoutCaching];
|
||||
hud.mode = MBProgressHUDModeCustomView;
|
||||
hud.customView = NewFontAwesomeHUDView([NSString fontAwesomeIconStringForEnum:FACheck]);
|
||||
hud.labelText = @"All good";
|
||||
[hud hide:YES afterDelay:1];
|
||||
}).catch(^(NSError *error) {
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert];
|
||||
__weak typeof(self) welf = self;
|
||||
[alertController addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
||||
typeof(self) self = welf;
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}]];
|
||||
[self presentViewController:alertController animated:YES completion:nil];
|
||||
}).finally(^{
|
||||
self.publishButton.enabled = YES;
|
||||
hud.mode = MBProgressHUDModeCustomView;
|
||||
hud.customView = NewFontAwesomeHUDView([NSString fontAwesomeIconStringForEnum:FATimes]);
|
||||
hud.labelText = @"Fail";
|
||||
hud.detailsLabelText = error.localizedDescription;
|
||||
[hud hide:YES afterDelay:3];
|
||||
NSLog(@"fail %@ %@", error, error.userInfo);
|
||||
});
|
||||
};
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Publish" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
||||
[alertController addAction:[UIAlertAction actionWithTitle:@"samhuri.net" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
|
||||
typeof(self) self = welf;
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
publish([self.blogController requestPublishToProductionEnvironment]);
|
||||
publish(@"samhuri.net", [self.blogController requestPublishToProductionEnvironment]);
|
||||
}]];
|
||||
[alertController addAction:[UIAlertAction actionWithTitle:@"beta.samhuri.net" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
||||
typeof(self) self = welf;
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
publish([self.blogController requestPublishToStagingEnvironment]);
|
||||
publish(@"beta.samhuri.net", [self.blogController requestPublishToStagingEnvironment]);
|
||||
}]];
|
||||
[alertController addAction:[UIAlertAction actionWithTitle:@"Push to GitHub" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
||||
typeof(self) self = welf;
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
publish([self.blogController requestSync]);
|
||||
publish(@"Pushing", [self.blogController requestSync]);
|
||||
}]];
|
||||
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
||||
typeof(self) self = welf;
|
||||
|
|
|
|||
Loading…
Reference in a new issue