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

Update site title when it changes from site settings #18543

Merged
merged 4 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
19.9
-----

[*] Site Settings: we fixed an issue that prevented the site title to be updated when it changed in Site Settings [#18543]

19.8
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ final class SitePickerViewController: UIViewController {
super.viewDidLoad()
setupHeaderView()
startObservingQuickStart()
startObservingTitleChanges()
}

deinit {
Expand All @@ -57,6 +58,15 @@ final class SitePickerViewController: UIViewController {
view.addSubview(blogDetailHeaderView)
view.pinSubviewToAllEdges(blogDetailHeaderView)
}

private func startObservingTitleChanges() {
NotificationCenter.default.addObserver(forName: NSNotification.Name.WPBlogUpdated,
object: nil,
queue: .main) { [weak self] _ in

self?.updateTitles()
}
}
}

// MARK: - BlogDetailHeaderViewDelegate
Expand Down Expand Up @@ -191,22 +201,14 @@ extension SitePickerViewController {
silentlyForBlog: blog)

blogService.updateSettings(for: blog, success: { [weak self] in
NotificationCenter.default.post(name: NSNotification.Name.WPBlogUpdated, object: nil)

let notice = Notice(title: title,
message: SiteTitleStrings.titleChangeSuccessfulMessage,
feedbackType: .success)
ActionDispatcher.global.dispatch(NoticeAction.post(notice))

self?.blogDetailHeaderView.setTitleLoading(false)
self?.blogDetailHeaderView.refreshSiteTitle()

guard let parent = self?.parent as? MySiteViewController else {
return
}

parent.updateNavigationTitle(for: blog)

NotificationCenter.default.post(name: NSNotification.Name.WPBlogUpdated, object: nil)
}, failure: { [weak self] error in
self?.blog.settings?.name = existingBlogTitle
self?.blogDetailHeaderView.setTitleLoading(false)
Expand All @@ -219,6 +221,16 @@ extension SitePickerViewController {
})
}

/// Updates site title and navigation bar title
private func updateTitles() {
blogDetailHeaderView.refreshSiteTitle()

guard let parent = parent as? MySiteViewController else {
return
}
parent.updateNavigationTitle(for: blog)
}

private func showViewSite() {
WPAppAnalytics.track(.openedViewSite, withProperties: [WPAppAnalyticsKeyTapSource: "link"], with: blog)

Expand Down