Skip to content

Commit

Permalink
#11 [feat] : apply wishlist filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
yskim6772 committed Nov 28, 2024
1 parent 3c25614 commit 08e0f82
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -20,6 +23,11 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.example.market_kurly.core.base.BaseViewModelFactory
import com.example.market_kurly.core.util.KeyStorage.WISHLIST_CATEGORY_DAIRY_PRODUCT
import com.example.market_kurly.core.util.KeyStorage.WISHLIST_CATEGORY_FRUIT_NUTS_RICE
import com.example.market_kurly.core.util.KeyStorage.WISHLIST_CATEGORY_SIMPLE_PRODUCT
import com.example.market_kurly.core.util.KeyStorage.WISHLIST_CATEGORY_SNACK
import com.example.market_kurly.core.util.KeyStorage.WISHLIST_CATEGORY_TOTAL
import com.example.market_kurly.feature.wishlist.component.WishListFilteringTab
import com.example.market_kurly.feature.wishlist.component.WishListProduct
import com.example.market_kurly.feature.wishlist.component.WishListTopBar
Expand All @@ -34,10 +42,23 @@ fun WishListScreen(
val viewModel: WishListViewModel = viewModel(factory = BaseViewModelFactory())
val wishList by viewModel.wishListItems.collectAsStateWithLifecycle()

var selectedCategory by remember { mutableStateOf(WISHLIST_CATEGORY_TOTAL) }

LaunchedEffect(Unit) {
viewModel.getWishListData(memberId = 1)
}

val filteredWishList = remember(wishList, selectedCategory) {
when (selectedCategory) {
WISHLIST_CATEGORY_TOTAL -> wishList
WISHLIST_CATEGORY_DAIRY_PRODUCT -> wishList.filter { it.categoryScope == "DairyProduct" }
WISHLIST_CATEGORY_SIMPLE_PRODUCT -> wishList.filter { it.categoryScope == "convenience" }
WISHLIST_CATEGORY_FRUIT_NUTS_RICE -> wishList.filter { it.categoryScope == "FruitsNutsRice" }
WISHLIST_CATEGORY_SNACK -> wishList.filter { it.categoryScope == "SnacksRicecakes" }
else -> wishList
}
}

Column(
modifier = modifier
.fillMaxSize()
Expand All @@ -51,14 +72,14 @@ fun WishListScreen(

WishListFilteringTab(
modifier = modifier.fillMaxWidth(),
onClick = {}
onClick = { category -> selectedCategory = category }
)

LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(bottom = 16.dp)
) {
items(wishList) { wishListItem ->
items(filteredWishList) { wishListItem ->
WishListProduct(
name = wishListItem.name,
image = wishListItem.image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import okhttp3.internal.immutableListOf

@Composable
fun WishListFilteringTab(
onClick: () -> Unit,
onClick: (String) -> Unit,
modifier: Modifier = Modifier,
) {
val categoryMenus =
Expand Down Expand Up @@ -62,9 +62,12 @@ fun WishListFilteringTab(
FilterChip(
modifier = Modifier
.height(32.dp)
.noRippleClickable(onClick),
.noRippleClickable { onClick(category) },
selected = selectedCategory == category,
onClick = { selectedCategory = category },
onClick = {
selectedCategory = category
onClick(category)
},
label = {
Text(
text = category,
Expand Down

0 comments on commit 08e0f82

Please sign in to comment.