|
@@ -4,17 +4,21 @@ import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.layout.*
|
|
|
import androidx.compose.material.Text
|
|
|
-import androidx.compose.runtime.Composable
|
|
|
-import androidx.compose.runtime.LaunchedEffect
|
|
|
+import androidx.compose.runtime.*
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
+import androidx.compose.ui.platform.LocalLifecycleOwner
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
+import androidx.lifecycle.Lifecycle
|
|
|
+import androidx.lifecycle.flowWithLifecycle
|
|
|
import com.ys.bdtp.adm.R
|
|
|
import com.ys.bdtp.adm.app.theme.textBlackColor
|
|
|
+import com.ys.bdtp.adm.mvvm.model.Data
|
|
|
+import com.ys.bdtp.adm.mvvm.model.State
|
|
|
import com.ys.bdtp.adm.mvvm.ui.screen.main.LocalNavHostController
|
|
|
import com.ys.bdtp.adm.mvvm.ui.screen.main.flashToLogin
|
|
|
import com.ys.bdtp.adm.mvvm.ui.screen.main.flashToProject
|
|
@@ -29,8 +33,15 @@ fun Flash() {
|
|
|
val nav = LocalNavHostController.current!!
|
|
|
val vm by rememberViewModel<FlashViewModel>()
|
|
|
|
|
|
- LaunchedEffect(Unit) {
|
|
|
- val user = vm.currentUser()
|
|
|
+ val lifecycleOwner = LocalLifecycleOwner.current
|
|
|
+ val lifecycleWare = remember(vm.getUser, lifecycleOwner) {
|
|
|
+ vm.getUser.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
|
|
|
+ }
|
|
|
+
|
|
|
+ val userState = lifecycleWare.collectAsState(Data.loading())
|
|
|
+
|
|
|
+ if (userState.value.state == State.Success) {
|
|
|
+ val user = userState.value.data
|
|
|
if (user != null) {
|
|
|
nav.flashToProject()
|
|
|
} else {
|