|
@@ -7,16 +7,13 @@ import androidx.compose.material.Text
|
|
|
import androidx.compose.runtime.*
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
-import androidx.compose.ui.platform.LocalLifecycleOwner
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
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.app.theme.textBlackColor
|
|
|
import com.ys.bdtp.adm.app.theme.underColor
|
|
|
-import com.ys.bdtp.adm.mvvm.model.Data
|
|
|
+import com.ys.bdtp.adm.app.tools.lifecycleState
|
|
|
import com.ys.bdtp.adm.mvvm.model.State
|
|
|
import com.ys.bdtp.adm.mvvm.ui.compose.*
|
|
|
import com.ys.bdtp.adm.mvvm.ui.screen.main.LocalNavHostController
|
|
@@ -36,12 +33,7 @@ fun Project() {
|
|
|
val scope = rememberCoroutineScope()
|
|
|
var popupState by remember { mutableStateOf(false) }
|
|
|
|
|
|
- val lifecycleOwner = LocalLifecycleOwner.current
|
|
|
- val userFlowLifecycleAware = remember(vm.userWithsProjects, lifecycleOwner) {
|
|
|
- vm.userWithsProjects.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
|
|
|
- }
|
|
|
-
|
|
|
- val dataState = userFlowLifecycleAware.collectAsState(Data.loading())
|
|
|
+ val userWithProjectsState = lifecycleState(vm.userWithsProjectsFlow)
|
|
|
|
|
|
Column(
|
|
|
modifier = Modifier.fillMaxSize()
|
|
@@ -85,28 +77,25 @@ fun Project() {
|
|
|
Column(
|
|
|
modifier = Modifier
|
|
|
.fillMaxSize()
|
|
|
- .wrapContentWidth()
|
|
|
.background(underColor)
|
|
|
- .padding(horizontal = 32.dp, vertical = 40.dp)
|
|
|
+ .padding(horizontal = 32.dp, vertical = 40.dp),
|
|
|
) {
|
|
|
- val userWithProjects = dataState.value
|
|
|
+ val userWithProjects = userWithProjectsState.value
|
|
|
when (userWithProjects.state) {
|
|
|
is State.Loading -> {
|
|
|
- // TODO 给与加载提示
|
|
|
+ CircularProgress()
|
|
|
}
|
|
|
is State.Success -> {
|
|
|
- val uwp = userWithProjects.data
|
|
|
- if (uwp == null) {
|
|
|
+ val data = userWithProjects.data
|
|
|
+ if (data == null) {
|
|
|
nav.projectToLogin()
|
|
|
- } else if (uwp.projects.isEmpty()) {
|
|
|
+ } else if (data.projects.isEmpty()) {
|
|
|
Blank()
|
|
|
} else {
|
|
|
- ProjectContent(uwp.projects)
|
|
|
+ ProjectContent(data.projects)
|
|
|
}
|
|
|
}
|
|
|
- is State.Failure -> {
|
|
|
- // TODO 给与失败提示
|
|
|
- }
|
|
|
+ is State.Failure -> {}
|
|
|
}
|
|
|
}
|
|
|
}
|