Skip to content

Commit

Permalink
Improve AnnotationEditSaveAction closure
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Aug 14, 2024
1 parent 6433d3f commit 88b9ccf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ struct AnnotationEditState: ViewModelState {
var updateSubsequentLabels: Bool
var changes: Changes

var data: Data {
.init(type: type, isEditable: isEditable, color: color, lineWidth: lineWidth, pageLabel: pageLabel, highlightText: highlightText, highlightFont: highlightFont, fontSize: fontSize)
}

init(data: Data) {
type = data.type
isEditable = data.isEditable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

import RxSwift

typealias AnnotationEditSaveAction = (_ key: String, _ lineWidth: CGFloat, _ fontSize: UInt, _ pageLabel: String, _ updateSubsequentLabels: Bool, _ highlightText: NSAttributedString) -> Void
typealias AnnotationEditSaveAction = (_ data: AnnotationEditState.Data, _ updateSubsequentLabels: Bool) -> Void
typealias AnnotationEditDeleteAction = () -> Void

final class AnnotationEditViewController: UIViewController {
Expand Down Expand Up @@ -174,7 +174,7 @@ final class AnnotationEditViewController: UIViewController {
.subscribe(onNext: { [weak self] in
guard let self else { return }
let state = viewModel.state
saveAction(state.color, state.lineWidth, state.fontSize, state.pageLabel, state.updateSubsequentLabels, state.highlightText)
saveAction(state.data, state.updateSubsequentLabels)
self.cancel()
})
.disposed(by: self.disposeBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ final class AnnotationPopoverViewController: UIViewController {
// key, color, lineWidth, fontSize, pageLabel, updateSubsequentLabels, highlightText
coordinatorDelegate?.showEdit(
state: viewModel.state,
saveAction: { [weak self] _, _, _, pageLabel, updateSubsequentLabels, highlightText in
self?.viewModel.process(action: .setProperties(pageLabel: pageLabel, updateSubsequentLabels: updateSubsequentLabels, highlightText: highlightText))
saveAction: { [weak self] data, updateSubsequentLabels in
self?.viewModel.process(action: .setProperties(pageLabel: data.pageLabel, updateSubsequentLabels: updateSubsequentLabels, highlightText: data.highlightText))
},
deleteAction: { [weak self] in
self?.viewModel.process(action: .delete)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,24 @@ final class PDFAnnotationsViewController: UIViewController {
case .options(let sender):
guard let sender else { return }
let key = annotation.readerKey
let highlightFont = viewModel.state.textEditorFont
coordinatorDelegate?.showCellOptions(
for: annotation,
highlightFont: highlightFont,
highlightFont: viewModel.state.textEditorFont,
userId: viewModel.state.userId,
library: viewModel.state.library,
sender: sender,
userInterfaceStyle: viewModel.state.interfaceStyle,
saveAction: { [weak viewModel] color, lineWidth, fontSize, pageLabel, updateSubsequentLabels, highlightText in
saveAction: { [weak viewModel] data, updateSubsequentLabels in
guard let viewModel else { return }
viewModel.process(action: .updateAnnotationProperties(
key: key.key,
color: color,
lineWidth: lineWidth,
fontSize: fontSize,
pageLabel: pageLabel,
color: data.color,
lineWidth: data.lineWidth,
fontSize: data.fontSize ?? 0,
pageLabel: data.pageLabel,
updateSubsequentLabels: updateSubsequentLabels,
highlightText: highlightText,
higlightFont: highlightFont
highlightText: data.highlightText,
higlightFont: data.highlightFont
))
},
deleteAction: { [weak self] in
Expand Down

0 comments on commit 88b9ccf

Please sign in to comment.