Skip to content

Commit

Permalink
Already define a compose state and a "loading" status for the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Aug 15, 2024
1 parent 4e46d2e commit f9db0f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteType
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.NewTransferFab
Expand All @@ -42,17 +44,20 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewTablet
@Composable
fun SentScreen(
navigateToDetails: (transferId: Int) -> Unit,
sentViewModel: SentViewModel = viewModel<SentViewModel>(),
) {
val viewmodel = viewModel<SentViewModel>()
val transfers by sentViewModel.transfers.collectAsStateWithLifecycle()
SentScreen(
isEmpty = viewmodel.transfers.isEmpty(),
transfers = transfers,
navType = LocalNavType.current,
)
}

@Composable
private fun SentScreen(isEmpty: Boolean, navType: NavigationSuiteType) {
if (isEmpty) {
private fun SentScreen(transfers: List<Any>?, navType: NavigationSuiteType) {
if (transfers == null) return

if (transfers.isEmpty()) {
EmptyScreen()
} else {
TransferScreen(navType)
Expand Down Expand Up @@ -108,7 +113,7 @@ private fun SentScreenMobilePreview() {
SwissTransferTheme {
Surface {
SentScreen(
isEmpty = true,
transfers = emptyList(),
navType = NavigationSuiteType.NavigationBar,
)
}
Expand All @@ -121,7 +126,7 @@ private fun SentScreenTabletPreview() {
SwissTransferTheme {
Surface {
SentScreen(
isEmpty = true,
transfers = emptyList(),
navType = NavigationSuiteType.NavigationRail,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
package com.infomaniak.swisstransfer.ui.screen.main.sent

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.stateIn

class SentViewModel: ViewModel() {
val transfers = emptyList<Any>()
class SentViewModel : ViewModel() {
val transfers = callbackFlow<List<Any>> { emptyList<Any>() }.stateIn(viewModelScope, SharingStarted.Eagerly, null)
}

0 comments on commit f9db0f3

Please sign in to comment.