-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1664 from planetary-social/onboarding-display-name
#1597: Display Name screen in onboarding
- Loading branch information
Showing
9 changed files
with
195 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Nos/Assets/Colors.xcassets/text-field-placeholder.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "0.500", | ||
"blue" : "0xD8", | ||
"green" : "0x88", | ||
"red" : "0xA5" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Foundation | ||
|
||
/// An error that may occur while saving a profile. | ||
enum SaveProfileError: LocalizedError { | ||
case unexpectedError | ||
case unableToPublishChanges | ||
|
||
var errorDescription: String? { | ||
switch self { | ||
case .unexpectedError: | ||
return "Something unexpected happened" | ||
case .unableToPublishChanges: | ||
return "We were unable to publish your changes to the network." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import Dependencies | ||
import SwiftUI | ||
|
||
/// The Display Name view in the onboarding. | ||
struct DisplayNameView: View { | ||
@Environment(OnboardingState.self) private var state | ||
@Environment(CurrentUser.self) private var currentUser | ||
@Environment(\.managedObjectContext) private var viewContext | ||
|
||
@Dependency(\.crashReporting) private var crashReporting | ||
|
||
@State private var displayName = "" | ||
@State private var showError: Bool = false | ||
|
||
var body: some View { | ||
ZStack { | ||
Color.appBg | ||
.ignoresSafeArea() | ||
ViewThatFits(in: .vertical) { | ||
displayNameStack | ||
|
||
ScrollView { | ||
displayNameStack | ||
} | ||
} | ||
} | ||
.navigationBarHidden(true) | ||
.alert("displayNameError", isPresented: $showError) { | ||
Button { | ||
nextStep() | ||
} label: { | ||
Text("skipForNow") | ||
} | ||
} | ||
} | ||
|
||
var displayNameStack: some View { | ||
VStack(alignment: .leading, spacing: 20) { | ||
LargeNumberView(3) | ||
Text("displayNameHeadline") | ||
.font(.clarityBold(.title)) | ||
.foregroundStyle(Color.primaryTxt) | ||
Text("displayNameDescription") | ||
.font(.body) | ||
.foregroundStyle(Color.secondaryTxt) | ||
TextField( | ||
"", | ||
text: $displayName, | ||
prompt: Text("displayNamePlaceholder") | ||
.foregroundStyle(Color.textFieldPlaceholder) | ||
) | ||
.textInputAutocapitalization(.none) | ||
.foregroundStyle(Color.primaryTxt) | ||
.fontWeight(.bold) | ||
.autocorrectionDisabled() | ||
.padding() | ||
.withStyledBorder() | ||
Spacer() | ||
BigActionButton("next") { | ||
await save() | ||
} | ||
} | ||
.padding(40) | ||
.readabilityPadding() | ||
} | ||
|
||
func nextStep() { | ||
state.step = .buildYourNetwork | ||
} | ||
|
||
/// Saves the display name locally and publishes the event to relays. Sets `showError` if it fails. | ||
func save() async { | ||
guard let author = await currentUser.author else { | ||
showError = true | ||
return | ||
} | ||
|
||
author.displayName = displayName | ||
do { | ||
try viewContext.save() | ||
try await currentUser.publishMetadata() | ||
nextStep() | ||
} catch { | ||
crashReporting.report(error) | ||
showError = true | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
DisplayNameView() | ||
.environment(OnboardingState()) | ||
.inject(previewData: PreviewData()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters