Skip to content

Commit 349e4f6

Browse files
Merge release/26.5.2 into trunk (#25071)
* Bump version number * Fix CMM-1065: Find existing tag before creating a new one (#25061) * Fix CMM-1065: Find existing tag before creating a new one The issue was introduced in #24955. * Replace original input with the actual tag * Invert a boolean check of most recently used tags first (#25065) The issue was introduced in #24955. I missed a `!` in the refactor. * Fix an issue where the app fails to remove tags from posts (#25067) This is a regression introduced in #24964. We should not check if values are an empty list in the "update" parameter types. * Move finding existing tag code (#25068) Moving the code to the view model, so that it can cover tags and custom taxonomy terms, which are two seperate `TagsServiceProtocol` implementations. * Clear the tag input field after tapping the Enter key (#25069) We already have code that clears the text field in the `addTag` function. However, during testing, I noticed it does not always work. The new change here makes sure the `UITextField` is cleared, because we are calling the UIKit directly, instead of relying on SwiftUI to pass the `text` changes to UIKit. * Manually bump version number --------- Co-authored-by: Tony Li <[email protected]>
1 parent fab218e commit 349e4f6

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

Modules/Sources/WordPressKit/RemotePostParameters.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,10 @@ struct RemotePostUpdateParametersWordPressComEncoder: Encodable {
350350

351351
// Terms (including tags)
352352
var terms = [String: [String]]()
353-
if let tags = parameters.tags, !tags.isEmpty {
353+
if let tags = parameters.tags {
354354
terms[RemotePostWordPressComCodingKeys.postTags] = tags
355355
}
356-
if let otherTerms = parameters.otherTerms, !otherTerms.isEmpty {
356+
if let otherTerms = parameters.otherTerms {
357357
terms.merge(otherTerms) { old, _ in old }
358358
}
359359
if !terms.isEmpty {
@@ -476,10 +476,10 @@ struct RemotePostUpdateParametersXMLRPCEncoder: Encodable {
476476

477477
// Terms (including tags)
478478
var terms = [String: [String]]()
479-
if let tags = parameters.tags, !tags.isEmpty {
479+
if let tags = parameters.tags {
480480
terms[RemotePostXMLRPCCodingKeys.taxonomyTag] = tags
481481
}
482-
if let otherTerms = parameters.otherTerms, !otherTerms.isEmpty {
482+
if let otherTerms = parameters.otherTerms {
483483
terms.merge(otherTerms) { old, _ in old }
484484
}
485485
if !terms.isEmpty {

WordPress/Classes/ViewRelated/Post/PostSettings/Views/PostTagsView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ private struct AddTagsTextField: UIViewRepresentable {
328328

329329
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
330330
view.onSubmit()
331+
self.view.text = ""
332+
textField.text = ""
331333
return false
332334
}
333335
}

WordPress/Classes/ViewRelated/Tags/TagsViewModel.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class TagsViewModel: ObservableObject {
9090
let page = pageIndex ?? 0
9191
let remoteTags = try await self.tagsService.getTags(
9292
page: page,
93-
recentlyUsed: self.isBrowseMode
93+
recentlyUsed: !self.isBrowseMode
9494
)
9595

9696
let hasMore = remoteTags.count == 100
@@ -159,7 +159,21 @@ class TagsViewModel: ObservableObject {
159159
// Create a new tag in the background, which is consistent with the web editor.
160160
Task {
161161
do {
162-
_ = try await tagsService.createTag(name: name, description: "")
162+
let newTag: AnyTermWithViewContext
163+
if let existing = try await tagsService.searchTags(with: name)
164+
.first(where: { $0.name.compare(name, options: .caseInsensitive) == .orderedSame }) {
165+
newTag = existing
166+
} else {
167+
newTag = try await tagsService.createTag(name: name, description: "")
168+
}
169+
170+
// The original input `name` was used as a temporary tag before sending the API request.
171+
// Replace it with the actual tag returned by the API.
172+
if newTag.name != name, let index = selectedTags.firstIndex(of: name) {
173+
selectedTagsSet.remove(lowercasedName)
174+
selectedTagsSet.insert(newTag.name.lowercased())
175+
selectedTags[index] = newTag.name
176+
}
163177
} catch {
164178
removeSelectedTag(name)
165179
}

config/Version.public.xcconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION_LONG = 26.5.1.0
2-
VERSION_SHORT = 26.5.1
1+
VERSION_LONG = 26.5.2.1
2+
VERSION_SHORT = 26.5.2

0 commit comments

Comments
 (0)