mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-27 11:46:58 +02:00
implementation done, only tests, localisation and design feedback are left
This commit is contained in:
+3
@@ -20,6 +20,7 @@ import WysiwygComposer
|
||||
protocol ComposerLinkActionBridgePresenterDelegate: AnyObject {
|
||||
func didCancel()
|
||||
func didDismissInteractively()
|
||||
func didRequestLinkOperation(_ linkOperation: WysiwygLinkOperation)
|
||||
}
|
||||
|
||||
final class ComposerLinkActionBridgePresenter: NSObject {
|
||||
@@ -41,6 +42,8 @@ final class ComposerLinkActionBridgePresenter: NSObject {
|
||||
self?.delegate?.didCancel()
|
||||
case .didDismissInteractively:
|
||||
self?.delegate?.didDismissInteractively()
|
||||
case let .didRequestLinkOperation(linkOperation):
|
||||
self?.delegate?.didRequestLinkOperation(linkOperation)
|
||||
}
|
||||
}
|
||||
let presentable = composerLinkActionCoordinator.toPresentable()
|
||||
|
||||
+4
-1
@@ -20,6 +20,7 @@ import WysiwygComposer
|
||||
enum ComposerLinkActionCoordinatorAction {
|
||||
case didTapCancel
|
||||
case didDismissInteractively
|
||||
case didRequestLinkOperation(_ linkOperation: WysiwygLinkOperation)
|
||||
}
|
||||
|
||||
final class ComposerLinkActionCoordinator: NSObject, Coordinator, Presentable {
|
||||
@@ -42,10 +43,12 @@ final class ComposerLinkActionCoordinator: NSObject, Coordinator, Presentable {
|
||||
switch result {
|
||||
case .cancel:
|
||||
self?.callback?(.didTapCancel)
|
||||
case let .performOperation(linkOperation):
|
||||
self?.callback?(.didRequestLinkOperation(linkOperation))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
hostingController
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ enum ComposerLinkActionViewAction: Equatable {
|
||||
|
||||
enum ComposerLinkActionViewModelResult: Equatable {
|
||||
case cancel
|
||||
case performOperation(_ linkOperation: WysiwygLinkOperation)
|
||||
}
|
||||
|
||||
// MARK: View
|
||||
|
||||
+23
-7
@@ -21,9 +21,9 @@ typealias ComposerLinkActionViewModelType = StateStoreViewModel<ComposerLinkActi
|
||||
|
||||
final class ComposerLinkActionViewModel: ComposerLinkActionViewModelType, ComposerLinkActionViewModelProtocol {
|
||||
// MARK: - Properties
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var callback: ((ComposerLinkActionViewModelResult) -> Void)?
|
||||
@@ -33,10 +33,8 @@ final class ComposerLinkActionViewModel: ComposerLinkActionViewModelType, Compos
|
||||
init(from linkAction: LinkAction) {
|
||||
let initialViewState: ComposerLinkActionViewState
|
||||
let simpleBindings = ComposerLinkActionBindings(text: "", linkUrl: "")
|
||||
// TODO: Add translations
|
||||
switch linkAction {
|
||||
case .edit:
|
||||
let link = "https://element.io"
|
||||
case let .edit(link):
|
||||
initialViewState = .init(
|
||||
linkAction: .edit(link: link),
|
||||
bindings: .init(
|
||||
@@ -57,8 +55,26 @@ final class ComposerLinkActionViewModel: ComposerLinkActionViewModelType, Compos
|
||||
switch viewAction {
|
||||
case .cancel:
|
||||
callback?(.cancel)
|
||||
case .save, .remove:
|
||||
break
|
||||
case .remove:
|
||||
callback?(.performOperation(.removeLinks))
|
||||
case .save:
|
||||
switch state.linkAction {
|
||||
case .createWithText:
|
||||
callback?(
|
||||
.performOperation(
|
||||
.createLink(
|
||||
urlString: state.bindings.linkUrl,
|
||||
text: state.bindings.text
|
||||
)
|
||||
)
|
||||
)
|
||||
case .create, .edit:
|
||||
callback?(
|
||||
.performOperation(
|
||||
.setLink(urlString: state.bindings.linkUrl)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +142,7 @@ enum ComposerViewAction: Equatable {
|
||||
case cancel
|
||||
case contentDidChange(isEmpty: Bool)
|
||||
case linkTapped(linkAction: LinkAction)
|
||||
case storeSelection(selection: NSRange)
|
||||
}
|
||||
|
||||
enum ComposerViewModelResult: Equatable {
|
||||
|
||||
@@ -227,6 +227,7 @@ struct Composer: View {
|
||||
sendMediaButton
|
||||
FormattingToolbar(formatItems: formatItems) { type in
|
||||
if type.action == .link {
|
||||
storeCurrentSelection()
|
||||
sendLinkAction()
|
||||
} else {
|
||||
wysiwygViewModel.apply(type.action)
|
||||
@@ -247,6 +248,10 @@ struct Composer: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func storeCurrentSelection() {
|
||||
viewModel.send(viewAction: .storeSelection(selection: wysiwygViewModel.attributedContent.selection))
|
||||
}
|
||||
|
||||
private func sendLinkAction() {
|
||||
let linkAction = wysiwygViewModel.getLinkAction()
|
||||
viewModel.send(viewAction: .linkTapped(linkAction: linkAction))
|
||||
|
||||
@@ -22,7 +22,7 @@ final class ComposerViewModel: ComposerViewModelType, ComposerViewModelProtocol
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var callback: ((ComposerViewModelResult) -> Void)?
|
||||
@@ -76,6 +76,8 @@ final class ComposerViewModel: ComposerViewModelType, ComposerViewModelProtocol
|
||||
state.bindings.focused
|
||||
}
|
||||
|
||||
var selectionToRestore: NSRange?
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: ComposerViewAction) {
|
||||
@@ -86,6 +88,8 @@ final class ComposerViewModel: ComposerViewModelType, ComposerViewModelProtocol
|
||||
callback?(.contentDidChange(isEmpty: isEmpty))
|
||||
case let .linkTapped(linkAction):
|
||||
callback?(.linkTapped(LinkAction: linkAction))
|
||||
case let .storeSelection(selection):
|
||||
selectionToRestore = selection
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ protocol ComposerViewModelProtocol {
|
||||
var placeholder: String? { get set }
|
||||
var isFocused: Bool { get }
|
||||
var isLandscapePhone: Bool { get set }
|
||||
var selectionToRestore: NSRange? { get }
|
||||
|
||||
func dismissKeyboard()
|
||||
func showKeyboard()
|
||||
|
||||
Reference in New Issue
Block a user