Always initialize server/user view models

This commit is contained in:
Damontecres 2025-11-14 13:33:33 -05:00
parent c5a5345f6c
commit b7dfb2ca5f
No known key found for this signature in database
4 changed files with 7 additions and 10 deletions

View file

@ -53,6 +53,7 @@ fun SwitchServerContent(
var showAddServer by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
viewModel.init()
viewModel.discoverServers()
}

View file

@ -52,10 +52,6 @@ class SwitchServerViewModel
addServerState.value = LoadingState.Pending
}
init {
init()
}
fun init() {
viewModelScope.launchIO {
withContext(Dispatchers.Main) {

View file

@ -58,6 +58,9 @@ fun SwitchUserContent(
),
) {
val context = LocalContext.current
LaunchedEffect(Unit) {
viewModel.init()
}
// val currentServer by viewModel.serverRepository.currentServer.observeAsState()
val currentUser by viewModel.serverRepository.currentUser.observeAsState()

View file

@ -48,12 +48,6 @@ class SwitchUserViewModel
fun create(server: JellyfinServer): SwitchUserViewModel
}
init {
viewModelScope.launch(Dispatchers.Main + ExceptionHandler()) {
serverRepository.switchServerOrUser()
}
}
val serverQuickConnect = MutableLiveData<Boolean>(false)
val users = MutableLiveData<List<JellyfinUser>>(listOf())
@ -78,6 +72,9 @@ class SwitchUserViewModel
}
fun init() {
viewModelScope.launch(Dispatchers.Main + ExceptionHandler()) {
serverRepository.switchServerOrUser()
}
quickConnectJob?.cancel()
viewModelScope.launchIO {
users.setValueOnMain(listOf())