mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
nav link instead of sheet
This commit is contained in:
@@ -9,24 +9,13 @@
|
||||
import SwiftUI
|
||||
import SimpleXChat
|
||||
|
||||
private enum ChooseServerOperatorsSheet: Identifiable {
|
||||
case showConditions(conditionsAction: UsageConditionsAction)
|
||||
|
||||
var id: String {
|
||||
switch self {
|
||||
case .showConditions: return "showConditions"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ChooseServerOperators: View {
|
||||
@EnvironmentObject var theme: AppTheme
|
||||
@State private var showInfoSheet = false
|
||||
@State private var serverOperators: [ServerOperator] = []
|
||||
@State private var selectedOperators = Set<Int64>()
|
||||
@State private var customServersNavLinkActive = false
|
||||
@State private var sheetItem: ChooseServerOperatorsSheet? = nil
|
||||
@State private var conditionsAccepted = false
|
||||
@State private var reviewConditionsNavLinkActive = false
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
@@ -65,28 +54,11 @@ struct ChooseServerOperators: View {
|
||||
.sheet(isPresented: $showInfoSheet) {
|
||||
ChooseServerOperatorsInfoView()
|
||||
}
|
||||
.sheet(item: $sheetItem, onDismiss: onConditionsSheetDismissed) { item in
|
||||
switch item {
|
||||
case let .showConditions(conditionsAction):
|
||||
UsageConditionsView(conditionsAction: conditionsAction, conditionsAccepted: $conditionsAccepted)
|
||||
.modifier(ThemedBackground(grouped: true))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var acceptForOperators: [ServerOperator] { serverOperators.filter { selectedOperators.contains($0.operatorId) } }
|
||||
|
||||
private func onConditionsSheetDismissed() {
|
||||
if conditionsAccepted {
|
||||
ChatModel.shared.enableServerOperators(acceptForOperators)
|
||||
withAnimation {
|
||||
onboardingStageDefault.set(.step4_SetNotificationsMode)
|
||||
ChatModel.shared.onboardingStage = .step4_SetNotificationsMode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func infoText() -> some View {
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: "info.circle")
|
||||
@@ -187,19 +159,47 @@ struct ChooseServerOperators: View {
|
||||
}
|
||||
|
||||
private func reviewConditionsButton() -> some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
Button {
|
||||
sheetItem = .showConditions(conditionsAction: .reviewUpdatedConditions(acceptForOperators: acceptForOperators, deadline: nil))
|
||||
} label: {
|
||||
Text("Review conditions")
|
||||
ZStack {
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
Button {
|
||||
reviewConditionsNavLinkActive = true
|
||||
} label: {
|
||||
Text("Review conditions")
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
|
||||
Spacer()
|
||||
.disabled(selectedOperators.isEmpty)
|
||||
|
||||
|
||||
NavigationLink(isActive: $reviewConditionsNavLinkActive) {
|
||||
reviewConditionsDestinationView()
|
||||
} label: {
|
||||
EmptyView()
|
||||
}
|
||||
.frame(width: 1, height: 1)
|
||||
.hidden()
|
||||
}
|
||||
.disabled(selectedOperators.isEmpty)
|
||||
}
|
||||
|
||||
private func reviewConditionsDestinationView() -> some View {
|
||||
UsageConditionsView(
|
||||
showTitle: false,
|
||||
conditionsAction: .reviewUpdatedConditions(acceptForOperators: acceptForOperators, deadline: nil),
|
||||
onAcceptAction: {
|
||||
ChatModel.shared.enableServerOperators(acceptForOperators)
|
||||
withAnimation {
|
||||
onboardingStageDefault.set(.step4_SetNotificationsMode)
|
||||
ChatModel.shared.onboardingStage = .step4_SetNotificationsMode
|
||||
}
|
||||
}
|
||||
)
|
||||
.navigationTitle("Conditions of use")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
.modifier(ThemedBackground(grouped: true))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ struct NetworkAndServers: View {
|
||||
@EnvironmentObject var theme: AppTheme
|
||||
@State private var serverOperators: [ServerOperator] = []
|
||||
@State private var sheetItem: NetworkAndServersSheet? = nil
|
||||
@State private var conditionsAccepted = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@@ -113,21 +112,15 @@ struct NetworkAndServers: View {
|
||||
.onAppear {
|
||||
serverOperators = ChatModel.shared.serverOperators
|
||||
}
|
||||
.sheet(item: $sheetItem, onDismiss: onConditionsSheetDismissed) { item in
|
||||
.sheet(item: $sheetItem, onDismiss: { serverOperators = ChatModel.shared.serverOperators }) { item in
|
||||
switch item {
|
||||
case let .showConditions(conditionsAction):
|
||||
UsageConditionsView(conditionsAction: conditionsAction, conditionsAccepted: $conditionsAccepted)
|
||||
UsageConditionsView(showTitle: true, conditionsAction: conditionsAction)
|
||||
.modifier(ThemedBackground(grouped: true))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func onConditionsSheetDismissed() {
|
||||
if conditionsAccepted {
|
||||
serverOperators = ChatModel.shared.serverOperators
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func serverOperatorView(
|
||||
_ serverOperator: Binding<ServerOperator>,
|
||||
_ smpServers: [ServerCfg],
|
||||
|
||||
@@ -276,7 +276,8 @@ struct SingleOperatorUsageConditionsView: View {
|
||||
Text("Conditions accepted on: \(conditionsTimestamp(date)).")
|
||||
.foregroundColor(theme.colors.secondary)
|
||||
.padding(.bottom)
|
||||
|
||||
.padding(.bottom)
|
||||
|
||||
} else if !operatorsWithConditionsAccepted.isEmpty {
|
||||
|
||||
Text("You already accepted conditions of use for following operator(s): \(operatorsWithConditionsAccepted.map { $0.name }.joined(separator: ", ")).")
|
||||
@@ -299,7 +300,8 @@ struct SingleOperatorUsageConditionsView: View {
|
||||
|
||||
acceptConditionsButton()
|
||||
.padding(.bottom)
|
||||
|
||||
.padding(.bottom)
|
||||
|
||||
} else {
|
||||
|
||||
Text("In order to use operator \(serverOperator.name), accept conditions of use.")
|
||||
@@ -310,7 +312,8 @@ struct SingleOperatorUsageConditionsView: View {
|
||||
|
||||
acceptConditionsButton()
|
||||
.padding(.bottom)
|
||||
|
||||
.padding(.bottom)
|
||||
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
@@ -350,17 +353,20 @@ struct SingleOperatorUsageConditionsView: View {
|
||||
struct UsageConditionsView: View {
|
||||
@Environment(\.dismiss) var dismiss: DismissAction
|
||||
@EnvironmentObject var theme: AppTheme
|
||||
var showTitle: Bool
|
||||
var conditionsAction: UsageConditionsAction
|
||||
@Binding var conditionsAccepted: Bool
|
||||
var onAcceptAction: (() -> Void)?
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 20) {
|
||||
Group {
|
||||
Text("Conditions of use")
|
||||
.font(.largeTitle)
|
||||
.bold()
|
||||
.padding(.top)
|
||||
.padding(.top)
|
||||
if showTitle {
|
||||
Text("Conditions of use")
|
||||
.font(.largeTitle)
|
||||
.bold()
|
||||
.padding(.top)
|
||||
.padding(.top)
|
||||
}
|
||||
|
||||
switch conditionsAction {
|
||||
case let .reviewUpdatedConditions(acceptForOperators, _):
|
||||
@@ -371,6 +377,7 @@ struct UsageConditionsView: View {
|
||||
|
||||
acceptConditionsButton(acceptForOperators)
|
||||
.padding(.bottom)
|
||||
.padding(.bottom)
|
||||
|
||||
case let .viewAcceptedConditions(acceptedForOperators):
|
||||
|
||||
@@ -378,6 +385,7 @@ struct UsageConditionsView: View {
|
||||
|
||||
conditionsTextView()
|
||||
.padding(.bottom)
|
||||
.padding(.bottom)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -395,8 +403,11 @@ struct UsageConditionsView: View {
|
||||
// (It's counterintuitive to lose to closed sheet or Reset)
|
||||
let date = Date.now
|
||||
ChatModel.shared.acceptConditionsForOperators(acceptForOperators, date)
|
||||
conditionsAccepted = true
|
||||
dismiss()
|
||||
if let onAcceptAction = onAcceptAction {
|
||||
onAcceptAction()
|
||||
} else {
|
||||
dismiss()
|
||||
}
|
||||
} label: {
|
||||
Text("Accept conditions")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user