All checks were successful
CI / build-and-deploy (push) Successful in 24s
The list row shows effectiveTags which merges real linkding tagNames with AI-enriched aiTags. If a bookmark has only AI tags, the edit form was appearing empty because it only seeded from tagNames. Now falls back to aiTags when tagNames is empty. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
111 lines
3.7 KiB
Swift
111 lines
3.7 KiB
Swift
import SwiftUI
|
|
|
|
struct EditBookmarkView: View {
|
|
@Bindable var viewModel: BookmarksViewModel
|
|
let bookmark: Bookmark
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@State private var url: String
|
|
@State private var title: String
|
|
@State private var description: String
|
|
@State private var tagsText: String
|
|
@State private var unread: Bool
|
|
@State private var isSaving = false
|
|
@State private var error: String?
|
|
|
|
init(viewModel: BookmarksViewModel, bookmark: Bookmark) {
|
|
self.viewModel = viewModel
|
|
self.bookmark = bookmark
|
|
_url = State(initialValue: bookmark.url)
|
|
_title = State(initialValue: bookmark.title)
|
|
_description = State(initialValue: bookmark.description)
|
|
let effectiveTags = bookmark.tagNames.isEmpty ? (bookmark.aiTags ?? []) : bookmark.tagNames
|
|
_tagsText = State(initialValue: effectiveTags.joined(separator: ", "))
|
|
_unread = State(initialValue: bookmark.unread)
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
Form {
|
|
Section("URL") {
|
|
TextField("https://", text: $url)
|
|
.keyboardType(.URL)
|
|
.textInputAutocapitalization(.never)
|
|
.autocorrectionDisabled()
|
|
}
|
|
|
|
Section("Title") {
|
|
TextField("Optional", text: $title)
|
|
}
|
|
|
|
Section("Description") {
|
|
TextField("Optional", text: $description, axis: .vertical)
|
|
.lineLimit(3...6)
|
|
}
|
|
|
|
Section {
|
|
TextField("comma separated", text: $tagsText)
|
|
.textInputAutocapitalization(.never)
|
|
.autocorrectionDisabled()
|
|
} header: {
|
|
Text("Tags")
|
|
} footer: {
|
|
Text("Separate tags with commas")
|
|
}
|
|
|
|
Section {
|
|
Toggle("Mark as unread", isOn: $unread)
|
|
}
|
|
|
|
if let error {
|
|
Section {
|
|
Text(error)
|
|
.foregroundStyle(.red)
|
|
.font(.footnote)
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle("Edit Bookmark")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button("Cancel") { dismiss() }
|
|
}
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
Button("Save") { save() }
|
|
.disabled(url.trimmingCharacters(in: .whitespaces).isEmpty || isSaving)
|
|
.overlay {
|
|
if isSaving { ProgressView().scaleEffect(0.7) }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func save() {
|
|
let urlString = url.normalizedURL
|
|
guard URL(string: urlString) != nil else {
|
|
error = "Invalid URL"
|
|
return
|
|
}
|
|
let tags = tagsText.parsedTags
|
|
var updated = bookmark
|
|
updated.url = urlString
|
|
updated.title = title.trimmingCharacters(in: .whitespaces)
|
|
updated.description = description.trimmingCharacters(in: .whitespaces)
|
|
updated.tagNames = tags
|
|
updated.unread = unread
|
|
isSaving = true
|
|
error = nil
|
|
Task {
|
|
do {
|
|
try await viewModel.updateBookmark(updated)
|
|
dismiss()
|
|
} catch {
|
|
self.error = error.localizedDescription
|
|
isSaving = false
|
|
}
|
|
}
|
|
}
|
|
}
|