onboarding wip

This commit is contained in:
spaced4ndy
2024-10-31 13:29:43 +04:00
parent 534f814165
commit d30d28c9db
5 changed files with 140 additions and 4 deletions
+1 -1
View File
@@ -1624,7 +1624,7 @@ func startChat(refreshInvitations: Bool = true) throws {
withAnimation {
let savedOnboardingStage = onboardingStageDefault.get()
m.onboardingStage = [.step1_SimpleXInfo, .step2_CreateProfile].contains(savedOnboardingStage) && m.users.count == 1
? .step3_CreateSimpleXAddress
? .step3_ChooseServerOperators
: savedOnboardingStage
if m.onboardingStage == .onboardingComplete && !privacyDeliveryReceiptsSet.get() {
m.setDeliveryReceipts = true
@@ -0,0 +1,130 @@
//
// ChooseServerOperators.swift
// SimpleX (iOS)
//
// Created by spaced4ndy on 31.10.2024.
// Copyright © 2024 SimpleX Chat. All rights reserved.
//
import SwiftUI
import SimpleXChat
struct ChooseServerOperators: View {
@EnvironmentObject var theme: AppTheme
@State private var showInfoSheet = false
@State private var serverOperators: [ServerOperator] = []
@State private var selectedOperators = Set<Int64>()
var body: some View {
GeometryReader { g in
ScrollView {
VStack(alignment: .leading, spacing: 20) {
Text("Choose operators")
.font(.largeTitle)
.bold()
.padding(.top)
infoText()
Spacer()
ForEach(serverOperators) { srvOperator in
operatorCheckView(srvOperator)
.padding(.horizontal)
}
Spacer()
Spacer()
continueButton()
.padding(.bottom)
}
.frame(minHeight: g.size.height)
}
}
.frame(maxHeight: .infinity)
.padding()
.onAppear {
serverOperators = ChatModel.shared.serverOperators
selectedOperators = Set(serverOperators.filter { $0.enabled }.map { $0.operatorId })
}
.sheet(isPresented: $showInfoSheet) {
Text("Info")
}
}
private func infoText() -> some View {
HStack(spacing: 12) {
Image(systemName: "info.circle")
.resizable()
.scaledToFit()
.frame(width: 20, height: 20)
.foregroundColor(theme.colors.primary)
.onTapGesture {
showInfoSheet = true
}
Text("Select operators, whose servers you will be using.")
}
}
@ViewBuilder private func operatorCheckView(_ serverOperator: ServerOperator) -> some View {
let checked = selectedOperators.contains(serverOperator.operatorId)
let icon = checked ? "checkmark.circle.fill" : "circle"
let iconColor = checked ? theme.colors.primary : Color(uiColor: .tertiaryLabel).asAnotherColorFromSecondary(theme)
HStack(spacing: 10) {
Image(serverOperator.info.logo)
.resizable()
.scaledToFit()
.frame(width: 30, height: 30)
Text(serverOperator.name)
.font(.title2)
Spacer()
Image(systemName: icon)
.resizable()
.scaledToFit()
.frame(width: 26, height: 26)
.foregroundColor(iconColor)
}
.background(Color(.systemBackground))
.onTapGesture {
if checked {
selectedOperators.remove(serverOperator.operatorId)
} else {
selectedOperators.insert(serverOperator.operatorId)
}
}
}
private func yourServersButton() -> some View {
NavigationLink {
YourServersView()
.navigationTitle("Your servers")
.modifier(ThemedBackground(grouped: true))
} label: {
Text("Your servers")
}
}
private func continueButton() -> some View {
HStack {
Spacer()
Button {
withAnimation {
onboardingStageDefault.set(.step4_SetNotificationsMode)
ChatModel.shared.onboardingStage = .step4_SetNotificationsMode
}
} label: {
Text("Continue")
}
.buttonStyle(.borderedProminent)
Spacer()
}
}
}
#Preview {
ChooseServerOperators()
}
@@ -176,8 +176,8 @@ private func createProfile(_ displayName: String, showAlert: (UserProfileAlert)
if m.users.isEmpty || m.users.allSatisfy({ $0.user.hidden }) {
try startChat()
withAnimation {
onboardingStageDefault.set(.step3_CreateSimpleXAddress)
m.onboardingStage = .step3_CreateSimpleXAddress
onboardingStageDefault.set(.step3_ChooseServerOperators)
m.onboardingStage = .step3_ChooseServerOperators
}
} else {
onboardingStageDefault.set(.onboardingComplete)
@@ -16,6 +16,7 @@ struct OnboardingView: View {
case .step1_SimpleXInfo: SimpleXInfo(onboarding: true)
case .step2_CreateProfile: CreateFirstProfile()
case .step3_CreateSimpleXAddress: CreateSimpleXAddress()
case .step3_ChooseServerOperators: ChooseServerOperators()
case .step4_SetNotificationsMode: SetNotificationsMode()
case .onboardingComplete: EmptyView()
}
@@ -25,7 +26,8 @@ struct OnboardingView: View {
enum OnboardingStage: String, Identifiable {
case step1_SimpleXInfo
case step2_CreateProfile
case step3_CreateSimpleXAddress
case step3_CreateSimpleXAddress // deprecated
case step3_ChooseServerOperators
case step4_SetNotificationsMode
case onboardingComplete
@@ -145,6 +145,7 @@
640417CD2B29B8C200CCB412 /* NewChatMenuButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640417CB2B29B8C200CCB412 /* NewChatMenuButton.swift */; };
640417CE2B29B8C200CCB412 /* NewChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640417CC2B29B8C200CCB412 /* NewChatView.swift */; };
6407435F2CD2922400158442 /* YourServersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6407435E2CD2922400158442 /* YourServersView.swift */; };
640743612CD360E600158442 /* ChooseServerOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640743602CD360E600158442 /* ChooseServerOperators.swift */; };
6407BA83295DA85D0082BA18 /* CIInvalidJSONView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6407BA82295DA85D0082BA18 /* CIInvalidJSONView.swift */; };
6419EC562AB8BC8B004A607A /* ContextInvitingContactMemberView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6419EC552AB8BC8B004A607A /* ContextInvitingContactMemberView.swift */; };
6419EC582AB97507004A607A /* CIMemberCreatedContactView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6419EC572AB97507004A607A /* CIMemberCreatedContactView.swift */; };
@@ -490,6 +491,7 @@
640417CB2B29B8C200CCB412 /* NewChatMenuButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewChatMenuButton.swift; sourceTree = "<group>"; };
640417CC2B29B8C200CCB412 /* NewChatView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewChatView.swift; sourceTree = "<group>"; };
6407435E2CD2922400158442 /* YourServersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YourServersView.swift; sourceTree = "<group>"; };
640743602CD360E600158442 /* ChooseServerOperators.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChooseServerOperators.swift; sourceTree = "<group>"; };
6407BA82295DA85D0082BA18 /* CIInvalidJSONView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIInvalidJSONView.swift; sourceTree = "<group>"; };
6419EC552AB8BC8B004A607A /* ContextInvitingContactMemberView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextInvitingContactMemberView.swift; sourceTree = "<group>"; };
6419EC572AB97507004A607A /* CIMemberCreatedContactView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIMemberCreatedContactView.swift; sourceTree = "<group>"; };
@@ -886,6 +888,7 @@
64466DC729FC2B3B00E3D48D /* CreateSimpleXAddress.swift */,
5C9A5BDA2871E05400A5B906 /* SetNotificationsMode.swift */,
5CBD285B29575B8E00EC2CF4 /* WhatsNewView.swift */,
640743602CD360E600158442 /* ChooseServerOperators.swift */,
);
path = Onboarding;
sourceTree = "<group>";
@@ -1389,6 +1392,7 @@
64C06EB52A0A4A7C00792D4D /* ChatItemInfoView.swift in Sources */,
640417CE2B29B8C200CCB412 /* NewChatView.swift in Sources */,
6440CA03288AECA70062C672 /* AddGroupMembersView.swift in Sources */,
640743612CD360E600158442 /* ChooseServerOperators.swift in Sources */,
5C3F1D58284363C400EC8A82 /* PrivacySettings.swift in Sources */,
5C55A923283CEDE600C4E99E /* SoundPlayer.swift in Sources */,
5C93292F29239A170090FFF9 /* ProtocolServersView.swift in Sources */,