Skip to content

Commit

Permalink
Improve note editor save callback for new notes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed May 8, 2024
1 parent c713e19 commit 2101643
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Zotero/Scenes/Detail/DetailCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,9 @@ extension DetailCoordinator: DetailNoteEditorCoordinatorDelegate {
DDLogInfo("DetailCoordinator: show note creation")
amendedSaveCallback = { [weak self] key, result in
switch result {
case .success(let note):
case .success((let note, let isCreated)):
// If indeed a new note is created inform open items controller about it.
if let self, let openItemsController = controllers.userControllers?.openItemsController {
if isCreated, let self, let openItemsController = controllers.userControllers?.openItemsController {
openItemsController.open(.note(libraryId: library.identifier, key: note.key), for: sessionIdentifier)
openItemsController.setOpenItemsUserActivity(from: navigationController, libraryId: library.identifier, title: note.title)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ struct ItemDetailActionHandler: ViewModelActionHandler, BackgroundDbProcessingAc
}
}
switch result {
case .success(let note):
case .success((let note, _)):
update(viewModel: viewModel) { state in
if let oldIndex {
state.notes[oldIndex] = note
Expand Down
2 changes: 1 addition & 1 deletion Zotero/Scenes/General/NoteEditorCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protocol NoteEditorCoordinatorDelegate: AnyObject {
}

final class NoteEditorCoordinator: NSObject, Coordinator {
typealias SaveResult = Result<Note, Error>
typealias SaveResult = Result<(note: Note, isCreated: Bool), Error>
typealias SaveCallback = (_ key: String?, _ result: SaveResult) -> Void

weak var parentCoordinator: Coordinator?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct NoteEditorActionHandler: ViewModelActionHandler, BackgroundDbProcessingAc
update(viewModel: viewModel) { state in
state.kind = .edit(key: note.key)
}
saveCallback(note.key, .success(note))
saveCallback(note.key, .success((note: note, isCreated: true)))

case .failure(let error):
DDLogError("NoteEditorActionHandler: can't create item note: \(error)")
Expand All @@ -119,7 +119,7 @@ struct NoteEditorActionHandler: ViewModelActionHandler, BackgroundDbProcessingAc
DDLogError("NoteEditorActionHandler: can't update existing note: \(error)")
saveCallback(key, .failure(error))
} else {
saveCallback(key, .success(note))
saveCallback(key, .success((note: note, isCreated: false)))
}
}
}
Expand Down

0 comments on commit 2101643

Please sign in to comment.