Skip to content

Commit 214e487

Browse files
Refactor: Fix silent failure in name validation
Updated `OnboardingViewModel.saveName` to return a `Boolean` indicating success. Updated `OnboardingScreen` to check this return value and show a Toast message if validation fails, preventing navigation to the next step. This addresses the feedback that the previous refactoring allowed users to proceed with a blank name.
1 parent bf87d9c commit 214e487

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app/src/main/java/com/example/theloop/OnboardingViewModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ class OnboardingViewModel @Inject constructor(
2222
_name.value = newName
2323
}
2424

25-
fun saveName() {
25+
fun saveName(): Boolean {
2626
if (name.value.isNotBlank()) {
2727
viewModelScope.launch {
2828
userPreferencesRepository.saveUserName(name.value)
2929
}
30+
return true
3031
}
32+
return false
3133
}
3234

3335
fun completeOnboarding() {

app/src/main/java/com/example/theloop/ui/screens/OnboardingScreen.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ fun OnboardingScreen(
9898
Button(onClick = {
9999
if (currentStep == 0) {
100100
// Save Name
101-
viewModel.saveName()
101+
if (!viewModel.saveName()) {
102+
Toast.makeText(context, "Name cannot be blank", Toast.LENGTH_SHORT).show()
103+
return@Button
104+
}
102105
}
103106

104107
if (currentStep < totalSteps - 1) {

0 commit comments

Comments
 (0)