Skip to content

Commit bf87d9c

Browse files
Refactor: Move name validation to OnboardingViewModel
Moved the user name validation logic from OnboardingScreen (Composable) to OnboardingViewModel. Changed validation from isNotEmpty() to isNotBlank() to prevent saving whitespace-only names. This improves separation of concerns and testability.
1 parent ed0e88e commit bf87d9c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ class OnboardingViewModel @Inject constructor(
2323
}
2424

2525
fun saveName() {
26-
viewModelScope.launch {
27-
userPreferencesRepository.saveUserName(name.value)
26+
if (name.value.isNotBlank()) {
27+
viewModelScope.launch {
28+
userPreferencesRepository.saveUserName(name.value)
29+
}
2830
}
2931
}
3032

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ fun OnboardingScreen(
9898
Button(onClick = {
9999
if (currentStep == 0) {
100100
// Save Name
101-
if (name.isNotEmpty()) {
102-
viewModel.saveName()
103-
}
101+
viewModel.saveName()
104102
}
105103

106104
if (currentStep < totalSteps - 1) {

0 commit comments

Comments
 (0)