mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-06-28 05:29:28 +00:00
add publish draft and unpublish post
This commit is contained in:
parent
395170037a
commit
b1b7cc6a70
2 changed files with 32 additions and 0 deletions
|
|
@ -43,6 +43,12 @@
|
|||
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" barStyle="black" translucent="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YUD-Xe-6Cc">
|
||||
<rect key="frame" x="0.0" y="492" width="600" height="44"/>
|
||||
<items>
|
||||
<barButtonItem title="Publish" id="qEb-VA-ueB">
|
||||
<connections>
|
||||
<action selector="publishOrUnpublish:" destination="JEX-9P-axG" id="Vxe-Fp-IDn"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
<barButtonItem style="plain" systemItem="flexibleSpace" id="dZ8-jR-S40"/>
|
||||
<barButtonItem title="Preview" id="uGx-Jy-rOz">
|
||||
<connections>
|
||||
<segue destination="ixd-IL-hNy" kind="show" identifier="showPreview" id="eVY-Ks-1b3"/>
|
||||
|
|
@ -98,6 +104,8 @@
|
|||
</navigationItem>
|
||||
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics" statusBarStyle="lightContent"/>
|
||||
<connections>
|
||||
<outlet property="linkLabel" destination="UkA-he-S6k" id="Czh-uA-7KF"/>
|
||||
<outlet property="publishBarButtonItem" destination="qEb-VA-ueB" id="biG-Yd-W5Z"/>
|
||||
<outlet property="textView" destination="wrG-1y-ZY3" id="lvo-lm-t7Z"/>
|
||||
<outlet property="titleView" destination="udr-9h-BhX" id="fju-wx-M92"/>
|
||||
<outlet property="toolbar" destination="YUD-Xe-6Cc" id="SIv-cT-WDD"/>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
@property (nonatomic, weak) IBOutlet UILabel *titleView;
|
||||
@property (nonatomic, weak) IBOutlet UITextView *textView;
|
||||
@property (nonatomic, weak) IBOutlet UIToolbar *toolbar;
|
||||
@property (nonatomic, weak) IBOutlet UIBarButtonItem *publishBarButtonItem;
|
||||
@property (strong, nonatomic) Post *modifiedPost;
|
||||
@property (strong, nonatomic) PMKPromise *savePromise;
|
||||
|
||||
|
|
@ -54,6 +55,7 @@
|
|||
[self.toolbar.items enumerateObjectsUsingBlock:^(UIBarButtonItem *item, NSUInteger idx, BOOL *stop) {
|
||||
item.enabled = toolbarEnabled;
|
||||
}];
|
||||
self.publishBarButtonItem.title = self.modifiedPost.draft ? @"Publish" : @"Unpublish";
|
||||
}
|
||||
|
||||
- (void)configureTitleView {
|
||||
|
|
@ -151,6 +153,28 @@
|
|||
self.modifiedPost = [self.modifiedPost copyWithURL:url];
|
||||
}
|
||||
|
||||
- (IBAction)publishOrUnpublish:(id)sender {
|
||||
// TODO: prevent changes while publishing
|
||||
[self savePost].then(^{
|
||||
PMKPromise *promise = nil;
|
||||
Post *post = self.modifiedPost;
|
||||
if (post.draft) {
|
||||
promise = [self.blogController requestPublishDraftWithPath:post.path];
|
||||
}
|
||||
else {
|
||||
promise = [self.blogController requestUnpublishPostWithPath:post.path];
|
||||
}
|
||||
promise.then(^(Post *post) {
|
||||
self.post = post;
|
||||
self.modifiedPost = post;
|
||||
[self configureView];
|
||||
if (self.postUpdatedBlock) {
|
||||
self.postUpdatedBlock(post);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
- (IBAction)presentChangeTitle:(id)sender {
|
||||
if (self.presentedViewController) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue