Skip to content

Commit

Permalink
#4 소소하지 않음 - updateNeeded를 조작해 homeViewModel.refresh()를 호출
Browse files Browse the repository at this point in the history
  • Loading branch information
comye1 committed Feb 22, 2022
1 parent 6516b30 commit a0eb49f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/src/main/java/com/comye1/cheggprep/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class MainActivity : ComponentActivity() {
}

val firebaseAuth = moreViewModel.firebaseAuth.collectAsState()

val updateNeeded = remember {
mutableStateOf(false)
}

/*
event flow를 보내서 signIn / signOut을 전달받고
각 viewModel의 함수를 호출해서 새롭게 로드할 수 있을까?!
Expand All @@ -97,7 +102,7 @@ class MainActivity : ComponentActivity() {
moreViewModel.userEvent.collect { event ->
when (event) {
MoreViewModel.Companion.UserEvent.SignIn -> {
homeViewModel.refresh()
updateNeeded.value = true
}
MoreViewModel.Companion.UserEvent.SignOut -> {
homeViewModel.clearDecks()
Expand All @@ -116,10 +121,6 @@ class MainActivity : ComponentActivity() {
mutableStateOf(true)
}

val updateNeeded = remember {
mutableStateOf(true)
}

Scaffold(
bottomBar = {
if (bottomBarShown) {
Expand All @@ -131,10 +132,10 @@ class MainActivity : ComponentActivity() {
composable(Screen.Home.route) {
showBottomBar(true)
if (updateNeeded.value) {
homeViewModel.refresh()
Log.d("homerefresh", "called")
DotsTyping()
LaunchedEffect(key1 = true) {
homeViewModel.refresh()
delay(800L)
updateNeeded.value = false
}
Expand Down

0 comments on commit a0eb49f

Please sign in to comment.