Skip to content
Snippets Groups Projects
Commit 3b6d4db7 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Improve form on BackupView

parent 9f37c6ea
No related branches found
No related tags found
2 merge requests!112Restore contacts from backup,!102Release 1.0.0
This commit is part of merge request !112. Comments created here will be created in the context of that merge request.
...@@ -7,6 +7,10 @@ import XXMessengerClient ...@@ -7,6 +7,10 @@ import XXMessengerClient
import XXModels import XXModels
public struct BackupState: Equatable { public struct BackupState: Equatable {
public enum Field: String, Hashable {
case passphrase
}
public enum Error: String, Swift.Error, Equatable { public enum Error: String, Swift.Error, Equatable {
case dbContactNotFound case dbContactNotFound
case dbContactUsernameMissing case dbContactUsernameMissing
...@@ -19,6 +23,7 @@ public struct BackupState: Equatable { ...@@ -19,6 +23,7 @@ public struct BackupState: Equatable {
isStopping: Bool = false, isStopping: Bool = false,
backup: BackupStorage.Backup? = nil, backup: BackupStorage.Backup? = nil,
alert: AlertState<BackupAction>? = nil, alert: AlertState<BackupAction>? = nil,
focusedField: Field? = nil,
passphrase: String = "", passphrase: String = "",
isExporting: Bool = false, isExporting: Bool = false,
exportData: Data? = nil exportData: Data? = nil
...@@ -29,6 +34,7 @@ public struct BackupState: Equatable { ...@@ -29,6 +34,7 @@ public struct BackupState: Equatable {
self.isStopping = isStopping self.isStopping = isStopping
self.backup = backup self.backup = backup
self.alert = alert self.alert = alert
self.focusedField = focusedField
self.passphrase = passphrase self.passphrase = passphrase
self.isExporting = isExporting self.isExporting = isExporting
self.exportData = exportData self.exportData = exportData
...@@ -40,6 +46,7 @@ public struct BackupState: Equatable { ...@@ -40,6 +46,7 @@ public struct BackupState: Equatable {
public var isStopping: Bool public var isStopping: Bool
public var backup: BackupStorage.Backup? public var backup: BackupStorage.Backup?
public var alert: AlertState<BackupAction>? public var alert: AlertState<BackupAction>?
@BindableState public var focusedField: Field?
@BindableState public var passphrase: String @BindableState public var passphrase: String
@BindableState public var isExporting: Bool @BindableState public var isExporting: Bool
public var exportData: Data? public var exportData: Data?
...@@ -119,6 +126,7 @@ public let backupReducer = Reducer<BackupState, BackupAction, BackupEnvironment> ...@@ -119,6 +126,7 @@ public let backupReducer = Reducer<BackupState, BackupAction, BackupEnvironment>
case .startTapped: case .startTapped:
state.isStarting = true state.isStarting = true
state.focusedField = nil
return Effect.run { [state] subscriber in return Effect.run { [state] subscriber in
do { do {
let e2e: E2E = try env.messenger.e2e.tryGet() let e2e: E2E = try env.messenger.e2e.tryGet()
......
...@@ -8,6 +8,7 @@ public struct BackupView: View { ...@@ -8,6 +8,7 @@ public struct BackupView: View {
} }
let store: Store<BackupState, BackupAction> let store: Store<BackupState, BackupAction>
@FocusState var focusedField: BackupState.Field?
struct ViewState: Equatable { struct ViewState: Equatable {
struct Backup: Equatable { struct Backup: Equatable {
...@@ -23,6 +24,7 @@ public struct BackupView: View { ...@@ -23,6 +24,7 @@ public struct BackupView: View {
backup = state.backup.map { backup in backup = state.backup.map { backup in
Backup(date: backup.date, size: backup.data.count) Backup(date: backup.date, size: backup.data.count)
} }
focusedField = state.focusedField
passphrase = state.passphrase passphrase = state.passphrase
isExporting = state.isExporting isExporting = state.isExporting
exportData = state.exportData exportData = state.exportData
...@@ -34,6 +36,7 @@ public struct BackupView: View { ...@@ -34,6 +36,7 @@ public struct BackupView: View {
var isStopping: Bool var isStopping: Bool
var isLoading: Bool { isStarting || isResuming || isStopping } var isLoading: Bool { isStarting || isResuming || isStopping }
var backup: Backup? var backup: Backup?
var focusedField: BackupState.Field?
var passphrase: String var passphrase: String
var isExporting: Bool var isExporting: Bool
var exportData: Data? var exportData: Data?
...@@ -57,9 +60,9 @@ public struct BackupView: View { ...@@ -57,9 +60,9 @@ public struct BackupView: View {
) )
} }
.navigationTitle("Backup") .navigationTitle("Backup")
.task { .task { await viewStore.send(.task).finish() }
await viewStore.send(.task).finish() .onChange(of: viewStore.focusedField) { focusedField = $0 }
} .onChange(of: focusedField) { viewStore.send(.set(\.$focusedField, $0)) }
} }
} }
...@@ -75,6 +78,11 @@ public struct BackupView: View { ...@@ -75,6 +78,11 @@ public struct BackupView: View {
prompt: Text("Backup passphrase"), prompt: Text("Backup passphrase"),
label: { Text("Backup passphrase") } label: { Text("Backup passphrase") }
) )
.textContentType(.password)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.focused($focusedField, equals: .passphrase)
Button { Button {
viewStore.send(.startTapped) viewStore.send(.startTapped)
} label: { } label: {
...@@ -91,6 +99,7 @@ public struct BackupView: View { ...@@ -91,6 +99,7 @@ public struct BackupView: View {
} header: { } header: {
Text("New backup") Text("New backup")
} }
.disabled(viewStore.isStarting)
} }
@ViewBuilder func backupSection( @ViewBuilder func backupSection(
......
...@@ -101,6 +101,9 @@ final class BackupFeatureTests: XCTestCase { ...@@ -101,6 +101,9 @@ final class BackupFeatureTests: XCTestCase {
} }
actions = [] actions = []
store.send(.set(\.$focusedField, .passphrase)) {
$0.focusedField = .passphrase
}
store.send(.set(\.$passphrase, passphrase)) { store.send(.set(\.$passphrase, passphrase)) {
$0.passphrase = passphrase $0.passphrase = passphrase
} }
...@@ -110,6 +113,7 @@ final class BackupFeatureTests: XCTestCase { ...@@ -110,6 +113,7 @@ final class BackupFeatureTests: XCTestCase {
actions = [] actions = []
store.send(.startTapped) { store.send(.startTapped) {
$0.isStarting = true $0.isStarting = true
$0.focusedField = nil
} }
XCTAssertNoDifference(actions, [ XCTAssertNoDifference(actions, [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment