Skip to content

Add homepage / posts page setting functionality - #14209

Merged
frosty merged 9 commits into
developfrom
feature/homepage-settings-page-select
May 30, 2020
Merged

Add homepage / posts page setting functionality#14209
frosty merged 9 commits into
developfrom
feature/homepage-settings-page-select

Conversation

@bjtitus

@bjtitus bjtitus commented May 28, 2020

Copy link
Copy Markdown
Contributor

Ref #14167

This reuses the SelectPostViewController for selecting a post for the Homepage Settings functionality.

Note that this design is slightly different than the original issue. I wanted to reuse the same view controller we use for selecting a post for links and this view controller also includes search, which seems like a nice feature addition. If the grouped table style is necessary, I can adjust that style for this particular presentation.

Testing

All scenarios from #14169 should continue to work. The following represent several new scenarios to test:

Scenario 5

  • With a Jetpack or WordPress.com site, visit the Site Settings screen.
  • Tap Static Homepage if not already selected
  • Tap Homepage and select a page from the list
  • Ensure that the label on the Homepage row matches the page you selected
  • Tap back out to Settings and ensure that the Homepage Settings row now reads Static Homepage
  • On the web, visit the Customizer for your test site, and check that the Homepage Settings section shows the selected Homepage.

Scenario 6

  • On the web, visit the Customizer for your test site, and find the Homepage Settings section there. Change it to Static Homepage, and choose both a Homepage and a Posts Page. Don't forget to save your changes!
  • In the app, refresh your sites list and then navigate into your test site
  • Go to Site Settings, and check that the Homepage Settings row says "Static Homepage"
  • Check that the Homepage and Posts Page that you selected are shown in the Choose Pages section
  • Change the Homepage value to a different page
  • Reload the customizer on the web for the site, and check your new Homepage shows the newly selected page

Scenario 7

  • Build and run on your device
  • Navigate into Site Settings for your site, and tap Homepage Settings
  • Put your device into airplane mode
  • Try changing the Homepage value to a new page. A spinning activity indicator should how in the Homepage cell, the operation should fail (the setting should not change), and a notice should be displayed.

Scenario 8

This is to verify existing functionality which also used SelectPostViewController

  • Visit a post using the Classic Editor (existing Post > ... > "Switch to Classic Editor")
  • Insert a link using the keyboard toolbar
  • Tap "Link to Existing Content"
  • Ensure that selecting a post works and is linked properly.

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@bjtitus bjtitus added this to the 15.0 milestone May 28, 2020
@bjtitus
bjtitus requested a review from frosty May 28, 2020 03:47
@bjtitus bjtitus self-assigned this May 28, 2020
@peril-wordpress-mobile

peril-wordpress-mobile Bot commented May 28, 2020

Copy link
Copy Markdown

You can trigger an installable build for these changes by visiting CircleCI here.

@peril-wordpress-mobile

peril-wordpress-mobile Bot commented May 28, 2020

Copy link
Copy Markdown

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@frosty

frosty commented May 28, 2020

Copy link
Copy Markdown
Contributor

cc @SylvesterWilmott is this slight tweak to the posts / homepage picker okay with you? I think it's nice to have search in there, and a pragmatic way to get this shipped faster :)

@frosty frosty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, and works fine for me when testing it out. I left some small code cleanup suggestions.

One thing missing here from the designs is that ideally a page you've already selected for one of the settings shouldn't show up in the other setting's picker. We could address this in a followup PR if that's easier?

}
}
if post.permaLink == selectedLink {
if isSelectedPost?(post) == true {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could omit the == true here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block is optional here so it needs something like == true or isSelectedPost?(post) ?? false.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, sorry!

homepageRow = ActivityIndicatorRow(title: Strings.homepage, animating: true, action: nil)
} else {
homepageRow = NavigationItemRow(title: Strings.homepage, detail: homepageTitle, action: { _ in
self.pushPageSelection(selectedPostID: self.blog?.homepagePageID) { [weak self] selected in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we extract the contents of this action to another method or something to make it a little clearer to follow? Also, should this self be weak?

}

// MARK: - Updating Settings
open override func viewWillAppear(_ animated: Bool) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this up below viewDidLoad?

let viewController = SelectPostViewController(blog: blog,
isSelectedPost: { $0.postID?.intValue == selectedPostID },
showsPostType: false,
entityName: Page.entityName()) { (post) in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the trailing closure name? I think it might just be a little easier to understand what the closure's for.

if let page = post as? Page {
completion(page)
}
self.navigationController?.popViewController(animated: true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weak self?

@bjtitus

bjtitus commented May 28, 2020

Copy link
Copy Markdown
Contributor Author

@frosty I totally missed that! It should be easy enough to add to this.

@frosty frosty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Scenarios 5, 6, 7, and 8 are working as expected for me. I did find one issue related to bad / slow connectivity. It's easiest to see if you use Network Link Conditioner set to very bad network:

  • Go to the Homepage Settings screen, with it set to Static Homepage
  • Tap one of the rows and choose a page
  • While the loading indicator is still spinning for that row, go and select a page for the other row
  • Your second selection won't 'stick' – the cell will still show the original page name while the first one continues loading.

}

func posts(for blog: Blog, containsTitle title: String, entityName: String? = nil) -> NSFetchedResultsController<AbstractPost> {
func posts(for blog: Blog, containsTitle title: String, entityName: String? = nil, excludingPostIDs excludedPostIDs: [Int] = []) -> NSFetchedResultsController<AbstractPost> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to switch around the order here so that containsTitle and excludingPostIDs are grouped together. So entityName should either go second or last. What do you think?

if !title.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty {
compoundPredicates.append(NSPredicate(format: "postTitle contains[c] %@", title))
}
compoundPredicates.append(NSPredicate(format: "NOT (postID IN %@)", excludedPostIDs))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we only add this if excludedPostIDs contains some items?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, I figured it doesn't matter much if the array is empty but it's probably a theoretical performance improvement.

@SylvesterWilmott

Copy link
Copy Markdown

Looks great! Thanks @bjtitus

@bjtitus

bjtitus commented May 29, 2020

Copy link
Copy Markdown
Contributor Author

@frosty Fixed that bad network issue by just disabling selection on the table view. If that seems like a bad idea, I also considered allowing selection but immediately deselecting the cell and not performing the action (just so there's some intractability left for the user). I'm not quite sure which one seems less confusing – let me know what you think.

@bjtitus
bjtitus requested a review from frosty May 29, 2020 19:59

@frosty frosty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current solution works fine – thanks for making that change! I've just added a code-level comment about a bug I spotted, and the last thing that I can see is that the activity indicator in the rows is currently super hard to see in dark mode. I'm surprised it doesn't change automatically – perhaps we need to tint it to a system color.

return ActivityIndicatorRow(title: title, animating: true, action: nil)
} else {
return NavigationItemRow(title: title, detail: detail, action: { [weak self] _ in
self?.showPageSelection(selectedPostID: self?.blog?.homepagePageID, hiddenPostID: self?.blog?.homepagePostsPageID, change: changeForPost)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're always passing homepageID for the selected post, and postPageID for the hidden post ID here, so the picker shown the same content no matter which row you're tapping into. These should be switched for the Posts row.

@bjtitus
bjtitus requested a review from frosty May 30, 2020 14:41

@frosty frosty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Activity indicator now visible in dark mode, and the correct page is hidden for each of posts / pages.

I'll go ahead and merge this ahead of the freeze on Monday.

@frosty
frosty merged commit 9f25996 into develop May 30, 2020
@bjtitus
bjtitus deleted the feature/homepage-settings-page-select branch June 10, 2020 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants