mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Refactor how drafts are handled on a coordinator level and add support for them on thread timelines.
This commit is contained in:
committed by
Stefan Ceriu
parent
eaf14eaaac
commit
6fc6df9375
@@ -39,6 +39,8 @@ enum ComposerToolbarViewModelAction {
|
||||
|
||||
enum ComposerToolbarViewAction {
|
||||
case composerAppeared
|
||||
case composerDisappeared
|
||||
|
||||
case sendMessage
|
||||
case editLastMessage
|
||||
case cancelReply
|
||||
|
||||
@@ -161,9 +161,22 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification).sink { [weak self] _ in
|
||||
self?.saveDraft()
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func start() {
|
||||
Task { await loadDraft() }
|
||||
}
|
||||
|
||||
func stop() {
|
||||
saveDraft()
|
||||
}
|
||||
|
||||
override func process(viewAction: ComposerToolbarViewAction) {
|
||||
switch viewAction {
|
||||
@@ -172,6 +185,8 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
||||
hasAppeard = true
|
||||
wysiwygViewModel.setup()
|
||||
}
|
||||
case .composerDisappeared:
|
||||
saveDraft()
|
||||
case .sendMessage:
|
||||
guard !state.sendButtonDisabled else { return }
|
||||
|
||||
|
||||
+3
-2
@@ -13,8 +13,9 @@ import WysiwygComposer
|
||||
protocol ComposerToolbarViewModelProtocol {
|
||||
var actions: AnyPublisher<ComposerToolbarViewModelAction, Never> { get }
|
||||
var context: ComposerToolbarViewModelType.Context { get }
|
||||
|
||||
func start()
|
||||
func stop()
|
||||
|
||||
func process(timelineAction: TimelineComposerAction)
|
||||
func loadDraft() async
|
||||
func saveDraft()
|
||||
}
|
||||
|
||||
@@ -181,6 +181,9 @@ struct ComposerToolbar: View {
|
||||
} onAppearAction: {
|
||||
context.send(viewAction: .composerAppeared)
|
||||
}
|
||||
.onDisappear {
|
||||
context.send(viewAction: .composerDisappeared)
|
||||
}
|
||||
.environmentObject(context)
|
||||
.focused($composerFocused)
|
||||
.padding(.leading, context.composerFormattingEnabled ? 7 : 0)
|
||||
|
||||
Reference in New Issue
Block a user