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 Zaps(target: ZapTarget)
case Search(search: SearchModel)
case EULA
case Login
case CreateAccount
case SaveKeys(account: CreateAccountModel)
@ViewBuilder
func view(navigationCordinator: NavigationCoordinator, damusState: DamusState) -> some View {
@@ -82,6 +86,18 @@ enum Route: Hashable {
ZapsView(state: damusState, target: target)
case .Search(let 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
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
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:
return false
}
@@ -201,6 +225,15 @@ enum Route: Hashable {
hasher.combine("search")
hasher.combine(search.sub_id)
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 {
@Published var path = [Route]()
func push(route: Route) {
path.append(route)
}
func popToRoot() {
path = []
}

View File

@@ -10,8 +10,7 @@ import SwiftUI
struct CreateAccountView: View {
@StateObject var account: CreateAccountModel = CreateAccountModel()
@StateObject var profileUploadViewModel = ProfileUploadingViewModel()
@State var is_done: Bool = false
@EnvironmentObject var navigationCoordinator: NavigationCoordinator
func SignupForm<FormContent: View>(@ViewBuilder content: () -> FormContent) -> some View {
return VStack(alignment: .leading, spacing: 10.0, content: content)
@@ -25,10 +24,6 @@ struct CreateAccountView: View {
var body: some View {
ZStack(alignment: .top) {
NavigationLink(destination: SaveKeysView(account: account), isActive: $is_done) {
EmptyView()
}
VStack {
VStack(alignment: .center) {
ProfilePictureSelector(pubkey: account.pubkey, viewModel: profileUploadViewModel, callback: uploadedProfilePicture(image_url:))
@@ -63,7 +58,7 @@ struct CreateAccountView: View {
.padding(.top, 10)
Button(action: {
self.is_done = true
navigationCoordinator.push(route: Route.SaveKeys(account: account))
}) {
HStack {
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 {
@State private var login = false
@State var accepted = false
@Environment(\.colorScheme) var colorScheme
@Environment(\.dismiss) var dismiss
@EnvironmentObject var navigationCoordinator: NavigationCoordinator
var body: some View {
ZStack {
ScrollView {
NavigationLink(destination: LoginView(accepted: $accepted), isActive: $login) {
EmptyView()
}
Text(Markdown.parse(content: eula))
.padding()
}
@@ -96,8 +91,7 @@ struct EULAView: View {
}
Button(action: {
accepted = true
login.toggle()
navigationCoordinator.push(route: Route.Login)
}) {
HStack {
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 {
@State private var create_account = false
@State var key: String = ""
@State var is_pubkey: Bool = false
@State var error: String? = nil
@State private var credential_handler = CredentialHandler()
@Binding var accepted: Bool
@EnvironmentObject var navigationCoordinator: NavigationCoordinator
func get_error(parsed_key: ParsedKey?) -> String? {
if self.error != nil {
@@ -55,12 +53,6 @@ struct LoginView: View {
var body: some View {
ZStack(alignment: .top) {
if accepted {
NavigationLink(destination: CreateAccountView(), isActive: $create_account) {
EmptyView()
}
}
VStack {
SignInHeader()
.padding(.top, 100)
@@ -107,7 +99,8 @@ struct LoginView: View {
.padding(.top, 10)
}
CreateAccountPrompt(create_account: $create_account)
CreateAccountPrompt()
.environmentObject(navigationCoordinator)
.padding(.top, 10)
Spacer()
@@ -337,14 +330,14 @@ struct SignInEntry: View {
}
struct CreateAccountPrompt: View {
@Binding var create_account: Bool
@EnvironmentObject var navigationCoordinator: NavigationCoordinator
var body: some View {
HStack {
Text("New to Nostr?", comment: "Ask the user if they are new to Nostr")
.foregroundColor(Color("DamusMediumGrey"))
Button(NSLocalizedString("Create account", comment: "Button to navigate to create account view.")) {
create_account.toggle()
navigationCoordinator.push(route: Route.CreateAccount)
}
Spacer()
@@ -358,8 +351,8 @@ struct LoginView_Previews: PreviewProvider {
let pubkey = "npub18m76awca3y37hkvuneavuw6pjj4525fw90necxmadrvjg0sdy6qsngq955"
let bech32_pubkey = "KeyInput"
Group {
LoginView(key: pubkey, accepted: .constant(true))
LoginView(key: bech32_pubkey, accepted: .constant(true))
LoginView(key: pubkey)
LoginView(key: bech32_pubkey)
}
}
}

View File

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