From da471d444c4995a0223a5d123207d35719d1f4bd Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 12 Feb 2018 17:52:04 -0700 Subject: [PATCH 01/15] Initial showing of NoResultsVC when domain suggestion returns no results. Also, always show searchField. --- ...teCreationDomainsTableViewController.swift | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index 7b73ce56e5e4..98c334605ea0 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -11,6 +11,7 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { open var siteName: String? open var delegate: SiteCreationDomainsTableViewControllerDelegate? + private var noResultsViewController: NoResultsViewController? private var service: DomainsService? private var siteTitleSuggestions: [String] = [] private var searchSuggestions: [String] = [] @@ -71,6 +72,7 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { let api = WordPressComRestApi(oAuthToken: "") let service = DomainsService(managedObjectContext: ContextManager.sharedInstance().mainContext, remote: DomainsServiceRemote(wordPressComRestApi: api)) SVProgressHUD.show(withStatus: NSLocalizedString("Loading domains", comment: "Shown while the app waits for the domain suggestions web service to return during the site creation process.")) + service.getDomainSuggestions(base: searchTerm, success: { [weak self] (suggestions) in self?.isSearching = false SVProgressHUD.dismiss() @@ -79,6 +81,7 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { DDLogError("Error getting Domain Suggestions: \(error.localizedDescription)") self?.isSearching = false SVProgressHUD.dismiss() + self?.addNoResultsToView() } } @@ -116,14 +119,9 @@ extension SiteCreationDomainsTableViewController { override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch section { - case Sections.titleAndDescription.rawValue: + case Sections.titleAndDescription.rawValue, + Sections.searchField.rawValue: return 1 - case Sections.searchField.rawValue: - if siteTitleSuggestions.count == 0 { - return 0 - } else { - return 1 - } case Sections.suggestions.rawValue: return searchSuggestions.count > 0 ? searchSuggestions.count : siteTitleSuggestions.count default: @@ -207,6 +205,52 @@ extension SiteCreationDomainsTableViewController { } } +// MARK: NoResultsViewController Extension + +private extension SiteCreationDomainsTableViewController { + + func addNoResultsToView() { + if noResultsViewController == nil { + instantiateNoResultsViewController() + } + + guard let noResultsViewController = noResultsViewController else { + return + } + + // Calculate the frame for the noResultsVC. + var noResultsFrame = tableView.bounds + let titleCellRect = tableView.rect(forSection: Sections.titleAndDescription.rawValue) + let searchCellRect = tableView.rect(forSection: Sections.searchField.rawValue) + let noResultsOffset = searchCellRect.height + titleCellRect.height + + noResultsFrame.size.height -= noResultsOffset + noResultsFrame.origin.y += noResultsOffset + noResultsViewController.view.frame = noResultsFrame + + // Add noResultsVC to the tableView. + addChildViewController(noResultsViewController) + tableView.addSubview(noResultsViewController.view) + noResultsViewController.didMove(toParentViewController: self) + } + + func removeNoResultsFromView() { + noResultsViewController?.view.removeFromSuperview() + noResultsViewController?.removeFromParentViewController() + } + + func instantiateNoResultsViewController() { + let noResultsSB = UIStoryboard(name: "NoResults", bundle: nil) + noResultsViewController = noResultsSB.instantiateViewController(withIdentifier: "NoResults") as? NoResultsViewController + + let title = NSLocalizedString("No available site addresses with that name, maybe try another one?", comment: "Primary message shown when there are no domains that match the user entered text.") + let subtitle = NSLocalizedString("Enter another site name in the search box above.", comment: "Secondary message shown when there are no domains that match the user entered text.") + + noResultsViewController?.configure(title: title, buttonTitle: "i'm a button", subtitle: subtitle) + } + +} + // MARK: UITableViewDelegate extension SiteCreationDomainsTableViewController { @@ -247,6 +291,7 @@ extension SiteCreationDomainsTableViewController { extension SiteCreationDomainsTableViewController: SiteCreationDomainSearchTableViewCellDelegate { func startSearch(for searchTerm: String) { + removeNoResultsFromView() delegate?.newSearchStarted() guard searchTerm.count > 0 else { From c736264582d8915256de3d5c11da2f6897428666 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 14 Feb 2018 10:47:09 -0700 Subject: [PATCH 02/15] Adding the ability to hide the action button in the NoResults view. Hiding it for the the domain no suggestions view. --- .../Blog/NoResultsViewController.swift | 23 +++++++++++-------- ...teCreationDomainsTableViewController.swift | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blog/NoResultsViewController.swift b/WordPress/Classes/ViewRelated/Blog/NoResultsViewController.swift index d4540ce1358c..742823f419db 100644 --- a/WordPress/Classes/ViewRelated/Blog/NoResultsViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/NoResultsViewController.swift @@ -7,7 +7,8 @@ import UIKit /// A view to show when there are no results for a given situation. /// Ex: My Sites > account has no sites; My Sites > all sites are hidden. -/// The image, title, and action button will always show. +/// The image and title will always show. +/// The action button is shown by default, but will be hidden if button title is not provided. /// The subtitle is optional and will only show if provided. /// @objc class NoResultsViewController: NUXViewController { @@ -42,10 +43,10 @@ import UIKit /// /// - Parameters: /// - title: Main descriptive text. Required. - /// - buttonTitle: Title of action button. Required. + /// - buttonTitle: Title of action button. Optional. /// - subtitle: Secondary descriptive text. Optional. /// - image: Name of image file to use. Optional. - @objc func configure(title: String, buttonTitle: String, subtitle: String? = nil, image: String? = nil) { + @objc func configure(title: String, buttonTitle: String? = nil, subtitle: String? = nil, image: String? = nil) { titleText = title subtitleText = subtitle buttonText = buttonTitle @@ -67,17 +68,21 @@ import UIKit /// Use the values provided in the actual elements. private func configureView() { - guard let titleText = titleText, - let buttonText = buttonText else { + guard let titleText = titleText else { return } titleLabel.text = titleText subtitleLabel.text = subtitleText - actionButton?.setTitle(buttonText, for: UIControlState()) - actionButton?.setTitle(buttonText, for: .highlighted) - actionButton?.titleLabel?.adjustsFontForContentSizeCategory = true - actionButton?.accessibilityIdentifier = accessibilityIdentifier(for: buttonText) + + if let buttonText = buttonText { + actionButton?.setTitle(buttonText, for: UIControlState()) + actionButton?.setTitle(buttonText, for: .highlighted) + actionButton?.titleLabel?.adjustsFontForContentSizeCategory = true + actionButton?.accessibilityIdentifier = accessibilityIdentifier(for: buttonText) + } else { + actionButton.isHidden = true + } if let imageName = imageName { imageView.image = UIImage(named: imageName) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index 98c334605ea0..713310a8b4fd 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -246,7 +246,7 @@ private extension SiteCreationDomainsTableViewController { let title = NSLocalizedString("No available site addresses with that name, maybe try another one?", comment: "Primary message shown when there are no domains that match the user entered text.") let subtitle = NSLocalizedString("Enter another site name in the search box above.", comment: "Secondary message shown when there are no domains that match the user entered text.") - noResultsViewController?.configure(title: title, buttonTitle: "i'm a button", subtitle: subtitle) + noResultsViewController?.configure(title: title, buttonTitle: nil, subtitle: subtitle) } } From 83bf3885e3a98ce842a9ec25bccff249b6b9eb38 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 14 Feb 2018 11:15:27 -0700 Subject: [PATCH 03/15] Toggling the table separator for suggestions vs. no suggestions, to remove the stray line at the top of the table when there are no suggestions. --- .../NUX/SiteCreationDomainsTableViewController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index 713310a8b4fd..f5900620bc0b 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -76,11 +76,13 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { service.getDomainSuggestions(base: searchTerm, success: { [weak self] (suggestions) in self?.isSearching = false SVProgressHUD.dismiss() + self?.tableView.separatorStyle = .singleLine addSuggestions(suggestions) }) { [weak self] (error) in DDLogError("Error getting Domain Suggestions: \(error.localizedDescription)") self?.isSearching = false SVProgressHUD.dismiss() + self?.tableView.separatorStyle = .none self?.addNoResultsToView() } } From 402ac81a47b43bca6613efc8f18f3ef6df1461f7 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 14 Feb 2018 11:20:19 -0700 Subject: [PATCH 04/15] Calculate the frame for the NoResults view only once. --- ...teCreationDomainsTableViewController.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index f5900620bc0b..8180a63194aa 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -220,16 +220,6 @@ private extension SiteCreationDomainsTableViewController { return } - // Calculate the frame for the noResultsVC. - var noResultsFrame = tableView.bounds - let titleCellRect = tableView.rect(forSection: Sections.titleAndDescription.rawValue) - let searchCellRect = tableView.rect(forSection: Sections.searchField.rawValue) - let noResultsOffset = searchCellRect.height + titleCellRect.height - - noResultsFrame.size.height -= noResultsOffset - noResultsFrame.origin.y += noResultsOffset - noResultsViewController.view.frame = noResultsFrame - // Add noResultsVC to the tableView. addChildViewController(noResultsViewController) tableView.addSubview(noResultsViewController.view) @@ -249,6 +239,16 @@ private extension SiteCreationDomainsTableViewController { let subtitle = NSLocalizedString("Enter another site name in the search box above.", comment: "Secondary message shown when there are no domains that match the user entered text.") noResultsViewController?.configure(title: title, buttonTitle: nil, subtitle: subtitle) + + // Calculate the frame for the noResultsVC. + var noResultsFrame = tableView.bounds + let titleCellRect = tableView.rect(forSection: Sections.titleAndDescription.rawValue) + let searchCellRect = tableView.rect(forSection: Sections.searchField.rawValue) + let noResultsOffset = searchCellRect.height + titleCellRect.height + + noResultsFrame.size.height -= noResultsOffset + noResultsFrame.origin.y += noResultsOffset + noResultsViewController?.view.frame = noResultsFrame } } From 732955d6ae64a4fc3008c5a68a6e44b2c4e893da Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 14 Feb 2018 16:21:17 -0700 Subject: [PATCH 05/15] Adding NoResults view to the table as a table cell. --- ...teCreationDomainsTableViewController.swift | 69 +++++++++++++------ .../ViewRelated/Views/NoResults.storyboard | 2 +- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index 8180a63194aa..d3798c1290b7 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -18,6 +18,9 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { private var isSearching: Bool = false private var selectedCell: UITableViewCell? + // API returned no domain suggestions. + private var noSuggestions: Bool = false + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } @@ -40,7 +43,8 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - // only procede with initial search if we don't have site title suggestions yet (hopefully only the first time) + // only procede with initial search if we don't have site title suggestions yet + // (hopefully only the first time) guard siteTitleSuggestions.count < 1, let nameToSearch = siteName else { return @@ -77,13 +81,16 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { self?.isSearching = false SVProgressHUD.dismiss() self?.tableView.separatorStyle = .singleLine + self?.noSuggestions = false addSuggestions(suggestions) }) { [weak self] (error) in DDLogError("Error getting Domain Suggestions: \(error.localizedDescription)") self?.isSearching = false SVProgressHUD.dismiss() self?.tableView.separatorStyle = .none - self?.addNoResultsToView() + self?.noSuggestions = true + // reload to display the no results view. + self?.tableView.reloadSections(IndexSet(integer: Sections.suggestions.rawValue), with: .automatic) } } @@ -125,6 +132,9 @@ extension SiteCreationDomainsTableViewController { Sections.searchField.rawValue: return 1 case Sections.suggestions.rawValue: + if noSuggestions == true { + return 1 + } return searchSuggestions.count > 0 ? searchSuggestions.count : siteTitleSuggestions.count default: return 0 @@ -133,6 +143,7 @@ extension SiteCreationDomainsTableViewController { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: UITableViewCell + switch indexPath.section { case Sections.titleAndDescription.rawValue: cell = titleAndDescriptionCell() @@ -141,17 +152,35 @@ extension SiteCreationDomainsTableViewController { case Sections.suggestions.rawValue: fallthrough default: - let suggestion: String - if searchSuggestions.count > 0 { - suggestion = searchSuggestions[indexPath.row] + if noSuggestions == true { + cell = noResultsCell() } else { - suggestion = siteTitleSuggestions[indexPath.row] + let suggestion: String + if searchSuggestions.count > 0 { + suggestion = searchSuggestions[indexPath.row] + } else { + suggestion = siteTitleSuggestions[indexPath.row] + } + cell = suggestionCell(domain: suggestion) } - cell = suggestionCell(domain: suggestion) } return cell } + override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + + if indexPath.section == Sections.suggestions.rawValue && noSuggestions == true { + // Calculate the height of the no results cell from the bottom of + // the search field to the screen bottom, minus some padding. + let searchFieldRect = tableView.rect(forSection: Sections.searchField.rawValue) + let searchFieldBottom = searchFieldRect.origin.y + searchFieldRect.height + let screenBottom = UIScreen.main.bounds.height + return screenBottom - searchFieldBottom - 80 + } + + return super.tableView(tableView, heightForRowAt: indexPath) + } + override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { if section == Sections.suggestions.rawValue { let footer = UIView() @@ -187,6 +216,13 @@ extension SiteCreationDomainsTableViewController { return cell } + private func noResultsCell() -> UITableViewCell { + let cell = UITableViewCell() + addNoResultsTo(cell: cell) + cell.isUserInteractionEnabled = false + return cell + } + private func suggestionCell(domain: String) -> UITableViewCell { let cell = UITableViewCell() @@ -211,7 +247,7 @@ extension SiteCreationDomainsTableViewController { private extension SiteCreationDomainsTableViewController { - func addNoResultsToView() { + func addNoResultsTo(cell: UITableViewCell) { if noResultsViewController == nil { instantiateNoResultsViewController() } @@ -220,13 +256,16 @@ private extension SiteCreationDomainsTableViewController { return } - // Add noResultsVC to the tableView. + noResultsViewController.view.frame = cell.frame + cell.contentView.addSubview(noResultsViewController.view) + addChildViewController(noResultsViewController) - tableView.addSubview(noResultsViewController.view) noResultsViewController.didMove(toParentViewController: self) } func removeNoResultsFromView() { + noSuggestions = false + tableView.reloadSections(IndexSet(integer: Sections.suggestions.rawValue), with: .automatic) noResultsViewController?.view.removeFromSuperview() noResultsViewController?.removeFromParentViewController() } @@ -239,16 +278,6 @@ private extension SiteCreationDomainsTableViewController { let subtitle = NSLocalizedString("Enter another site name in the search box above.", comment: "Secondary message shown when there are no domains that match the user entered text.") noResultsViewController?.configure(title: title, buttonTitle: nil, subtitle: subtitle) - - // Calculate the frame for the noResultsVC. - var noResultsFrame = tableView.bounds - let titleCellRect = tableView.rect(forSection: Sections.titleAndDescription.rawValue) - let searchCellRect = tableView.rect(forSection: Sections.searchField.rawValue) - let noResultsOffset = searchCellRect.height + titleCellRect.height - - noResultsFrame.size.height -= noResultsOffset - noResultsFrame.origin.y += noResultsOffset - noResultsViewController?.view.frame = noResultsFrame } } diff --git a/WordPress/Classes/ViewRelated/Views/NoResults.storyboard b/WordPress/Classes/ViewRelated/Views/NoResults.storyboard index 38f4487f0b9e..8c2916f69bb9 100644 --- a/WordPress/Classes/ViewRelated/Views/NoResults.storyboard +++ b/WordPress/Classes/ViewRelated/Views/NoResults.storyboard @@ -19,7 +19,7 @@ - + From d347b9a22403ee1af5e38c70d62f45bb402c36e9 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 14 Feb 2018 16:39:13 -0700 Subject: [PATCH 06/15] Misc tweaks. --- .../NUX/SiteCreationDomainsTableViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index d3798c1290b7..7787fd603eca 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -175,7 +175,7 @@ extension SiteCreationDomainsTableViewController { let searchFieldRect = tableView.rect(forSection: Sections.searchField.rawValue) let searchFieldBottom = searchFieldRect.origin.y + searchFieldRect.height let screenBottom = UIScreen.main.bounds.height - return screenBottom - searchFieldBottom - 80 + return screenBottom - searchFieldBottom - 60 } return super.tableView(tableView, heightForRowAt: indexPath) @@ -275,7 +275,7 @@ private extension SiteCreationDomainsTableViewController { noResultsViewController = noResultsSB.instantiateViewController(withIdentifier: "NoResults") as? NoResultsViewController let title = NSLocalizedString("No available site addresses with that name, maybe try another one?", comment: "Primary message shown when there are no domains that match the user entered text.") - let subtitle = NSLocalizedString("Enter another site name in the search box above.", comment: "Secondary message shown when there are no domains that match the user entered text.") + let subtitle = NSLocalizedString("Enter another site name in the search field above.", comment: "Secondary message shown when there are no domains that match the user entered text.") noResultsViewController?.configure(title: title, buttonTitle: nil, subtitle: subtitle) } From 460f2b74586c8e30e5ce8aedad92d6f20e7a40ee Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Fri, 16 Feb 2018 10:38:41 -0700 Subject: [PATCH 07/15] Updating messaging. --- .../NUX/SiteCreationDomainsTableViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index 7787fd603eca..1ea7b73dddc4 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -274,8 +274,8 @@ private extension SiteCreationDomainsTableViewController { let noResultsSB = UIStoryboard(name: "NoResults", bundle: nil) noResultsViewController = noResultsSB.instantiateViewController(withIdentifier: "NoResults") as? NoResultsViewController - let title = NSLocalizedString("No available site addresses with that name, maybe try another one?", comment: "Primary message shown when there are no domains that match the user entered text.") - let subtitle = NSLocalizedString("Enter another site name in the search field above.", comment: "Secondary message shown when there are no domains that match the user entered text.") + let title = NSLocalizedString("We couldn't find any available address with the words you entered - let's try again.", comment: "Primary message shown when there are no domains that match the user entered text.") + let subtitle = NSLocalizedString("Enter different words above and we'll look for an address that matches it.", comment: "Secondary message shown when there are no domains that match the user entered text.") noResultsViewController?.configure(title: title, buttonTitle: nil, subtitle: subtitle) } From 6be6054dc9dd1d3ca42a29b3eef8ffa542514c3d Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Fri, 16 Feb 2018 12:11:51 -0700 Subject: [PATCH 08/15] Updating search placeholder text. --- .../ViewRelated/NUX/SiteCreationDomainSearchTableViewCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainSearchTableViewCell.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainSearchTableViewCell.swift index 238b7ba8a267..3a1d69793026 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainSearchTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainSearchTableViewCell.swift @@ -29,7 +29,7 @@ class SiteCreationDomainSearchTableViewCell: UITableViewCell { textField?.text = placeholder textField?.delegate = self textField?.contentInsets = Constants.textInsetsWithIcon - textField?.placeholder = NSLocalizedString("Type to get more suggestions", comment: "Placeholder text for domain search during site creation.") + textField?.placeholder = NSLocalizedString("Type a keyword for more ideas", comment: "Placeholder text for domain search during site creation.") textField?.accessibilityIdentifier = "Domain search field" if let searchIcon = textField?.leftViewImage { From f626422c4193b553a6bbb110377192f880d46754 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 20 Mar 2018 17:21:59 -0600 Subject: [PATCH 09/15] Changing definition of `noSuggestions` making it calculated. Removing setting `noSuggestions` everywhere. --- .../NUX/SiteCreationDomainsTableViewController.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index 6bab2ec19f0d..119161b5b069 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -19,7 +19,9 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { private var selectedCell: UITableViewCell? // API returned no domain suggestions. - private var noSuggestions: Bool = false + private var noSuggestions: Bool { + return siteTitleSuggestions.count == 0 && searchSuggestions.count == 0 + } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) @@ -83,14 +85,12 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { self?.isSearching = false SVProgressHUD.dismiss() self?.tableView.separatorStyle = .singleLine - self?.noSuggestions = false addSuggestions(suggestions) }) { [weak self] (error) in DDLogError("Error getting Domain Suggestions: \(error.localizedDescription)") self?.isSearching = false SVProgressHUD.dismiss() self?.tableView.separatorStyle = .none - self?.noSuggestions = true // reload to display the no results view. self?.tableView.reloadSections(IndexSet(integer: Sections.suggestions.rawValue), with: .automatic) } @@ -265,7 +265,6 @@ private extension SiteCreationDomainsTableViewController { } func removeNoResultsFromView() { - noSuggestions = false tableView.reloadSections(IndexSet(integer: Sections.suggestions.rawValue), with: .automatic) noResultsViewController?.view.removeFromSuperview() noResultsViewController?.removeFromParentViewController() From 0ad4950ee0bcef41586b6dd3490e3758152a4f3d Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 20 Mar 2018 17:24:23 -0600 Subject: [PATCH 10/15] Add 0 suggestions instead of reloading the suggestions section. --- .../NUX/SiteCreationDomainsTableViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index 119161b5b069..f7037126ccba 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -91,8 +91,8 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { self?.isSearching = false SVProgressHUD.dismiss() self?.tableView.separatorStyle = .none - // reload to display the no results view. - self?.tableView.reloadSections(IndexSet(integer: Sections.suggestions.rawValue), with: .automatic) + // Add no suggestions to display the no results view. + addSuggestions([]) } } From f6ef827a92b7da7cd7250e299dd0af16a7515030 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 20 Mar 2018 17:29:55 -0600 Subject: [PATCH 11/15] Adding an enum for the NoResultsView padding. --- ...teCreationDomainsTableViewController.swift | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index f7037126ccba..fa317588d5e3 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -8,6 +8,8 @@ protocol SiteCreationDomainsTableViewControllerDelegate { class SiteCreationDomainsTableViewController: NUXTableViewController { + // MARK: - Properties + open var siteName: String? open var delegate: SiteCreationDomainsTableViewControllerDelegate? @@ -23,6 +25,12 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { return siteTitleSuggestions.count == 0 && searchSuggestions.count == 0 } + fileprivate enum ViewPadding: CGFloat { + case noResultsView = 60 + } + + // MARK: - Init + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } @@ -33,6 +41,8 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { setupBackgroundTapGestureRecognizer() } + // MARK: - View + override func viewDidLoad() { super.viewDidLoad() @@ -110,7 +120,7 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { } } -// MARK: UITableViewDataSource +// MARK: - UITableViewDataSource extension SiteCreationDomainsTableViewController { fileprivate enum Sections: Int { @@ -176,7 +186,7 @@ extension SiteCreationDomainsTableViewController { let searchFieldRect = tableView.rect(forSection: Sections.searchField.rawValue) let searchFieldBottom = searchFieldRect.origin.y + searchFieldRect.height let screenBottom = UIScreen.main.bounds.height - return screenBottom - searchFieldBottom - 60 + return screenBottom - searchFieldBottom - ViewPadding.noResultsView.rawValue } return super.tableView(tableView, heightForRowAt: indexPath) @@ -244,7 +254,7 @@ extension SiteCreationDomainsTableViewController { } } -// MARK: NoResultsViewController Extension +// MARK: - NoResultsViewController Extension private extension SiteCreationDomainsTableViewController { @@ -282,7 +292,7 @@ private extension SiteCreationDomainsTableViewController { } -// MARK: UITableViewDelegate +// MARK: - UITableViewDelegate extension SiteCreationDomainsTableViewController { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { @@ -317,7 +327,7 @@ extension SiteCreationDomainsTableViewController { } } -// MARK: SiteCreationDomainSearchTableViewCellDelegate +// MARK: - SiteCreationDomainSearchTableViewCellDelegate extension SiteCreationDomainsTableViewController: SiteCreationDomainSearchTableViewCellDelegate { func startSearch(for searchTerm: String) { From 7f95d0416970c79132acfadf8796f42a12d58c70 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 20 Mar 2018 17:31:36 -0600 Subject: [PATCH 12/15] Resetting `tableView.separatorStyle` when no results view removed. --- .../ViewRelated/NUX/SiteCreationDomainsTableViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index fa317588d5e3..090199fe83f1 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -275,6 +275,7 @@ private extension SiteCreationDomainsTableViewController { } func removeNoResultsFromView() { + tableView.separatorStyle = .singleLine tableView.reloadSections(IndexSet(integer: Sections.suggestions.rawValue), with: .automatic) noResultsViewController?.view.removeFromSuperview() noResultsViewController?.removeFromParentViewController() From 4ef9dc7bb86bddda69e7364f4fddd57a2569b952 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 20 Mar 2018 18:26:26 -0600 Subject: [PATCH 13/15] =?UTF-8?q?Redacting=20`noSuggestions`=20as=20a=20ca?= =?UTF-8?q?lculated=20value=20as=20the=20NoResultsView=20was=20showing=20w?= =?UTF-8?q?hen=20it=20shouldn=E2=80=99t.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NUX/SiteCreationDomainsTableViewController.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index 090199fe83f1..afab78977054 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -21,9 +21,7 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { private var selectedCell: UITableViewCell? // API returned no domain suggestions. - private var noSuggestions: Bool { - return siteTitleSuggestions.count == 0 && searchSuggestions.count == 0 - } + private var noSuggestions: Bool = false fileprivate enum ViewPadding: CGFloat { case noResultsView = 60 @@ -93,12 +91,14 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { service.getDomainSuggestions(base: searchTerm, success: { [weak self] (suggestions) in self?.isSearching = false + self?.noSuggestions = false SVProgressHUD.dismiss() self?.tableView.separatorStyle = .singleLine addSuggestions(suggestions) }) { [weak self] (error) in DDLogError("Error getting Domain Suggestions: \(error.localizedDescription)") self?.isSearching = false + self?.noSuggestions = true SVProgressHUD.dismiss() self?.tableView.separatorStyle = .none // Add no suggestions to display the no results view. @@ -154,7 +154,6 @@ extension SiteCreationDomainsTableViewController { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: UITableViewCell - switch indexPath.section { case Sections.titleAndDescription.rawValue: cell = titleAndDescriptionCell() @@ -275,6 +274,7 @@ private extension SiteCreationDomainsTableViewController { } func removeNoResultsFromView() { + noSuggestions = false tableView.separatorStyle = .singleLine tableView.reloadSections(IndexSet(integer: Sections.suggestions.rawValue), with: .automatic) noResultsViewController?.view.removeFromSuperview() From 97d1d0240a8b06eb2f5ee32c0fdaea528dd309ef Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 20 Mar 2018 18:57:20 -0600 Subject: [PATCH 14/15] Dismiss the keyboard after searching. --- .../NUX/SiteCreationDomainsTableViewController.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index afab78977054..c3f58f052286 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -94,6 +94,8 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { self?.noSuggestions = false SVProgressHUD.dismiss() self?.tableView.separatorStyle = .singleLine + // Dismiss the keyboard so the full results list can be seen. + self?.view.endEditing(true) addSuggestions(suggestions) }) { [weak self] (error) in DDLogError("Error getting Domain Suggestions: \(error.localizedDescription)") @@ -101,6 +103,8 @@ class SiteCreationDomainsTableViewController: NUXTableViewController { self?.noSuggestions = true SVProgressHUD.dismiss() self?.tableView.separatorStyle = .none + // Dismiss the keyboard so the full no results view can be seen. + self?.view.endEditing(true) // Add no suggestions to display the no results view. addSuggestions([]) } From 0f9a105a110c3141653842080f979733352eddc7 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 21 Mar 2018 10:14:54 -0600 Subject: [PATCH 15/15] Removing unnecessary call to set `tableView.separatorStyle`. --- .../ViewRelated/NUX/SiteCreationDomainsTableViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift index b59766cea0ee..bfb70ffe0049 100644 --- a/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/SiteCreationDomainsTableViewController.swift @@ -279,7 +279,6 @@ private extension SiteCreationDomainsTableViewController { func removeNoResultsFromView() { noSuggestions = false - tableView.separatorStyle = .singleLine tableView.reloadSections(IndexSet(integer: Sections.suggestions.rawValue), with: .automatic) noResultsViewController?.view.removeFromSuperview() noResultsViewController?.removeFromParentViewController()