Skip to content

Commit

Permalink
feat: save SwitchConfigurator state in datastore
Browse files Browse the repository at this point in the history
Change-Id: I4088a94aceb87eafcd296b1d62faba20e02757ab
  • Loading branch information
Theo Bertacchini committed Aug 10, 2023
1 parent ea34e53 commit df14679
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import com.adevinta.spark.catalog.datastore.switchconfigurator.SwitchConfigurato
import com.adevinta.spark.catalog.model.Configurator
import com.adevinta.spark.catalog.themes.SegmentedButton
import com.adevinta.spark.catalog.util.SampleSourceUrl
import com.adevinta.spark.catalog.util.safeEnumValueOf
import com.adevinta.spark.components.menu.DropdownMenuItem
import com.adevinta.spark.components.text.Text
import com.adevinta.spark.components.textfields.SelectTextField
Expand Down Expand Up @@ -96,18 +95,8 @@ private fun SwitchSample() {
var label: String? by remember { mutableStateOf(null) }
val isEnabled: Boolean = remember(key1 = properties.isEnabled, calculation = properties::isEnabled)
val isSwitched: Boolean = remember(key1 = properties.isSwitched, calculation = properties::isSwitched)
val contentSide: ContentSide = remember(key1 = properties.contentSide) {
safeEnumValueOf(
name = properties.contentSide,
default = ContentSide.valueOf(SwitchConfiguratorProperties.DEFAULT.contentSide),
)
}
val intent: ToggleIntent = remember(key1 = properties.intent) {
safeEnumValueOf(
name = properties.intent,
default = ToggleIntent.valueOf(SwitchConfiguratorProperties.DEFAULT.intent),
)
}
val contentSide: ContentSide = remember(key1 = properties.contentSide, calculation = properties::contentSide)
val intent: ToggleIntent = remember(key1 = properties.intent, calculation = properties::intent)

val onClick = { checked: Boolean ->
updateProperties { properties -> properties.copy(isSwitched = checked) }
Expand Down Expand Up @@ -148,7 +137,7 @@ private fun SwitchSample() {
DropdownMenuItem(
text = { Text(it.name) },
onClick = {
updateProperties { properties -> properties.copy(intent = it.name) }
updateProperties { properties -> properties.copy(intent = it) }
expanded = false
},
)
Expand All @@ -167,7 +156,7 @@ private fun SwitchSample() {
options = contentSidesLabel,
selectedOption = contentSide.name,
onOptionSelect = {
updateProperties { properties -> properties.copy(contentSide = ContentSide.valueOf(it).name) }
updateProperties { properties -> properties.copy(contentSide = ContentSide.valueOf(it)) }
focusManager.clearFocus()
},
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@
*/
package com.adevinta.spark.catalog.datastore.switchconfigurator

import com.adevinta.spark.components.toggles.ContentSide
import com.adevinta.spark.components.toggles.ToggleIntent
import kotlinx.serialization.Serializable

@Serializable
internal data class SwitchConfiguratorProperties(
val isEnabled: Boolean,
val contentSide: String,
val isSwitched: Boolean,
val intent: String,
val intent: ToggleIntent,
val contentSide: ContentSide,
) {
companion object {
val DEFAULT = SwitchConfiguratorProperties(
isEnabled = true,
isSwitched = false,
contentSide = "End",
intent = "Main",
intent = ToggleIntent.Main,
contentSide = ContentSide.End,
)
}
}

0 comments on commit df14679

Please sign in to comment.