Передача имени
This commit is contained in:
parent
3a29d91f93
commit
90881142f3
@ -6,11 +6,14 @@ import ru.myitschool.work.utils.visibleOrGone
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import ru.myitschool.work.R
|
||||
import ru.myitschool.work.databinding.FragmentSearchUserBinding
|
||||
import ru.myitschool.work.ui.entrylist.EntryListFragment
|
||||
import ru.myitschool.work.ui.profile.ProfileDestination
|
||||
import ru.myitschool.work.ui.userInfo.UserInfoDestination
|
||||
|
||||
|
||||
@AndroidEntryPoint
|
||||
@ -49,6 +52,15 @@ class SearchUserFragment : Fragment(R.layout.fragment_search_user) {
|
||||
popUpTo<ProfileDestination> { inclusive = true }
|
||||
}
|
||||
}
|
||||
is SearchUserViewModel.Action.OpenInfo ->{
|
||||
val bundle = Bundle().apply {
|
||||
putString("username", action.userName)
|
||||
}
|
||||
findNavController().navigate(UserInfoDestination) {
|
||||
popUpTo<UserInfoDestination> { inclusive = true }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,11 @@ class SearchUserViewModel @Inject constructor(
|
||||
_state.update { State.Loading }
|
||||
}
|
||||
}
|
||||
fun openInfo(userName: String){
|
||||
viewModelScope.launch {
|
||||
_action.emit(Action.OpenInfo(userName))
|
||||
}
|
||||
}
|
||||
|
||||
fun searchUser(userName: String) {
|
||||
viewModelScope.launch {
|
||||
@ -50,9 +55,7 @@ class SearchUserViewModel @Inject constructor(
|
||||
val userExists = existingUsers.contains(userName)
|
||||
|
||||
if (userExists) {
|
||||
// If user exists, log their name
|
||||
Log.d("SearchUser ViewModel", "User found: $userName")
|
||||
// Here you can update the state if needed
|
||||
openInfo(userName)
|
||||
} else {
|
||||
// If user does not exist, update state with error
|
||||
val errorText = context.resources.getString(R.string.login_error)
|
||||
@ -67,6 +70,7 @@ class SearchUserViewModel @Inject constructor(
|
||||
|
||||
sealed interface Action {
|
||||
data object OpenProfile : Action
|
||||
data class OpenInfo(val userName: String): Action
|
||||
}
|
||||
|
||||
sealed interface State {
|
||||
|
Loading…
x
Reference in New Issue
Block a user