Skip to content

Commit

Permalink
feat: Use real data for Sent & Received transfers lists
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 13, 2024
1 parent 5c91be9 commit 2d9cd84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData
import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark
Expand All @@ -36,6 +38,7 @@ import java.util.Date
@Composable
fun TransfersListWithExpiredBottomSheet(
direction: TransferDirection,
transfers: List<TransferUi>,
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
) {
Expand All @@ -47,7 +50,7 @@ fun TransfersListWithExpiredBottomSheet(
TransferItemList(
modifier = Modifier.padding(Margin.Medium),
direction = direction,
transfers = transfersPreviewData, // TODO: Use real data
transfers = transfers,
getSelectedTransferUuid = getSelectedTransferUuid,
onClick = { transfer ->
when {
Expand Down Expand Up @@ -81,11 +84,12 @@ fun TransfersListWithExpiredBottomSheet(

@PreviewLightAndDark
@Composable
private fun Preview() {
private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) transfers: List<TransferUi>) {
SwissTransferTheme {
Surface {
TransfersListWithExpiredBottomSheet(
direction = TransferDirection.RECEIVED,
transfers = transfers,
navigateToDetails = {},
getSelectedTransferUuid = { null },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package com.infomaniak.swisstransfer.ui.screen.main.received

import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
Expand All @@ -40,34 +42,21 @@ fun ReceivedScreen(
getSelectedTransferUuid: () -> String?,
transfersViewModel: TransfersViewModel = hiltViewModel<TransfersViewModel>(),
) {
val transfers by transfersViewModel.receivedTransfers.collectAsStateWithLifecycle()
val areTransfersEmpty = false // TODO: Use the next line instead when available :
// val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } }

ReceivedScreen(
navigateToDetails = navigateToDetails,
getSelectedTransferUuid = getSelectedTransferUuid,
areTransfersEmpty = { areTransfersEmpty },
)
}
val transfers by transfersViewModel.receivedTransfers.collectAsStateWithLifecycle()
val areTransfersEmpty by remember { derivedStateOf { transfers.isEmpty() } }

@Composable
private fun ReceivedScreen(
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
areTransfersEmpty: () -> Boolean,
) {
BrandTopAppBarScaffold(
floatingActionButton = { ReceivedEmptyFab(areTransfersEmpty) },
floatingActionButton = { ReceivedEmptyFab { areTransfersEmpty } },
) {
if (areTransfersEmpty()) {
if (areTransfersEmpty) {
EmptyState(
icon = AppIllus.MascotSearching,
titleRes = R.string.noTransferReceivedTitle,
descriptionRes = R.string.noTransferReceivedDescription,
)
} else {
TransfersListWithExpiredBottomSheet(TransferDirection.RECEIVED, navigateToDetails, getSelectedTransferUuid)
TransfersListWithExpiredBottomSheet(TransferDirection.RECEIVED, transfers, navigateToDetails, getSelectedTransferUuid)
}
}
}
Expand All @@ -80,7 +69,6 @@ private fun Preview() {
ReceivedScreen(
navigateToDetails = {},
getSelectedTransferUuid = { null },
areTransfersEmpty = { false },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,22 @@ fun SentScreen(
getSelectedTransferUuid: () -> String?,
transfersViewModel: TransfersViewModel = hiltViewModel<TransfersViewModel>(),
) {
val transfers by transfersViewModel.sentTransfers.collectAsStateWithLifecycle()
val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } }

SentScreen(
navigateToDetails = navigateToDetails,
getSelectedTransferUuid = getSelectedTransferUuid,
areTransfersEmpty = { areTransfersEmpty },
)
}

@Composable
private fun SentScreen(
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
areTransfersEmpty: () -> Boolean,
) {

val transfers by transfersViewModel.sentTransfers.collectAsStateWithLifecycle()
val areTransfersEmpty by remember { derivedStateOf { transfers.isEmpty() } }
val windowAdaptiveInfo = currentWindowAdaptiveInfo()

BrandTopAppBarScaffold(
floatingActionButton = {
if (windowAdaptiveInfo.isWindowSmall() && !areTransfersEmpty()) {
if (windowAdaptiveInfo.isWindowSmall() && !areTransfersEmpty) {
NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR)
}
},
) {
if (areTransfersEmpty()) {
if (areTransfersEmpty) {
SentEmptyScreen()
} else {
TransfersListWithExpiredBottomSheet(TransferDirection.SENT, navigateToDetails, getSelectedTransferUuid)
TransfersListWithExpiredBottomSheet(TransferDirection.SENT, transfers, navigateToDetails, getSelectedTransferUuid)
}
}
}
Expand All @@ -83,7 +69,6 @@ private fun Preview() {
SentScreen(
navigateToDetails = {},
getSelectedTransferUuid = { null },
areTransfersEmpty = { true },
)
}
}
Expand Down

0 comments on commit 2d9cd84

Please sign in to comment.