Skip to content

Commit

Permalink
Offline Mode: Update post.status handling in post/page settings (#23071)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Apr 24, 2024
2 parents 7d16f0e + b59394d commit 893bb0a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Foundation
case editorPostPublishTap
case editorPostPublishDismissed
case editorPostScheduledChanged
case editorPostPendingReviewChanged
case editorPostTitleChanged
case editorPostVisibilityChanged
case editorPostTagsChanged
Expand Down Expand Up @@ -627,6 +628,8 @@ import Foundation
return "editor_post_publish_dismissed"
case .editorPostScheduledChanged:
return "editor_post_scheduled_changed"
case .editorPostPendingReviewChanged:
return "editor_post_pending_review_changed"
case .editorPostTitleChanged:
return "editor_post_title_changed"
case .editorPostVisibilityChanged:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension PostSettingsViewController {
Task { @MainActor in
do {
let coordinator = PostCoordinator.shared
if apost.original().status == .draft {
if coordinator.isSyncAllowed(for: apost) {
coordinator.setNeedsSync(for: apost)
} else {
try await coordinator._save(apost)
Expand Down
33 changes: 29 additions & 4 deletions WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ typedef NS_ENUM(NSInteger, PostSettingsRow) {
PostSettingsRowTags,
PostSettingsRowAuthor,
PostSettingsRowPublishDate,
// - warning: deprecated (kahu-offline-mode)
PostSettingsRowStatus,
PostSettingsRowPendingReview,
PostSettingsRowVisibility,
PostSettingsRowPassword,
PostSettingsRowFormat,
Expand All @@ -50,7 +52,7 @@ typedef NS_ENUM(NSInteger, PostSettingsRow) {
static NSString *const TableViewActivityCellIdentifier = @"TableViewActivityCellIdentifier";
static NSString *const TableViewProgressCellIdentifier = @"TableViewProgressCellIdentifier";
static NSString *const TableViewFeaturedImageCellIdentifier = @"TableViewFeaturedImageCellIdentifier";
static NSString *const TableViewStickyPostCellIdentifier = @"TableViewStickyPostCellIdentifier";
static NSString *const TableViewToggleCellIdentifier = @"TableViewToggleCellIdentifier";
static NSString *const TableViewGenericCellIdentifier = @"TableViewGenericCellIdentifier";


Expand Down Expand Up @@ -138,7 +140,7 @@ - (void)viewDidLoad
[self.tableView registerNib:[UINib nibWithNibName:@"WPTableViewActivityCell" bundle:nil] forCellReuseIdentifier:TableViewActivityCellIdentifier];
[self.tableView registerClass:[WPProgressTableViewCell class] forCellReuseIdentifier:TableViewProgressCellIdentifier];
[self.tableView registerClass:[PostFeaturedImageCell class] forCellReuseIdentifier:TableViewFeaturedImageCellIdentifier];
[self.tableView registerClass:[SwitchTableViewCell class] forCellReuseIdentifier:TableViewStickyPostCellIdentifier];
[self.tableView registerClass:[SwitchTableViewCell class] forCellReuseIdentifier:TableViewToggleCellIdentifier];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:TableViewGenericCellIdentifier];

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 44.0)]; // add some vertical padding
Expand Down Expand Up @@ -670,7 +672,19 @@ - (void)configureMetaSectionRows
[metaRows addObject:@(PostSettingsRowAuthor)];
}

if (![RemoteFeature enabled:RemoteFeatureFlagSyncPublishing] || !self.isDraftOrPending) {
if ([RemoteFeature enabled:RemoteFeatureFlagSyncPublishing]) {
if (self.isDraftOrPending) {
[metaRows addObject:@(PostSettingsRowPendingReview)];
} else {
[metaRows addObjectsFromArray:@[
@(PostSettingsRowPublishDate),
@(PostSettingsRowVisibility)
]];
if (self.apost.password) {
[metaRows addObject:@(PostSettingsRowPassword)];
}
}
} else {
[metaRows addObject:@(PostSettingsRowPublishDate)];
[metaRows addObjectsFromArray:@[ @(PostSettingsRowStatus),
@(PostSettingsRowVisibility) ]];
Expand Down Expand Up @@ -739,6 +753,17 @@ - (UITableViewCell *)configureMetaPostMetaCellForIndexPath:(NSIndexPath *)indexP

} else if (row == PostSettingsRowPassword) {
cell = [self configurePasswordCell];
} else if (row == PostSettingsRowPendingReview) {
// Pending Review
__weak __typeof(self) weakSelf = self;
SwitchTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:TableViewToggleCellIdentifier];
cell.name = NSLocalizedStringWithDefaultValue(@"postSettings.pendingReview", nil, [NSBundle mainBundle], @"Pending review", @"The 'Pending Review' setting of the post");
cell.on = [self.post.status isEqualToString:PostStatusPending];
cell.onChange = ^(BOOL newValue) {
[WPAnalytics trackEvent:WPAnalyticsEventEditorPostPendingReviewChanged properties:@{@"via": @"settings"}];
weakSelf.post.status = newValue ? PostStatusPending : PostStatusDraft;
};
return cell;
}

return cell;
Expand Down Expand Up @@ -826,7 +851,7 @@ - (UITableViewCell *)configureStickyPostCellForIndexPath:(NSIndexPath *)indexPat
{
__weak __typeof(self) weakSelf = self;

SwitchTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:TableViewStickyPostCellIdentifier];
SwitchTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:TableViewToggleCellIdentifier];
cell.name = NSLocalizedString(@"Stick post to the front page", @"This is the cell title.");
cell.on = self.post.isStickyPost;
cell.onChange = ^(BOOL newValue) {
Expand Down

0 comments on commit 893bb0a

Please sign in to comment.