From 3182d2b5957bbc0286b430633a14092b5104b29a Mon Sep 17 00:00:00 2001 From: Thomas Andres Gomez Date: Tue, 1 Apr 2025 22:58:01 +0200 Subject: [PATCH] Small UI adjustment for the alteration edit GM. --- .../edit/GMAlterationEditFactory.kt | 40 ++++++++++--------- .../alteration/edit/GMAlterationEditPage.kt | 6 +-- .../edit/GMAlterationEditViewModel.kt | 13 +++--- .../ui/screen/gamemaster/common/tag/GMTag.kt | 2 +- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditFactory.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditFactory.kt index c06cae7..1bf238b 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditFactory.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditFactory.kt @@ -24,43 +24,45 @@ class GMAlterationEditFactory( alteration: Alteration?, tags: Collection, ): GMAlterationEditPageUio { - val id = MutableStateFlow(alteration?.id ?: "") - val label = MutableStateFlow(alteration?.metadata?.name ?: "") - val description = MutableStateFlow(alteration?.metadata?.description ?: "") - val fields = MutableStateFlow(alteration?.fields?.map { createField(it) } ?: listOf( - createField(null) - )) + val idFlow = MutableStateFlow(alteration?.id ?: "") + val labelFlow = MutableStateFlow(alteration?.metadata?.name ?: "") + val descriptionFlow = MutableStateFlow(alteration?.metadata?.description ?: "") + val tagFlow = MutableStateFlow( + tagFactory.convertToGMTagItemUio( + tags = tags, + selectedTagIds = alteration?.tags ?: emptyList(), + ) + ) + val fieldsFlow = MutableStateFlow(alteration?.fields?.map { createField(it) } + ?: listOf(createField(null))) return GMAlterationEditPageUio( id = LwaTextFieldUio( enable = originId == null, isError = MutableStateFlow(false), labelFlow = MutableStateFlow(getString(Res.string.game_master__alteration__edit_id)), - valueFlow = id, + valueFlow = idFlow, placeHolderFlow = null, - onValueChange = { id.value = it }, + onValueChange = { idFlow.value = it }, ), label = LwaTextFieldUio( enable = true, isError = MutableStateFlow(false), labelFlow = MutableStateFlow(getString(Res.string.game_master__alteration__edit_label)), - valueFlow = label, + valueFlow = labelFlow, placeHolderFlow = null, - onValueChange = { label.value = it }, + onValueChange = { labelFlow.value = it }, ), description = LwaTextFieldUio( enable = true, isError = MutableStateFlow(false), labelFlow = MutableStateFlow(getString(Res.string.game_master__alteration__edit_description)), - valueFlow = description, + valueFlow = descriptionFlow, placeHolderFlow = null, - onValueChange = { description.value = it }, + onValueChange = { descriptionFlow.value = it }, ), - tags = tagFactory.convertToGMTagItemUio( - tags = tags, - selectedTagIds = alteration?.tags ?: emptyList(), - ), - fields = fields, + tags = tagFlow, + fields = fieldsFlow, ) } @@ -102,7 +104,9 @@ class GMAlterationEditFactory( name = form.label.valueFlow.value, description = form.description.valueFlow.value, ), - tags = form.tags.filter { it.highlight }.map { it.id }, + tags = form.tags.value + .filter { it.highlight } + .map { it.id }, fields = form.fields.value.mapNotNull { field -> expressionParser.parse(input = field.expression.valueFlow.value)?.let { Alteration.Field( diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditPage.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditPage.kt index e07e731..bf0d269 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditPage.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditPage.kt @@ -53,7 +53,6 @@ import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.type import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import androidx.navigation.NavHostController import com.pixelized.desktop.lwa.ui.composable.error.ErrorSnackHandler import com.pixelized.desktop.lwa.ui.composable.key.KeyHandler @@ -82,7 +81,7 @@ data class GMAlterationEditPageUio( val id: LwaTextFieldUio, val label: LwaTextFieldUio, val description: LwaTextFieldUio, - val tags: List, + val tags: MutableStateFlow>, val fields: MutableStateFlow>, ) { @Stable @@ -210,6 +209,7 @@ private fun GMAlterationEditContent( ) else -> { + val tags = it.tags.collectAsState() val fields = it.fields.collectAsState() LazyColumn( @@ -266,7 +266,7 @@ private fun GMAlterationEditContent( horizontalArrangement = Arrangement.spacedBy(space = 8.dp), ) { items( - items = it.tags, + items = tags.value, ) { tag -> GMTagButton( modifier = Modifier.height(48.dp), diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditViewModel.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditViewModel.kt index aa27701..216f220 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/alteration/edit/GMAlterationEditViewModel.kt @@ -81,14 +81,13 @@ class GMAlterationEditViewModel( } fun addTag(tag: GMTagUio) { - _form.update { - it?.copy( - tags = it.tags.toMutableList().also { tags -> - val index = tags.indexOf(tag) - if (index > -1) - tags[index] = tag.copy(highlight = tag.highlight.not()) + _form.value?.tags?.update { tags -> + tags.toMutableList().also { + val index = it.indexOf(tag) + if (index > -1) { + it[index] = tag.copy(highlight = tag.highlight.not()) } - ) + } } } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/common/tag/GMTag.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/common/tag/GMTag.kt index f1d7b05..8fe5de8 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/common/tag/GMTag.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/screen/gamemaster/common/tag/GMTag.kt @@ -29,7 +29,7 @@ data class GMTagUio( @Stable object GmTagDefault { - val padding = PaddingValues(horizontal = 8.dp, vertical = 2.dp) + val padding = PaddingValues(horizontal = 8.dp, vertical = 4.dp) } @Composable