Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Comment: add initial view #17046

Merged
merged 6 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum FeatureFlag: Int, CaseIterable, OverrideableFlag {
case siteIconCreator
case editorOnboardingHelpMenu
case unifiedCommentsAndNotificationsList
case newCommentEdit

/// Returns a boolean indicating if the feature is enabled
var enabled: Bool {
Expand Down Expand Up @@ -43,6 +44,8 @@ enum FeatureFlag: Int, CaseIterable, OverrideableFlag {
return BuildConfiguration.current ~= [.localDeveloper, .a8cBranchTest]
case .unifiedCommentsAndNotificationsList:
return true
case .newCommentEdit:
return false
}
}

Expand Down Expand Up @@ -91,6 +94,8 @@ extension FeatureFlag {
return "Editor Onboarding Help Menu"
case .unifiedCommentsAndNotificationsList:
return "Unified List for Comments and Notifications"
case .newCommentEdit:
return "New Comment Edit"
}
}

Expand Down
35 changes: 22 additions & 13 deletions WordPress/Classes/ViewRelated/Comments/CommentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -654,20 +654,29 @@ - (void)spamAction

- (void)editComment
{
EditCommentViewController *editViewController = [EditCommentViewController newEditViewController];
editViewController.content = [self.comment contentForEdit];

__typeof(self) __weak weakSelf = self;
editViewController.onCompletion = ^(BOOL hasNewContent, NSString *newContent) {
[self dismissViewControllerAnimated:YES completion:^{
if (hasNewContent) {
[weakSelf updateCommentForNewContent:newContent];
}
}];
};
UINavigationController *navController;

if ([Feature enabled:FeatureFlagNewCommentEdit]) {
EditCommentTableViewController *editViewController = [[EditCommentTableViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:editViewController];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
} else {
EditCommentViewController *editViewController = [EditCommentViewController newEditViewController];
editViewController.content = [self.comment contentForEdit];

__typeof(self) __weak weakSelf = self;
editViewController.onCompletion = ^(BOOL hasNewContent, NSString *newContent) {
[self dismissViewControllerAnimated:YES completion:^{
if (hasNewContent) {
[weakSelf updateCommentForNewContent:newContent];
}
}];
};

navController = [[UINavigationController alloc] initWithRootViewController:editViewController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
}

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:editViewController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
navController.navigationBar.translucent = NO;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import Foundation


class EditCommentTableViewController: UITableViewController {

// MARK: - Properties

private let sectionHeaders =
[NSLocalizedString("Name", comment: "Header for a comment author's name, shown when editing a comment.").localizedUppercase,
NSLocalizedString("Comment", comment: "Header for a comment's content, shown when editing a comment.").localizedUppercase,
NSLocalizedString("Web Address", comment: "Header for a comment author's web address, shown when editing a comment.").localizedUppercase,
NSLocalizedString("Email Address", comment: "Header for a comment author's email address, shown when editing a comment.").localizedUppercase]

// MARK: - Init

required convenience init() {
self.init(style: .insetGrouped)
}

override init(style: UITableView.Style) {
super.init(style: style)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - View

override func viewDidLoad() {
super.viewDidLoad()
setupNavBar()
}

// MARK: - UITableViewDelegate

override func numberOfSections(in tableView: UITableView) -> Int {
return sectionHeaders.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sectionHeaders[safe: section]
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// TODO: return custom cell
return UITableViewCell()
}

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
// Make sure no SectionFooter is rendered
return CGFloat.leastNormalMagnitude
}

override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
// Make sure no SectionFooter is rendered
return nil
}

}

private extension EditCommentTableViewController {

// MARK: - View Config

func setupNavBar() {
title = NSLocalizedString("Edit Comment", comment: "View title when editing a comment.")
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelButtonTapped))
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(doneButtonTapped))
}

// MARK: - Nav bar button actions

@objc func cancelButtonTapped(sender: UIBarButtonItem) {
// TODO: discard changes
dismiss(animated: true)
}

@objc func doneButtonTapped(sender: UIBarButtonItem) {
// TODO: save changes
dismiss(animated: true)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1223,20 +1223,30 @@ private extension NotificationDetailsViewController {
}

func displayCommentEditorWithBlock(_ block: FormattableCommentContent) {
let editViewController = EditCommentViewController.newEdit()
editViewController?.content = block.text
editViewController?.onCompletion = { (hasNewContent, newContent) in
self.dismiss(animated: true, completion: {
guard hasNewContent else {
return
}
let newContent = newContent ?? ""
self.updateComment(with: block, content: newContent)
})

var navController: UINavigationController

if FeatureFlag.newCommentEdit.enabled {
let editViewController = EditCommentTableViewController()
navController = UINavigationController(rootViewController: editViewController)
navController.modalPresentationStyle = .fullScreen
} else {
let editViewController = EditCommentViewController.newEdit()
editViewController?.content = block.text
editViewController?.onCompletion = { (hasNewContent, newContent) in
self.dismiss(animated: true, completion: {
guard hasNewContent else {
return
}
let newContent = newContent ?? ""
self.updateComment(with: block, content: newContent)
})
}

navController = UINavigationController(rootViewController: editViewController!)
navController.modalPresentationStyle = .formSheet
}

let navController = UINavigationController(rootViewController: editViewController!)
navController.modalPresentationStyle = .formSheet
navController.modalTransitionStyle = .coverVertical
navController.navigationBar.isTranslucent = false

Expand Down
6 changes: 6 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,8 @@
98906508237CC1DF00218CD2 /* WidgetTwoColumnCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 989064FE237CC1DE00218CD2 /* WidgetTwoColumnCell.xib */; };
98906509237CC1DF00218CD2 /* WidgetTwoColumnCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 989064FE237CC1DE00218CD2 /* WidgetTwoColumnCell.xib */; };
98921EF721372E12004949AA /* MediaCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98921EF621372E12004949AA /* MediaCoordinator.swift */; };
9895401126C1F39300EDEB5A /* EditCommentTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9895401026C1F39300EDEB5A /* EditCommentTableViewController.swift */; };
9895401226C1F39300EDEB5A /* EditCommentTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9895401026C1F39300EDEB5A /* EditCommentTableViewController.swift */; };
9895B6E021ED49160053D370 /* TopTotalsCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9895B6DF21ED49160053D370 /* TopTotalsCell.xib */; };
989643E223A02F080070720A /* WidgetUnconfiguredCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 989064FB237CC1DE00218CD2 /* WidgetUnconfiguredCell.swift */; };
989643E423A02F4E0070720A /* UIColor+MurielColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 435B762122973D0600511813 /* UIColor+MurielColors.swift */; };
Expand Down Expand Up @@ -6239,6 +6241,7 @@
989064FD237CC1DE00218CD2 /* WidgetTwoColumnCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidgetTwoColumnCell.swift; sourceTree = "<group>"; };
989064FE237CC1DE00218CD2 /* WidgetTwoColumnCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WidgetTwoColumnCell.xib; sourceTree = "<group>"; };
98921EF621372E12004949AA /* MediaCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaCoordinator.swift; sourceTree = "<group>"; };
9895401026C1F39300EDEB5A /* EditCommentTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditCommentTableViewController.swift; sourceTree = "<group>"; };
9895B6DF21ED49160053D370 /* TopTotalsCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TopTotalsCell.xib; sourceTree = "<group>"; };
989643EA23A0437B0070720A /* WidgetDifferenceCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetDifferenceCell.swift; sourceTree = "<group>"; };
989643EB23A0437B0070720A /* WidgetDifferenceCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = WidgetDifferenceCell.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -12387,6 +12390,7 @@
313AE49B19E3F20400AAFABE /* CommentViewController.h */,
313AE49C19E3F20400AAFABE /* CommentViewController.m */,
B0AC50B3251E959B0039E022 /* CommentViewController.swift */,
9895401026C1F39300EDEB5A /* EditCommentTableViewController.swift */,
2906F80F110CDA8900169D56 /* EditCommentViewController.h */,
2906F810110CDA8900169D56 /* EditCommentViewController.m */,
328CEC5D23A532BA00A6899E /* FullScreenCommentReplyViewController.swift */,
Expand Down Expand Up @@ -17287,6 +17291,7 @@
400A2C772217A8A0000A8A59 /* VisitsSummaryStatsRecordValue+CoreDataClass.swift in Sources */,
D8212CB320AA6861008E8AE8 /* ReaderFollowAction.swift in Sources */,
F5D399302541F25B0058D0AB /* SheetActions.swift in Sources */,
9895401126C1F39300EDEB5A /* EditCommentTableViewController.swift in Sources */,
8B7F51C924EED804008CF5B5 /* ReaderTracker.swift in Sources */,
E6F2788421BC1A4A008B4DB5 /* PlanFeature.swift in Sources */,
3F421DF524A3EC2B00CA9B9E /* Spotlightable.swift in Sources */,
Expand Down Expand Up @@ -19723,6 +19728,7 @@
FABB23F12602FC2C00C8785C /* DefaultStockPhotosService.swift in Sources */,
FABB23F22602FC2C00C8785C /* Animator.swift in Sources */,
FABB23F32602FC2C00C8785C /* SiteStatsDashboardViewController.swift in Sources */,
9895401226C1F39300EDEB5A /* EditCommentTableViewController.swift in Sources */,
FABB23F42602FC2C00C8785C /* MediaSettings.swift in Sources */,
FABB23F52602FC2C00C8785C /* DomainCreditRedemptionSuccessViewController.swift in Sources */,
FABB23F62602FC2C00C8785C /* ActivityLogDetailViewController.m in Sources */,
Expand Down