Skip to content

Commit

Permalink
Add Media Upload to Post Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Apr 26, 2024
1 parent 998a240 commit a62d150
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
4 changes: 2 additions & 2 deletions WordPress/Classes/ViewRelated/Post/PostMediaUploadsView.swift
Expand Up @@ -4,8 +4,8 @@ import SwiftUI
final class PostMediaUploadsViewController: UIHostingController<PostMediaUploadsView> {
private let viewModel: PostMediaUploadsViewModel

init(post: AbstractPost) {
self.viewModel = PostMediaUploadsViewModel(post: post) // Manange lifecycle
init(post: AbstractPost, isShowingOnlyPending: Bool = true) {
self.viewModel = PostMediaUploadsViewModel(post: post, isShowingOnlyPending: isShowingOnlyPending) // Manange lifecycle
super.init(rootView: PostMediaUploadsView(viewModel: viewModel))
}

Expand Down
Expand Up @@ -21,10 +21,13 @@ final class PostMediaUploadsViewModel: ObservableObject {
timer?.invalidate()
}

init(post: AbstractPost, coordinator: MediaCoordinator = .shared) {
init(post: AbstractPost, isShowingOnlyPending: Bool = true, coordinator: MediaCoordinator = .shared) {
self.post = post
self.coordinator = coordinator
self.uploads = Array(post.media).filter(\.isUploadNeeded).sorted {
let media = Array(post.media).filter {
isShowingOnlyPending ? $0.isUploadNeeded : true
}
self.uploads = media.sorted {
($0.creationDate ?? .now) < ($1.creationDate ?? .now)
}.map {
PostMediaUploadItemViewModel(media: $0, coordinator: coordinator)
Expand All @@ -41,6 +44,10 @@ final class PostMediaUploadsViewModel: ObservableObject {
}.store(in: &cancellables)
}

static func getPendingUploads(for post: AbstractPost) -> [Media] {
Array(post.media).filter(\.isUploadNeeded)
}

private func didUpdateMedia(_ media: Set<Media>) {
let remainingObjectIDs = Set(media.map(\.objectID))
withAnimation {
Expand Down
Expand Up @@ -172,6 +172,13 @@ extension PostSettingsViewController {
private static var cancellablesKey: UInt8 = 0
}

extension PostSettingsViewController {
@objc func showMediaUploadsController() {
let viewController = PostMediaUploadsViewController(post: apost, isShowingOnlyPending: false)
navigationController?.pushViewController(viewController, animated: true)
}
}

extension PostSettingsViewController: UIAdaptivePresentationControllerDelegate {
public func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
deleteRevision()
Expand Down
23 changes: 21 additions & 2 deletions WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m
Expand Up @@ -42,7 +42,8 @@ typedef NS_ENUM(NSInteger, PostSettingsRow) {
PostSettingsRowSlug,
PostSettingsRowExcerpt,
PostSettingsRowSocialNoConnections,
PostSettingsRowSocialRemainingShares
PostSettingsRowSocialRemainingShares,
PostSettingsRowMediaUploads
};

static CGFloat CellHeight = 44.0f;
Expand Down Expand Up @@ -418,7 +419,8 @@ - (void)configureSections
@(PostSettingsSectionShare),
disabledTwitterSection,
remainingSharesSection,
@(PostSettingsSectionMoreOptions) ] mutableCopy];
@(PostSettingsSectionMoreOptions),
@(PostSettingsSectionMaintenance)] mutableCopy];
// Remove sticky post section for self-hosted non Jetpack site
// and non admin user
//
Expand Down Expand Up @@ -466,6 +468,8 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return 1;
} else if (sec == PostSettingsSectionMoreOptions) {
return 2;
} else if (sec == PostSettingsSectionMaintenance) {
return 1;
}

return 0;
Expand Down Expand Up @@ -502,6 +506,8 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
} else if (sec == PostSettingsSectionMoreOptions) {
return NSLocalizedString(@"More Options", @"Label for the More Options area in post settings. Should use the same translation as core WP.");

} else if (sec == PostSettingsSectionMaintenance) {
return NSLocalizedStringWithDefaultValue(@"postSettings.section.maintenance.header", nil, [NSBundle mainBundle], @"Maintenance", @"Section title for the Maintanence Settings screen");
}
return nil;
}
Expand Down Expand Up @@ -584,6 +590,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [self configureRemainingSharesCell];
} else if (sec == PostSettingsSectionMoreOptions) {
cell = [self configureMoreOptionsCellForIndexPath:indexPath];
} else if (sec == PostSettingsSectionMaintenance) {
cell = [self configureMaintanenceSectionCellForIndexPath:indexPath];
}

return cell ?: [UITableViewCell new];
Expand Down Expand Up @@ -626,6 +634,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[self showEditSlugController];
} else if (cell.tag == PostSettingsRowExcerpt) {
[self showEditExcerptController];
} else if (cell.tag == PostSettingsRowMediaUploads) {
[self showMediaUploadsController];
}
}

Expand Down Expand Up @@ -949,6 +959,15 @@ - (UITableViewCell *)configureSocialCellForIndexPath:(NSIndexPath *)indexPath
return cell;
}

- (UITableViewCell *)configureMaintanenceSectionCellForIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [self getWPTableViewDisclosureCell];
cell.textLabel.text = NSLocalizedStringWithDefaultValue(@"postSettings.mediaUploadsRow", nil, [NSBundle mainBundle], @"Media Uploads", @"Post Settings media uploads row title");
cell.detailTextLabel.text = [NSString stringWithFormat:@"%i", self.apost.media.count];
cell.tag = PostSettingsRowMediaUploads;
return cell;
}

- (UITableViewCell *)configureDisclosureCellWithSharing:(BOOL)canEditSharing
{
UITableViewCell *cell = [self getWPTableViewDisclosureCell];
Expand Down
Expand Up @@ -10,7 +10,8 @@ typedef enum {
PostSettingsSectionDisabledTwitter, // NOTE: Clean up when Twitter has been removed from Publicize services.
PostSettingsSectionSharesRemaining,
PostSettingsSectionGeolocation,
PostSettingsSectionMoreOptions
PostSettingsSectionMoreOptions,
PostSettingsSectionMaintenance
} PostSettingsSection;


Expand Down

0 comments on commit a62d150

Please sign in to comment.