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 @@ -30,11 +30,12 @@ fun AdvancedFilterBottomSheet(
location: LocationFilter?,
date: DateFilter?
) -> Unit,
onReset: () -> Unit
onReset: () -> Unit,
initialDate: DateFilter? = null
) {
var selectedPrice by remember { mutableStateOf<PriceFilter?>(null) }
var selectedLocation by remember { mutableStateOf<LocationFilter?>(null) }
var selectedDate by remember { mutableStateOf<DateFilter?>(null) }
var selectedDate by remember { mutableStateOf(initialDate) }

ModalBottomSheet(
onDismissRequest = onDismiss,
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/cornellappdev/score/screen/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ fun HomeScreen(
sheetState = sheetState,
onDismiss = { showBottomSheet = false },
onApply = { price, location, date ->
// TODO: forward to ViewModel
homeViewModel.onDateFilterApplied(date)
},
onReset = {
// TODO: reset filters in ViewModel
}
homeViewModel.onFiltersReset()
},
initialDate = uiState.selectedDateFilter
)
}
}
Expand Down Expand Up @@ -171,12 +172,11 @@ private fun HomeLazyColumn(
text = "Game Schedule",
style = title,
)
//removed for 2/2026 release
// IconButton(
// icon = painterResource(id = R.drawable.advanced_filter),
// contentDescription = "Advanced filter",
// onClick = onAdvancedFilterClick
// )
IconButton(
icon = painterResource(id = R.drawable.advanced_filter),
contentDescription = "Advanced filter",
onClick = onAdvancedFilterClick
)
}
Spacer(modifier = Modifier.height(16.dp))
SportSelectorHeader(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cornellappdev.score.viewmodel

import com.cornellappdev.score.components.DateFilter
import com.cornellappdev.score.model.ApiResponse
import com.cornellappdev.score.model.GameCardData
import com.cornellappdev.score.model.GenderDivision
Expand All @@ -16,15 +17,24 @@ data class HomeUiState(
val selectedGender: GenderDivision,
val sportSelect: SportSelection,
val selectionList: List<SportSelection>,
val loadedState: ApiResponse<List<GameCardData>>
val loadedState: ApiResponse<List<GameCardData>>,
val selectedDateFilter: DateFilter? = null
) {
//TODO: refactor filters to use flows - not best practice to expose original games list to the view
val filteredGames: List<GameCardData>
get() = when (loadedState) {
is ApiResponse.Success -> loadedState.data.filter { game ->
(selectedGender == GenderDivision.ALL || game.gender == selectedGender.displayName) &&
(sportSelect is SportSelection.All ||
(sportSelect is SportSelection.SportSelect && game.sport == sportSelect.sport.displayName))
val genderMatch = selectedGender == GenderDivision.ALL || game.gender == selectedGender.displayName
val sportMatch = sportSelect is SportSelection.All ||
(sportSelect is SportSelection.SportSelect && game.sport == sportSelect.sport.displayName)
val dateMatch = when (selectedDateFilter) {
DateFilter.TODAY -> game.date == LocalDate.now()
DateFilter.WITHIN_7_DAYS -> game.date != null && !game.date.isAfter(LocalDate.now().plusDays(7))
DateFilter.WITHIN_A_MONTH -> game.date != null && !game.date.isAfter(LocalDate.now().plusDays(30))
DateFilter.OVER_A_MONTH -> game.date != null && game.date.isAfter(LocalDate.now().plusDays(30))
null -> true
}
genderMatch && sportMatch && dateMatch
}

ApiResponse.Loading -> emptyList()
Expand Down Expand Up @@ -91,4 +101,12 @@ class HomeViewModel @Inject constructor(
)
}
}

fun onDateFilterApplied(date: DateFilter?) {
applyMutation { copy(selectedDateFilter = date) }
}

fun onFiltersReset() {
applyMutation { copy(selectedDateFilter = null) }
}
}
Loading