Skip to content

Commit

Permalink
Properly close Note Editor when switching current open item
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed May 7, 2024
1 parent edc63ec commit c713e19
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions Zotero/Scenes/General/Views/NoteEditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ final class NoteEditorViewController: UIViewController {
case .done:
let done = UIBarButtonItem(title: L10n.done, style: .done, target: nil, action: nil)
done.rx.tap
.subscribe(with: self, onNext: { `self`, _ in
.subscribe(onNext: { [weak self] _ in
guard let self else { return }
forceSaveIfNeeded()
self.navigationController?.presentingViewController?.dismiss(animated: true, completion: nil)
navigationController?.presentingViewController?.dismiss(animated: true, completion: nil)
})
.disposed(by: disposeBag)
item = done
Expand All @@ -110,8 +111,12 @@ final class NoteEditorViewController: UIViewController {
self?.coordinatorDelegate
},
completion: { [weak self] changedCurrentItem, openItemsChanged in
guard let self, !changedCurrentItem && openItemsChanged else { return }
openItemsController.setOpenItemsUserActivity(from: self, libraryId: viewModel.state.library.identifier, title: viewModel.state.title?.title)
guard let self else { return }
if changedCurrentItem {
forceSaveIfNeeded()
} else if openItemsChanged {
openItemsController.setOpenItemsUserActivity(from: self, libraryId: viewModel.state.library.identifier, title: viewModel.state.title?.title)
}
}
)
let openItemsMenu = UIMenu(title: L10n.Accessibility.Pdf.openItems, options: [.displayInline], children: [deferredOpenItemsMenuElement])
Expand All @@ -128,12 +133,6 @@ final class NoteEditorViewController: UIViewController {
guard let item = navigationItem.rightBarButtonItems?.first(where: { button in RightBarButtonItem(rawValue: button.tag) == .restoreOpenItems }) else { return }
item.image = .openItemsImage(count: count)
}

func forceSaveIfNeeded() {
guard debounceDisposeBag != nil else { return }
debounceDisposeBag = nil
viewModel.process(action: .save)
}
}

func setupWebView() {
Expand Down Expand Up @@ -215,6 +214,12 @@ final class NoteEditorViewController: UIViewController {
self?.viewModel.process(action: .setTags(tags))
})
}

private func forceSaveIfNeeded() {
guard debounceDisposeBag != nil else { return }
debounceDisposeBag = nil
viewModel.process(action: .save)
}
}

extension NoteEditorViewController: WKNavigationDelegate {
Expand Down

0 comments on commit c713e19

Please sign in to comment.