Convert onboarding flow navigation links

This commit is contained in:
Scott Penrose
2023-06-03 13:22:43 -04:00
committed by William Casarin
parent 242455410e
commit c50ccef56d
5 changed files with 54 additions and 36 deletions

View File

@@ -31,6 +31,10 @@ enum Route: Hashable {
case Reactions(reactions: ReactionsModel) case Reactions(reactions: ReactionsModel)
case Zaps(target: ZapTarget) case Zaps(target: ZapTarget)
case Search(search: SearchModel) case Search(search: SearchModel)
case EULA
case Login
case CreateAccount
case SaveKeys(account: CreateAccountModel)
@ViewBuilder @ViewBuilder
func view(navigationCordinator: NavigationCoordinator, damusState: DamusState) -> some View { func view(navigationCordinator: NavigationCoordinator, damusState: DamusState) -> some View {
@@ -82,6 +86,18 @@ enum Route: Hashable {
ZapsView(state: damusState, target: target) ZapsView(state: damusState, target: target)
case .Search(let search): case .Search(let search):
SearchView(appstate: damusState, search: search) SearchView(appstate: damusState, search: search)
case .EULA:
EULAView()
.environmentObject(navigationCordinator)
case .Login:
LoginView()
.environmentObject(navigationCordinator)
case .CreateAccount:
CreateAccountView()
.environmentObject(navigationCordinator)
case .SaveKeys(let account):
SaveKeysView(account: account)
.environmentObject(navigationCordinator)
} }
} }
@@ -133,6 +149,14 @@ enum Route: Hashable {
return lhs_target == rhs_target return lhs_target == rhs_target
case (.Search(let lhs_search), .Search(let rhs_search)): case (.Search(let lhs_search), .Search(let rhs_search)):
return lhs_search.sub_id == rhs_search.sub_id && lhs_search.profiles_subid == rhs_search.profiles_subid return lhs_search.sub_id == rhs_search.sub_id && lhs_search.profiles_subid == rhs_search.profiles_subid
case (.EULA, .EULA):
return true
case (.Login, .Login):
return true
case (.CreateAccount, .CreateAccount):
return true
case (.SaveKeys(let lhs_account), .SaveKeys(let rhs_account)):
return lhs_account.pubkey == rhs_account.pubkey
default: default:
return false return false
} }
@@ -201,6 +225,15 @@ enum Route: Hashable {
hasher.combine("search") hasher.combine("search")
hasher.combine(search.sub_id) hasher.combine(search.sub_id)
hasher.combine(search.profiles_subid) hasher.combine(search.profiles_subid)
case .EULA:
hasher.combine("eula")
case .Login:
hasher.combine("login")
case .CreateAccount:
hasher.combine("createAccount")
case .SaveKeys(let account):
hasher.combine("saveKeys")
hasher.combine(account.pubkey)
} }
} }
} }
@@ -208,6 +241,10 @@ enum Route: Hashable {
class NavigationCoordinator: ObservableObject { class NavigationCoordinator: ObservableObject {
@Published var path = [Route]() @Published var path = [Route]()
func push(route: Route) {
path.append(route)
}
func popToRoot() { func popToRoot() {
path = [] path = []
} }

View File

@@ -10,8 +10,7 @@ import SwiftUI
struct CreateAccountView: View { struct CreateAccountView: View {
@StateObject var account: CreateAccountModel = CreateAccountModel() @StateObject var account: CreateAccountModel = CreateAccountModel()
@StateObject var profileUploadViewModel = ProfileUploadingViewModel() @StateObject var profileUploadViewModel = ProfileUploadingViewModel()
@EnvironmentObject var navigationCoordinator: NavigationCoordinator
@State var is_done: Bool = false
func SignupForm<FormContent: View>(@ViewBuilder content: () -> FormContent) -> some View { func SignupForm<FormContent: View>(@ViewBuilder content: () -> FormContent) -> some View {
return VStack(alignment: .leading, spacing: 10.0, content: content) return VStack(alignment: .leading, spacing: 10.0, content: content)
@@ -25,10 +24,6 @@ struct CreateAccountView: View {
var body: some View { var body: some View {
ZStack(alignment: .top) { ZStack(alignment: .top) {
NavigationLink(destination: SaveKeysView(account: account), isActive: $is_done) {
EmptyView()
}
VStack { VStack {
VStack(alignment: .center) { VStack(alignment: .center) {
ProfilePictureSelector(pubkey: account.pubkey, viewModel: profileUploadViewModel, callback: uploadedProfilePicture(image_url:)) ProfilePictureSelector(pubkey: account.pubkey, viewModel: profileUploadViewModel, callback: uploadedProfilePicture(image_url:))
@@ -63,7 +58,7 @@ struct CreateAccountView: View {
.padding(.top, 10) .padding(.top, 10)
Button(action: { Button(action: {
self.is_done = true navigationCoordinator.push(route: Route.SaveKeys(account: account))
}) { }) {
HStack { HStack {
Text("Create account now", comment: "Button to create account.") Text("Create account now", comment: "Button to create account.")

View File

@@ -56,18 +56,13 @@ By using our Application, you signify your acceptance of this EULA. If you do no
""" """
struct EULAView: View { struct EULAView: View {
@State private var login = false
@State var accepted = false
@Environment(\.colorScheme) var colorScheme @Environment(\.colorScheme) var colorScheme
@Environment(\.dismiss) var dismiss @Environment(\.dismiss) var dismiss
@EnvironmentObject var navigationCoordinator: NavigationCoordinator
var body: some View { var body: some View {
ZStack { ZStack {
ScrollView { ScrollView {
NavigationLink(destination: LoginView(accepted: $accepted), isActive: $login) {
EmptyView()
}
Text(Markdown.parse(content: eula)) Text(Markdown.parse(content: eula))
.padding() .padding()
} }
@@ -96,8 +91,7 @@ struct EULAView: View {
} }
Button(action: { Button(action: {
accepted = true navigationCoordinator.push(route: Route.Login)
login.toggle()
}) { }) {
HStack { HStack {
Text("Accept", comment: "Button to accept the end user license agreement before being allowed into the app.") Text("Accept", comment: "Button to accept the end user license agreement before being allowed into the app.")

View File

@@ -33,13 +33,11 @@ enum ParsedKey {
} }
struct LoginView: View { struct LoginView: View {
@State private var create_account = false
@State var key: String = "" @State var key: String = ""
@State var is_pubkey: Bool = false @State var is_pubkey: Bool = false
@State var error: String? = nil @State var error: String? = nil
@State private var credential_handler = CredentialHandler() @State private var credential_handler = CredentialHandler()
@EnvironmentObject var navigationCoordinator: NavigationCoordinator
@Binding var accepted: Bool
func get_error(parsed_key: ParsedKey?) -> String? { func get_error(parsed_key: ParsedKey?) -> String? {
if self.error != nil { if self.error != nil {
@@ -55,12 +53,6 @@ struct LoginView: View {
var body: some View { var body: some View {
ZStack(alignment: .top) { ZStack(alignment: .top) {
if accepted {
NavigationLink(destination: CreateAccountView(), isActive: $create_account) {
EmptyView()
}
}
VStack { VStack {
SignInHeader() SignInHeader()
.padding(.top, 100) .padding(.top, 100)
@@ -107,7 +99,8 @@ struct LoginView: View {
.padding(.top, 10) .padding(.top, 10)
} }
CreateAccountPrompt(create_account: $create_account) CreateAccountPrompt()
.environmentObject(navigationCoordinator)
.padding(.top, 10) .padding(.top, 10)
Spacer() Spacer()
@@ -337,14 +330,14 @@ struct SignInEntry: View {
} }
struct CreateAccountPrompt: View { struct CreateAccountPrompt: View {
@Binding var create_account: Bool @EnvironmentObject var navigationCoordinator: NavigationCoordinator
var body: some View { var body: some View {
HStack { HStack {
Text("New to Nostr?", comment: "Ask the user if they are new to Nostr") Text("New to Nostr?", comment: "Ask the user if they are new to Nostr")
.foregroundColor(Color("DamusMediumGrey")) .foregroundColor(Color("DamusMediumGrey"))
Button(NSLocalizedString("Create account", comment: "Button to navigate to create account view.")) { Button(NSLocalizedString("Create account", comment: "Button to navigate to create account view.")) {
create_account.toggle() navigationCoordinator.push(route: Route.CreateAccount)
} }
Spacer() Spacer()
@@ -358,8 +351,8 @@ struct LoginView_Previews: PreviewProvider {
let pubkey = "npub18m76awca3y37hkvuneavuw6pjj4525fw90necxmadrvjg0sdy6qsngq955" let pubkey = "npub18m76awca3y37hkvuneavuw6pjj4525fw90necxmadrvjg0sdy6qsngq955"
let bech32_pubkey = "KeyInput" let bech32_pubkey = "KeyInput"
Group { Group {
LoginView(key: pubkey, accepted: .constant(true)) LoginView(key: pubkey)
LoginView(key: bech32_pubkey, accepted: .constant(true)) LoginView(key: bech32_pubkey)
} }
} }
} }

View File

@@ -17,16 +17,12 @@ func hex_col(r: UInt8, g: UInt8, b: UInt8) -> Color {
struct SetupView: View { struct SetupView: View {
@State private var eula = false @StateObject var navigationCoordinator: NavigationCoordinator = NavigationCoordinator()
var body: some View { var body: some View {
NavigationView { NavigationStack(path: $navigationCoordinator.path) {
ZStack { ZStack {
VStack(alignment: .center) { VStack(alignment: .center) {
NavigationLink(destination: EULAView(), isActive: $eula) {
EmptyView()
}
Spacer() Spacer()
Image("logo-nobg") Image("logo-nobg")
@@ -53,7 +49,7 @@ struct SetupView: View {
Spacer() Spacer()
Button(action: { Button(action: {
eula.toggle() navigationCoordinator.push(route: Route.EULA)
}) { }) {
HStack { HStack {
Text("Let's get started!", comment: "Button to continue to login page.") Text("Let's get started!", comment: "Button to continue to login page.")
@@ -72,6 +68,9 @@ struct SetupView: View {
.ignoresSafeArea(), .ignoresSafeArea(),
alignment: .top alignment: .top
) )
.navigationDestination(for: Route.self) { route in
route.view(navigationCordinator: navigationCoordinator, damusState: DamusState.empty)
}
} }
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.navigationViewStyle(StackNavigationViewStyle()) .navigationViewStyle(StackNavigationViewStyle())