Skip to content

Commit a591197

Browse files
authored
Extract the GBK editor parts to a super class (#25166)
* Create a new `PostGBKEditorViewController` super class * Remove an unused initialiser * Remove unused parameters * Move initialiser to the super class * Add empty `EditorViewControllerDelegate` implementation * Add empty `PostEditorNavigationBarManagerDelegate` implementation * Add override keywords * Move `PostEditorNavigationBarManagerDelegate` implementation * Add override keywords * Remove private keyword * Remove empty override functions * Move `didUpdateHistoryState` delegate function to the super class * Move `didLogException` delegate function to the super class * Move modal dialog delegate functions to the super class * Move undo redo delegate functions to the super class * Move keyboard observers to the super class * Call setupKeyboardObservers in the super class * Move showSuggestions function to the super class * Move `didTriggerAutocompleter` to the super class * Move setting background * Move deinit to the super class * Move `setupEditorView()` to the super class * Move configureNavigationBar to the super class * Allow overriding `makeMoreMenu` * Move `loadAuthenticationCookiesAsync` to the super class * Move `prefetchSuggestionsIfNeeded` to the super class * Move `refreshInterface` to the super class * Move the super class to its own file * Move extension functions out to its own file * Add missing imports * Add an extension: `EditorLocalizableString.localized`
1 parent 22e143c commit a591197

3 files changed

Lines changed: 538 additions & 455 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import Foundation
2+
import GutenbergKit
3+
import Pulse
4+
import Support
5+
6+
extension GutenbergKit.EditorViewControllerDelegate {
7+
func editor(_ viewController: GutenbergKit.EditorViewController, didLogNetworkRequest request: GutenbergKit.RecordedNetworkRequest) {
8+
guard ExtensiveLogging.enabled, let url = URL(string: request.url) else {
9+
return
10+
}
11+
12+
var urlRequest = URLRequest(url: url)
13+
urlRequest.httpMethod = request.method
14+
urlRequest.allHTTPHeaderFields = request.requestHeaders
15+
urlRequest.httpBody = request.requestBody?.data(using: .utf8)
16+
17+
let httpResponse = HTTPURLResponse(
18+
url: url,
19+
statusCode: request.status,
20+
httpVersion: nil,
21+
headerFields: request.responseHeaders
22+
)
23+
24+
LoggerStore.shared.storeRequest(
25+
urlRequest,
26+
response: httpResponse,
27+
error: nil,
28+
data: request.responseBody?.data(using: .utf8)
29+
)
30+
}
31+
}
32+
33+
private func getLocalizedString(for value: GutenbergKit.EditorLocalizableString) -> String {
34+
switch value {
35+
case .showMore: NSLocalizedString("editor.blockInserter.showMore", value: "Show More", comment: "Button title to expand and show more blocks")
36+
case .showLess: NSLocalizedString("editor.blockInserter.showLess", value: "Show Less", comment: "Button title to collapse and show fewer blocks")
37+
case .search: NSLocalizedString("editor.blockInserter.search", value: "Search", comment: "Placeholder text for block search field")
38+
case .insertBlock: NSLocalizedString("editor.blockInserter.insertBlock", value: "Insert Block", comment: "Context menu action to insert a block")
39+
case .failedToInsertMedia: NSLocalizedString("editor.media.failedToInsert", value: "Failed to insert media", comment: "Error message when media insertion fails")
40+
case .patterns: NSLocalizedString("editor.patterns.title", value: "Patterns", comment: "Navigation title for patterns view")
41+
case .noPatternsFound: NSLocalizedString("editor.patterns.noPatternsFound", value: "No Patterns Found", comment: "Title shown when no patterns match the search")
42+
case .insertPattern: NSLocalizedString("editor.patterns.insertPattern", value: "Insert Pattern", comment: "Context menu action to insert a pattern")
43+
case .patternsCategoryUncategorized: NSLocalizedString("editor.patterns.uncategorized", value: "Uncategorized", comment: "Category name for patterns without a category")
44+
case .patternsCategoryAll: NSLocalizedString("editor.patterns.all", value: "All", comment: "Category name for section showing all patterns")
45+
case .loadingEditor: NSLocalizedString("editor.loading.title", value: "Loading Editor", comment: "Text shown while the editor is loading")
46+
case .editorError: NSLocalizedString("editor.error.title", value: "Editor Error", comment: "Title shown when the editor encounters an error")
47+
}
48+
}
49+
50+
extension EditorLocalizableString {
51+
var localized: String {
52+
getLocalizedString(for: self)
53+
}
54+
}

0 commit comments

Comments
 (0)