fix: trigger loadAccounts() on auth and loadCachedSchedule() on account selection
The schedule screen was never loading data because no LaunchedEffect called loadAccounts() when the user became authenticated. Now: - App.kt: calls scheduleViewModel.loadAccounts() when authState becomes Authenticated - ScheduleScreen.kt: calls loadCachedSchedule() when selectedAccount is set
This commit is contained in:
@@ -54,6 +54,9 @@ fun App(
|
|||||||
is AuthState.Unauthenticated -> Screen.Login
|
is AuthState.Unauthenticated -> Screen.Login
|
||||||
AuthState.Loading -> currentScreen
|
AuthState.Loading -> currentScreen
|
||||||
}
|
}
|
||||||
|
if (authState is AuthState.Authenticated) {
|
||||||
|
scheduleViewModel.loadAccounts()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MyIceTheme {
|
MyIceTheme {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -44,6 +45,12 @@ fun ScheduleScreen(
|
|||||||
val scheduleState by scheduleViewModel.state.collectAsState()
|
val scheduleState by scheduleViewModel.state.collectAsState()
|
||||||
val authState by authViewModel.state.collectAsState()
|
val authState by authViewModel.state.collectAsState()
|
||||||
|
|
||||||
|
LaunchedEffect(scheduleState.selectedAccount) {
|
||||||
|
if (scheduleState.selectedAccount != null && scheduleState.events.isEmpty()) {
|
||||||
|
scheduleViewModel.loadCachedSchedule()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
|
|||||||
Reference in New Issue
Block a user