Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fun WooPosOrdersListLoadingPane(modifier: Modifier = Modifier) {
}

@Composable
private fun OrderDetailsLoadingPane(modifier: Modifier = Modifier) {
fun OrderDetailsLoadingPane(modifier: Modifier = Modifier) {
Column(
modifier = modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,37 @@ private fun OrdersContent(
.weight(0.7f)
.background(MaterialTheme.colorScheme.surface)
) {
WooPosOrderDetails(
modifier = Modifier
.fillMaxHeight(),
details = state.selectedDetails,
onEmailReceiptButtonClicked = onEmailReceiptButtonClicked
)
when {
state.selectedDetails != null -> {
WooPosOrderDetails(
modifier = Modifier
.fillMaxHeight(),
details = state.selectedDetails,
onEmailReceiptButtonClicked = onEmailReceiptButtonClicked
)
}
state.items is WooPosOrdersState.Content.Items.Searching -> {
OrderDetailsLoadingPane(
modifier = Modifier
.fillMaxHeight()
.padding(
start = WooPosSpacing.Medium.value,
end = WooPosSpacing.Medium.value,
top = WooPosSpacing.XLarge.value,
bottom = WooPosSpacing.XLarge.value
)
)
}
else -> {
WooPosEmptyScreen(
modifier = Modifier.fillMaxSize(),
icon = WooPosIcons.OrdersEmpty,
title = stringResource(R.string.woopos_orders_no_order_selected),
message = "",
contentDescription = stringResource(R.string.woopos_orders_empty_list_image_description)
)
}
}
}
}
}
Expand Down Expand Up @@ -637,6 +662,30 @@ fun WooPosOrdersNothingFoundStatePreview() {
}
}

@WooPosPreview
@Composable
fun WooPosOrdersEmptyStatePreview() {
WooPosTheme {
WooPosOrdersScreen(
state = WooPosOrdersState.Empty(
pullToRefreshState = WooPosPullToRefreshState.Enabled,
searchInputState = WooPosSearchInputState.Closed,
),
scrollToTopEvent = MutableSharedFlow(),
onBackClicked = {},
onRefresh = {},
onOrderSelected = {},
onEndOfOrdersListReached = {},
onPaginationErrorTryAgain = {},
onSearchEvent = {},
onSearchErrorRetry = {},
onOrdersEmptyActionClicked = {},
onOrdersLoadingErrorRetryButtonClicked = {},
onEmailReceiptButtonClicked = {}
)
}
}

@Suppress("MagicNumber")
private fun sampleOrderDetails(
id: Long = 1L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ sealed class WooPosOrdersState {
val items: Items,
override val pullToRefreshState: WooPosPullToRefreshState,
override val searchInputState: WooPosSearchInputState,
val selectedDetails: OrderDetailsViewState.Computed.Details,
val selectedDetails: OrderDetailsViewState.Computed.Details?,
val paginationState: WooPosPaginationState
) : WooPosOrdersState() {
sealed class Items {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class WooPosOrdersViewModel @Inject constructor(

private fun refreshSelectedOrder() {
val current = _state.value as? WooPosOrdersState.Content ?: return
val selectedOrderId = current.selectedDetails.id
val selectedOrderId = current.selectedDetails?.id ?: return

viewModelScope.launch {
ordersDataSource.refreshOrderById(selectedOrderId)
Expand Down Expand Up @@ -329,7 +329,7 @@ class WooPosOrdersViewModel @Inject constructor(
private fun performSearch(query: String, isRefreshing: Boolean = false) {
cancelJobs()

val currentSelectedDetails = (_state.value as? WooPosOrdersState.Content)?.selectedDetails!!
val currentSelectedDetails = (_state.value as? WooPosOrdersState.Content)?.selectedDetails
searchJob = viewModelScope.launch {
delay(SEARCH_DEBOUNCE_DELAY_MS)
if (!isRefreshing) {
Expand All @@ -355,7 +355,7 @@ class WooPosOrdersViewModel @Inject constructor(
),
pullToRefreshState = WooPosPullToRefreshState.Enabled,
searchInputState = _state.value.searchInputState,
selectedDetails = currentSelectedDetails,
selectedDetails = null,
paginationState = WooPosPaginationState.None
)
}
Expand All @@ -369,7 +369,7 @@ class WooPosOrdersViewModel @Inject constructor(
),
pullToRefreshState = WooPosPullToRefreshState.Enabled,
searchInputState = _state.value.searchInputState,
selectedDetails = currentSelectedDetails,
selectedDetails = null,
paginationState = WooPosPaginationState.None
)
} else {
Expand Down Expand Up @@ -453,7 +453,15 @@ class WooPosOrdersViewModel @Inject constructor(

val orders = ordersWithRefunds.keys.toList()
val newFirstOrderId = orders.firstOrNull()?.id
val newSelectedId = requireNotNull(newFirstOrderId) { "Content requires at least one order" }

val currentSelectedId = (currentState as? WooPosOrdersState.Content)?.selectedDetails?.id
val isSelectedOrderStillInList = currentSelectedId != null && orders.any { it.id == currentSelectedId }
val newSelectedId =
if (isSelectedOrderStillInList) {
currentSelectedId
} else {
requireNotNull(newFirstOrderId) { "Content requires at least one order" }
}
val items = buildItemsMap(ordersWithRefunds, newSelectedId)
val selectedEntry = items.entries.first { (item, _) -> item.isSelected }
val selectedDetails = when (val details = selectedEntry.value) {
Expand Down
1 change: 1 addition & 0 deletions WooCommerce/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3789,6 +3789,7 @@
<string name="woopos_orders_empty_list_message">Explore how you can increase your store sales.</string>
<string name="woopos_orders_empty_action_label">Learn more</string>
<string name="woopos_orders_empty_list_image_description">No orders</string>
<string name="woopos_orders_no_order_selected">No order selected.</string>
<string name="woopos_orders_loading_error_title">Unable to load orders</string>
<string name="woopos_orders_loading_error_message">Please check your connection try again.</string>
<string name="woopos_orders_loading_error_retry_button">Retry</string>
Expand Down
Loading