Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add the ability to filter on description field to the home page #810

Merged
merged 1 commit into from
Jan 24, 2025
Merged
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
33 changes: 32 additions & 1 deletion app/src/main/kotlin/br/com/colman/petals/navigation/Usage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ package br.com.colman.petals.navigation
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Icon
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
Expand All @@ -36,7 +40,10 @@ import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import br.com.colman.petals.R.string.filter_data_by_description_containing
import br.com.colman.petals.R.string.with_a_friend
import br.com.colman.petals.review.ReviewAppRequester
import br.com.colman.petals.use.AddUseButton
import br.com.colman.petals.use.LastUseDateTimer
Expand All @@ -46,7 +53,10 @@ import br.com.colman.petals.use.UseCards
import br.com.colman.petals.use.pause.PauseButton
import br.com.colman.petals.use.pause.repository.PauseRepository
import br.com.colman.petals.use.repository.UseRepository
import compose.icons.TablerIcons
import compose.icons.tablericons.ListSearch
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.map
import org.koin.compose.koinInject
import java.time.LocalTime
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -87,10 +97,31 @@ fun Usage(

PauseCards(pauseRepository)

val uses by useRepository.all().collectAsState(emptyList())
var descriptionContains by remember { mutableStateOf("") }
val uses by useRepository.all().map { uses ->
uses.filter {
it.description.contains(
descriptionContains,
true
)
}
}.collectAsState(emptyList())
if (uses.isNotEmpty()) {
StatsBlocks(uses)
UsageFilter(descriptionContains) { descriptionContains = it }
UseCards(uses, { useRepository.upsert(it) }, { useRepository.delete(it) })
}
}
}

@Composable
private fun UsageFilter(value: String, onValueChange: (String) -> Unit) {
OutlinedTextField(
value = value,
onValueChange = onValueChange,
modifier = Modifier.fillMaxWidth().padding(16.dp),
leadingIcon = { Icon(TablerIcons.ListSearch, null) },
label = { Text(stringResource(filter_data_by_description_containing)) },
placeholder = { Text(stringResource(with_a_friend)) }
)
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,6 @@
<string name="description_label">description</string>
<string name="description">Description</string>
<string name="because_i_wanted">Because I wanted to</string>
<string name="filter_data_by_description_containing">Filter data by description containing...</string>
<string name="with_a_friend">with a friend</string>
</resources>
Loading