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

Refactor: Rename showPostTab #23616

Merged
merged 1 commit into from
Sep 25, 2024
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 @@ -24,7 +24,7 @@ open class WP3DTouchShortcutHandler: NSObject {
return true
case ShortcutIdentifier.NewPost.type:
WPAnalytics.track(.shortcutNewPost)
rootViewPresenter.showPostTab(animated: false)
rootViewPresenter.showPostEditor(animated: false)
return true
case ShortcutIdentifier.Stats.type:
WPAnalytics.track(.shortcutStats)
Expand Down
45 changes: 12 additions & 33 deletions WordPress/Classes/System/RootViewPresenter+EditorNavigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,12 @@ extension RootViewPresenter {
return Blog.lastUsedOrFirst(in: context)
}

func showPostTab() {
showPostTab(completion: nil)
}

func showPostTab(completion afterDismiss: (() -> Void)?) {
let context = ContextManager.shared.mainContext
// Ignore taps on the post tab and instead show the modal.
if Blog.count(in: context) > 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There used to be a second branch here that I removed. The method that it called returns if there are no sites, so there is no need to repeat this code.

showPostTab(animated: true, completion: afterDismiss)
}
}

func showPostTab(for blog: Blog) {
let context = ContextManager.shared.mainContext
if Blog.count(in: context) > 0 {
showPostTab(animated: true, blog: blog)
}
}

// TODO: rename
func showPostTab(animated: Bool,
post: Post? = nil,
blog: Blog? = nil,
completion afterDismiss: (() -> Void)? = nil) {
func showPostEditor(
animated: Bool = true,
post: Post? = nil,
blog: Blog? = nil,
completion afterDismiss: (() -> Void)? = nil
) {
if rootViewController.presentedViewController != nil {
rootViewController.dismiss(animated: false)
}
Expand All @@ -56,22 +38,19 @@ extension RootViewPresenter {
rootViewController.present(editor, animated: false)
}

func showPageEditor(forBlog: Blog? = nil) {
showPageEditor(blog: forBlog)
}

/// Show the page tab
/// - Parameter blog: Blog to a add a page to. Uses the current or last blog if not provided
func showPageEditor(blog inBlog: Blog? = nil, title: String? = nil, content: String? = nil, source: String = "create_button") {
/// - parameter blog: Blog to a add a page to. Uses the current or last blog if not provided
func showPageEditor(blog: Blog? = nil, title: String? = nil, content: String? = nil, source: String = "create_button") {

// If we are already showing a view controller, dismiss and show the editor afterward
guard rootViewController.presentedViewController == nil else {
rootViewController.dismiss(animated: true) { [weak self] in
self?.showPageEditor(blog: inBlog, title: title, content: content, source: source)
self?.showPageEditor(blog: blog, title: title, content: content, source: source)
}
return
}
guard let blog = inBlog ?? self.currentOrLastBlog() else { return }
guard let blog = blog ?? self.currentOrLastBlog() else {
return
}
guard content == nil else {
showEditor(blog: blog, title: title, content: content)
return
Expand Down
6 changes: 1 addition & 5 deletions WordPress/Classes/Utility/Universal Links/Route+Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ struct NewPageForSiteRoute: Route {

struct NewPageNavigationAction: NavigationAction {
func perform(_ values: [String: String], source: UIViewController? = nil, router: LinkRouter) {
if let blog = blog(from: values) {
RootViewCoordinator.sharedPresenter.showPageEditor(forBlog: blog)
} else {
RootViewCoordinator.sharedPresenter.showPageEditor()
}
RootViewCoordinator.sharedPresenter.showPageEditor(blog: blog(from: values))
}
}
6 changes: 1 addition & 5 deletions WordPress/Classes/Utility/Universal Links/Routes+Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ struct NewPostForSiteRoute: Route {

struct NewPostNavigationAction: NavigationAction {
func perform(_ values: [String: String], source: UIViewController? = nil, router: LinkRouter) {
if let blog = blog(from: values) {
RootViewCoordinator.sharedPresenter.showPostTab(for: blog)
} else {
RootViewCoordinator.sharedPresenter.showPostTab()
}
RootViewCoordinator.sharedPresenter.showPostEditor(blog: blog(from: values))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ extension MySiteViewController {
@objc func makeCreateButtonCoordinator() -> CreateButtonCoordinator {

let newPage = {
let presenter = RootViewCoordinator.sharedPresenter
let blog = presenter.currentOrLastBlog()
presenter.showPageEditor(forBlog: blog)
RootViewCoordinator.sharedPresenter.showPageEditor()
}

let newPost = {
let presenter = RootViewCoordinator.sharedPresenter
presenter.showPostTab(completion: {})
RootViewCoordinator.sharedPresenter.showPostEditor()
}

let source = "my_site"
Expand Down Expand Up @@ -50,7 +47,7 @@ extension MySiteViewController {
let presenter = RootViewCoordinator.sharedPresenter
let post = blog.createDraftPost()
post.voiceContent = transcription
presenter.showPostTab(animated: true, post: post)
presenter.showPostEditor(post: post)
}
}
let view = VoiceToContentView(viewModel: viewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ extension NotificationsViewController: NoResultsViewControllerDelegate {
RootViewCoordinator.sharedPresenter.showReader()
case .unread:
WPAnalytics.track(.notificationsTappedNewPost, withProperties: properties)
RootViewCoordinator.sharedPresenter.showPostTab()
RootViewCoordinator.sharedPresenter.showPostEditor()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ReaderTabViewController: UIViewController {

let postAction = PostAction(handler: {
let presenter = RootViewCoordinator.sharedPresenter
presenter.showPostTab()
presenter.showPostEditor()
}, source: source)

return CreateButtonCoordinator(self, actions: [postAction], source: source, blog: blog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ extension SiteStatsInsightsTableViewController: SiteStatsInsightsDelegate {
}

func showCreatePost() {
RootViewCoordinator.sharedPresenter.showPostTab { [weak self] in
RootViewCoordinator.sharedPresenter.showPostEditor { [weak self] in
self?.refreshInsights()
}
}
Expand Down