Skip to content

Commit

Permalink
Merge pull request #166 from cuappdev/Amy/small-ui-fixes
Browse files Browse the repository at this point in the history
Amy/small UI fixes
  • Loading branch information
amjiao authored Oct 23, 2024
2 parents d9128e4 + 18b20a2 commit 6290d8d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,20 @@ fun FilterRow(
item {
FilterButton(
onFilterClicked = {
onFilterClicked(Filter.UNDER_10)
onFilterClicked(Filter.SWIPES)
},
selected = currentFiltersSelected.contains(Filter.UNDER_10),
text = Filter.UNDER_10.text
selected = currentFiltersSelected.contains(Filter.SWIPES),
text = Filter.SWIPES.text
)
}

item {
FilterButton(
onFilterClicked = onPaymentMethodsClicked,
selected = paymentMethodFilters.isNotEmpty(),
text = paymentMethodFilterText,
icon = Icons.Default.ExpandMore
onFilterClicked = {
onFilterClicked(Filter.BRB)
},
selected = currentFiltersSelected.contains(Filter.BRB),
text = Filter.BRB.text
)
}

Expand All @@ -104,6 +105,16 @@ fun FilterRow(
)
}

item {
FilterButton(
onFilterClicked = {
onFilterClicked(Filter.UNDER_10)
},
selected = currentFiltersSelected.contains(Filter.UNDER_10),
text = Filter.UNDER_10.text
)
}

item {
Spacer(Modifier.width(16.dp))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fun HomeScreen(
) {
val context = LocalContext.current
val favorites = homeViewModel.favoriteEateries.collectAsState().value
val nearestEateries = homeViewModel.nearestEateries.collectAsState().value
val nearestEateries = homeViewModel.eateriesByDistance.collectAsState().value
val eateriesApiResponse = homeViewModel.eateryFlow.collectAsState().value
val filters = homeViewModel.filtersFlow.collectAsState().value

Expand Down Expand Up @@ -180,7 +180,11 @@ fun HomeScreen(
floatingActionButtonPosition = FabPosition.End,
content = { paddingValues ->

Box(modifier = Modifier.background(Color.White).padding(paddingValues)) {
Box(
modifier = Modifier
.background(Color.White)
.padding(paddingValues)
) {
ModalBottomSheetLayout(
sheetState = modalBottomSheetState,
sheetShape = RoundedCornerShape(
Expand Down Expand Up @@ -227,7 +231,6 @@ fun HomeScreen(
onSearchClick = onSearchClick,
onEateryClick = onEateryClick,
onFavoriteExpand = onFavoriteExpand,
onNearestExpand = onNearestExpand,
modalBottomSheetState = modalBottomSheetState,
eateriesApiResponse = eateriesApiResponse,
favorites = favorites,
Expand All @@ -254,7 +257,6 @@ fun HomeScreen(
}
)


if (FirstTimeShown.firstTimeShown) {
PermissionRequestDialog(
showBottomBar = showBottomBar,
Expand All @@ -281,7 +283,6 @@ private fun HomeScrollableMainContent(
onFavoriteClick: (Eatery, Boolean) -> Unit,
onFilterClicked: (Filter) -> Unit,
onResetFilters: () -> Unit,
onNearestExpand: () -> Unit,
modalBottomSheetState: ModalBottomSheetState,
eateriesApiResponse: EateryApiResponse<List<Eatery>>,
nearestEateries: List<Eatery>,
Expand All @@ -305,14 +306,6 @@ private fun HomeScrollableMainContent(
}


// A sneaky 6 dp tween.
val tweenHeight by animateFloatAsState(
targetValue = if (favorites.isEmpty()) 6f else 0f,
animationSpec = tween(600, delayMillis = 350),
label = "Sneaky tween"
)


LazyColumn(
state = listState,
modifier = Modifier
Expand Down Expand Up @@ -414,23 +407,6 @@ private fun HomeScrollableMainContent(
)
}


item {
// Sneaky spacer to make padding work right for favorites.
Spacer(modifier = Modifier.height(tweenHeight.dp))


EateryHomeSection(
title = "Nearest to You",
eateries = nearestEateries,
onEateryClick = onEateryClick,
onFavoriteClick = onFavoriteClick,
onExpandClick = onNearestExpand,
favoritesDecider = { favorites.contains(it) }
)
}


item {
Text(
modifier = Modifier
Expand All @@ -443,7 +419,7 @@ private fun HomeScrollableMainContent(


itemsIndexed(
eateries
nearestEateries
) { index, eatery ->
Box(
Modifier.padding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,18 @@ class HomeViewModel @Inject constructor(
}
}.stateIn(viewModelScope, SharingStarted.Eagerly, listOf())

/**
* A [StateFlow] that emits the 6 nearest eateries based on location.
/**A [StateFlow] that emits a list of all eateries sorted by nearest proximity
*
* Sorted (by descending priority): Open/Closed, Walk Time
*
* TODO: Walk times may not be updating automatically; may have to change location to use state.
*/

val nearestEateries: StateFlow<List<Eatery>> = eateryFlow.map { apiResponse ->
* TODO: (from old nearestEateries function) Walk times may not be updating automatically; may have to change location to use state.
* */
val eateriesByDistance: StateFlow<List<Eatery>> = eateryFlow.map { apiResponse ->
when (apiResponse) {
is EateryApiResponse.Error -> listOf()
is EateryApiResponse.Pending -> listOf()
is EateryApiResponse.Success -> {
apiResponse.data.sortedBy { it.getWalkTimes() }.sortedBy { it.isClosed() }
.let { nearestSorted ->
if (nearestSorted.size < 6) nearestSorted
else nearestSorted.slice(0..5)
}
}
}
}.stateIn(viewModelScope, SharingStarted.Eagerly, listOf())
Expand Down

0 comments on commit 6290d8d

Please sign in to comment.