Skip to content

Commit

Permalink
Add click functionality to keyword chip
Browse files Browse the repository at this point in the history
  • Loading branch information
lneugebauer committed Jun 29, 2023
1 parent c3fa1aa commit 708b542
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ import de.lukasneugebauer.nextcloudcookbook.core.util.getActivity
import de.lukasneugebauer.nextcloudcookbook.core.util.notZero
import de.lukasneugebauer.nextcloudcookbook.core.util.openInBrowser
import de.lukasneugebauer.nextcloudcookbook.destinations.RecipeEditScreenDestination
import de.lukasneugebauer.nextcloudcookbook.destinations.RecipeListScreenDestination
import de.lukasneugebauer.nextcloudcookbook.recipe.domain.model.Recipe
import de.lukasneugebauer.nextcloudcookbook.recipe.domain.model.RecipeListFilter
import de.lukasneugebauer.nextcloudcookbook.recipe.presentation.components.Chip
import de.lukasneugebauer.nextcloudcookbook.recipe.presentation.components.CircleChip
import de.lukasneugebauer.nextcloudcookbook.recipe.util.emptyRecipe
Expand Down Expand Up @@ -168,6 +170,14 @@ fun RecipeDetailScreen(
modifier = Modifier
.padding(paddingValues = innerPadding)
.verticalScroll(rememberScrollState()),
onKeywordClick = { keyword ->
navigator.navigate(
RecipeListScreenDestination(
filterBy = keyword,
filterKind = RecipeListFilter.TAG,
),
)
},
)
}
}
Expand Down Expand Up @@ -275,14 +285,18 @@ private fun DropDownMenuItemDelete(onClick: () -> Unit) {
}

@Composable
private fun Content(recipe: Recipe, modifier: Modifier = Modifier) {
private fun Content(
recipe: Recipe,
modifier: Modifier = Modifier,
onKeywordClick: (tagName: String) -> Unit,
) {
Column(
modifier = modifier,
) {
Image(recipe.imageUrl, recipe.name)
Name(recipe.name)
if (recipe.keywords.isNotEmpty()) {
Keywords(recipe.keywords)
Keywords(recipe.keywords, onKeywordClick)
}
if (recipe.description.isNotBlank()) {
Description(recipe.description)
Expand Down Expand Up @@ -334,7 +348,7 @@ private fun Name(name: String) {
}

@Composable
private fun Keywords(keywords: List<String>) {
private fun Keywords(keywords: List<String>, onClick: (keyword: String) -> Unit) {
FlowRow(
modifier = Modifier
.padding(horizontal = dimensionResource(id = R.dimen.padding_m))
Expand All @@ -343,7 +357,9 @@ private fun Keywords(keywords: List<String>) {
crossAxisSpacing = dimensionResource(id = R.dimen.padding_s),
) {
keywords.forEach {
Chip(text = it)
Chip(text = it) {
onClick.invoke(it)
}
}
}
}
Expand Down Expand Up @@ -542,6 +558,6 @@ private fun ContentPreview() {
modifiedAt = "",
)
NextcloudCookbookTheme {
Content(recipe = recipe)
Content(recipe = recipe, onKeywordClick = {})
}
}

0 comments on commit 708b542

Please sign in to comment.