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

My Site Dashboard: Add site picker to MySite screen only once #17814

Merged
merged 5 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ class MySiteViewController: UIViewController, NoResultsViewHost {
return
}

showSitePicker(for: newBlog)
addSitePickerIfNeeded(for: newBlog)
showBlogDetails(for: newBlog)
}

get {
return blogDetailsViewController?.blog
guard FeatureFlag.mySiteDashboard.enabled else {
return blogDetailsViewController?.blog
}

return sitePickerViewController?.blog
}
}

Expand All @@ -90,6 +94,8 @@ class MySiteViewController: UIViewController, NoResultsViewHost {

private let blogDashboardViewController = BlogDashboardViewController()

private(set) var sitePickerViewController: SitePickerViewController?

/// When we display a no results view, we'll do so in a scrollview so that
/// we can allow pull to refresh to sync the user's list of sites.
///
Expand Down Expand Up @@ -144,24 +150,6 @@ class MySiteViewController: UIViewController, NoResultsViewHost {
NotificationCenter.default.addObserver(self, selector: #selector(showAddSelfHostedSite), name: .addSelfHosted, object: nil)
}

private func showSitePicker(for blog: Blog) {
guard FeatureFlag.mySiteDashboard.enabled else {
return
}

let sitePickerViewController = SitePickerViewController(blog: blog, meScenePresenter: meScenePresenter)

sitePickerViewController.onBlogSwitched = { [weak self] in
self?.blogDetailsViewController?.showInitialDetailsForBlog()
self?.blogDetailsViewController?.tableView.reloadData()
self?.blogDetailsViewController?.preloadMetadata()
}

addChild(sitePickerViewController)
stackView.insertArrangedSubview(sitePickerViewController.view, at: 0)
sitePickerViewController.didMove(toParent: self)
}

private func setupSegmentedControl() {
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: we shouldn't show the segmented control for self-hosted sites. Not sure if this is planned for a future task, but it might be good to add it as a subtask so we won't forget about it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created an issue! #17825

segmentedControlContainerView.isHidden = !FeatureFlag.mySiteDashboard.enabled

Expand All @@ -170,6 +158,8 @@ class MySiteViewController: UIViewController, NoResultsViewHost {
segmentedControl.insertSegment(withTitle: section.title, at: section.rawValue, animated: false)
}
segmentedControl.selectedSegmentIndex = 0

segmentedControl.addTarget(self, action: #selector(segmentedControlValueChanged(_:)), for: .valueChanged)
}

private func setupView() {
Expand Down Expand Up @@ -283,7 +273,7 @@ class MySiteViewController: UIViewController, NoResultsViewHost {
return
}

showSitePicker(for: mainBlog)
addSitePickerIfNeeded(for: mainBlog)
showBlogDetails(for: mainBlog)
}

Expand All @@ -304,9 +294,9 @@ class MySiteViewController: UIViewController, NoResultsViewHost {
}
}

// MARK: - IBAction
// MARK: - Segmented Control

@IBAction func segmentedControlValueChanged(_ sender: Any) {
@objc private func segmentedControlValueChanged(_ sender: Any) {
guard let blog = blog,
let section = Section(rawValue: segmentedControl.selectedSegmentIndex) else {
return
Expand Down Expand Up @@ -543,6 +533,49 @@ class MySiteViewController: UIViewController, NoResultsViewHost {
return blogDetailsViewController
}

private func addSitePickerIfNeeded(for blog: Blog) {
guard FeatureFlag.mySiteDashboard.enabled else {
return
}

guard sitePickerViewController == nil else {
return
}

let sitePickerViewController = makeSitePickerViewController(for: blog)
self.sitePickerViewController = sitePickerViewController

addChild(sitePickerViewController)
stackView.insertArrangedSubview(sitePickerViewController.view, at: 0)
sitePickerViewController.didMove(toParent: self)
}

private func makeSitePickerViewController(for blog: Blog) -> SitePickerViewController {
let sitePickerViewController = SitePickerViewController(blog: blog, meScenePresenter: meScenePresenter)

sitePickerViewController.onBlogSwitched = { [weak self] blog in
self?.updateChildViewController(for: blog)
}

return sitePickerViewController
}

private func updateChildViewController(for blog: Blog) {
guard let section = Section(rawValue: segmentedControl.selectedSegmentIndex) else {
return
}

switch section {
case .siteMenu:
blogDetailsViewController?.blog = blog
blogDetailsViewController?.tableView.reloadData()
blogDetailsViewController?.preloadMetadata()
case .dashboard:
// TODO: Update blog dashboard vc
break
}
}

func presentCreateSheet() {
blogDetailsViewController?.createButtonCoordinator?.showCreateSheet()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class SitePickerViewController: UIViewController {

var siteIconPresenter: SiteIconPickerPresenter?
var siteIconPickerPresenter: SiteIconPickerPresenter?
var onBlogSwitched: (() -> Void)?
var onBlogSwitched: ((Blog) -> Void)?

let meScenePresenter: ScenePresenter
let blogService: BlogService
Expand Down Expand Up @@ -134,14 +134,9 @@ extension SitePickerViewController: BlogDetailHeaderViewDelegate {
extension SitePickerViewController {

private func switchToBlog(_ blog: Blog) {
guard let parent = parent as? MySiteViewController else {
return
}

self.blog = blog
parent.blog = blog
blogDetailHeaderView.blog = blog
onBlogSwitched?()
onBlogSwitched?(blog)
}

private func showSiteTitleSettings() {
Expand Down