Skip to content

Commit

Permalink
remove obsolete delete logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabtron committed Dec 23, 2024
1 parent 7772f64 commit 4b65adb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ fun ShoppingCartScreen(
},
onQuantityChanged = { item, quantity ->
viewModel.onEvent(UpdateQuantity(item, quantity))
},
onDeleteDepositReturnClick = {
viewModel.onEvent(RemoveDepositReturn(it))
}
)
}
Expand All @@ -60,7 +57,6 @@ private fun ShoppingCartScreen(
uiState: UiState,
modifier: Modifier = Modifier,
onItemDeleted: (ShoppingCart.Item) -> Unit,
onDeleteDepositReturnClick: (ShoppingCart.Item) -> Unit,
onQuantityChanged: (ShoppingCart.Item, Int) -> Unit
) {

Expand All @@ -82,7 +78,7 @@ private fun ShoppingCartScreen(

is DepositReturnItem -> {
val showHint = uiState.totalCartPrice != null && uiState.totalCartPrice < 0
DepositReturn(item = cartItem, showHint = showHint, onDeleteClick = onDeleteDepositReturnClick)
DepositReturn(item = cartItem, showHint = showHint, onDeleteClick = onItemDeleted)
}

is CartDiscountItem -> {
Expand Down Expand Up @@ -134,7 +130,6 @@ private fun CardWithDefaultItems() {
uiState = uiState,
onItemDeleted = {},
onQuantityChanged = { _, _ -> },
onDeleteDepositReturnClick = {}
)
}

Expand Down Expand Up @@ -164,7 +159,6 @@ private fun CardWithUserWeightedItems() {
uiState = uiState,
onItemDeleted = {},
onQuantityChanged = { _, _ -> },
onDeleteDepositReturnClick = {}
)
}

Expand Down Expand Up @@ -200,7 +194,6 @@ private fun CardWithDiscountItem() {
uiState = uiState,
onItemDeleted = {},
onQuantityChanged = { _, _ -> },
onDeleteDepositReturnClick = {}
)
}

Expand Down Expand Up @@ -235,7 +228,6 @@ private fun CardWithDeposit() {
uiState = uiState,
onItemDeleted = {},
onQuantityChanged = { _, _ -> },
onDeleteDepositReturnClick = {}
)
}

Expand Down Expand Up @@ -268,6 +260,5 @@ private fun CardWithCartDiscount() {
uiState = uiState,
onItemDeleted = {},
onQuantityChanged = { _, _ -> },
onDeleteDepositReturnClick = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ class ShoppingCartViewModel : ViewModel() {
when (event) {
is RemoveItem -> removeItemFromCart(event.item, event.onSuccess)
is UpdateQuantity -> updateQuantity(event.item, event.quantity)
is RemoveDepositReturn -> removeDepositReturnItem(event.item)
}
}

private fun removeDepositReturnItem(item: ShoppingCart.Item) {
val index = cachedCart.indexOf(item)
if (index != -1) {
cachedCart.remove(index)
}
}

Expand Down Expand Up @@ -99,15 +91,15 @@ class ShoppingCartViewModel : ViewModel() {

private fun MutableList<CartItem>.addDepositReturnItems(depositReturns: List<ShoppingCart.Item>) {
depositReturns.forEach { returnVoucher ->
val totalDepositReturn =
returnVoucher.depositReturnVoucher?.lineItems?.sumOf { it.totalPrice } ?: return@forEach
add(
DepositReturnItem(
item = returnVoucher,
totalDeposit = priceFormatter?.format(totalDepositReturn).orEmpty()
)
val totalDepositReturn =
returnVoucher.depositReturnVoucher?.lineItems?.sumOf { it.totalPrice } ?: return@forEach
add(
DepositReturnItem(
item = returnVoucher,
totalDeposit = priceFormatter?.format(totalDepositReturn).orEmpty()
)
}
)
}
}

private fun MutableList<CartItem>.sortCartDiscountsToBottom() {
Expand Down Expand Up @@ -253,10 +245,6 @@ class ShoppingCartViewModel : ViewModel() {

sealed interface Event

internal data class RemoveDepositReturn(
val item: ShoppingCart.Item,
) : Event

internal data class RemoveItem(
val item: ShoppingCart.Item,
val onSuccess: (index: Int) -> Unit
Expand Down

0 comments on commit 4b65adb

Please sign in to comment.