-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use PostRepository to fetch pages in the Menu screen
Fixes #21947
- Loading branch information
1 parent
c2493d9
commit fb3fad8
Showing
8 changed files
with
109 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
WordPress/Classes/ViewRelated/Menus/MenusViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Foundation | ||
|
||
extension MenusViewController { | ||
|
||
/// Fetch all pages from the site. | ||
/// | ||
/// - Returns: A block that can be used to cancel the fetching. | ||
@objc func fetchAllPages(success: @escaping ([MenuItem]) -> Void, failure: @escaping (Error) -> Void) -> () -> Void { | ||
let coreDataStack = ContextManager.shared | ||
let repository = PostRepository(coreDataStack: coreDataStack) | ||
let fetchAllPagesTask = repository.fetchAllPages(statuses: [.publish], in: TaggedManagedObjectID(blog)) | ||
|
||
// Wait for the fetching all pages task to complete and pass its result to the success or failure block. | ||
Task { [weak self] in | ||
let allPages: [TaggedManagedObjectID<Page>] | ||
do { | ||
allPages = try await fetchAllPagesTask.value | ||
} catch { | ||
failure(error) | ||
return | ||
} | ||
|
||
guard let menusService = self?.menusService else { return } | ||
|
||
await menusService.managedObjectContext.perform { | ||
let items = allPages.compactMap { | ||
menusService.createItem(withPageID: $0.objectID, in: menusService.managedObjectContext) | ||
} | ||
success(items) | ||
} | ||
} | ||
|
||
return fetchAllPagesTask.cancel | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters