Skip to content

Commit

Permalink
Rename showPostEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Sep 18, 2024
1 parent a03a068 commit 034b92d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 53 deletions.
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 {
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

0 comments on commit 034b92d

Please sign in to comment.