Martin Janči
05/21/2025, 3:15 PMArtem Kobzar
05/21/2025, 3:43 PMturansky
05/21/2025, 3:50 PMHTMLAttributes
+ selected
) but probably it’s not best solution in your caseturansky
05/21/2025, 3:53 PMexternal interface LayoutListItemProps : HTMLAttributes {
var selected: Boolean
}
val LayoutListItem = div.styled<LayoutListItemProps> { props ->
display = Display.flex
alignItems = AlignItems.center
justifyContent = JustifyContent.spaceBetween
padding(vertical = 8.px, horizontal = 24.px)
backgroundColor = if (props.selected) SharedStyles.darkColor else Color("white")
borderRadius = 6.px
fontSize = 1.rem
color = SharedStyles.darkColor
boxShadow = SharedStyles.shadows.small
}
turansky
05/21/2025, 3:56 PMPadding
factory function
padding = Padding(8.px, 24.px)
Martin Janči
05/21/2025, 3:59 PMexternal interface LayoutListItemProps : HTMLAttributes<HTMLDivElement> {
var selected: Boolean
}
val LayoutListItem2 = div.styled<LayoutListItemProps> { props ->
display = Display.flex
alignItems = AlignItems.center
justifyContent = JustifyContent.spaceBetween
padding = Padding(1.px, 32.px)
backgroundColor = if (props.selected) SharedStyles.darkColor else Color("white")
borderRadius = 6.px
fontSize = 1.rem
color = SharedStyles.darkColor
boxShadow = SharedStyles.shadows.small
}
Martin Janči
05/21/2025, 4:00 PMval LayoutSideBar = FC<LayoutSideBarProps> { props ->
val viewModel by reactKoin.inject<SideBarViewModel>()
val (items, setItems) = useState<List<LayoutItem>>(emptyList())
val scope = useMemo { CoroutineScope(Dispatchers.Default) }
var editingId by useState<Uuid?>(null)
var editingName by useState("")
var selectedId by useState<String?>(null)
useEffectRaw({
val job = scope.launch {
viewModel.layouts.collectLatest { latestList ->
setItems(latestList.map { layout -> LayoutItem(layout.id!!, layout.name) })
editingId = null
}
}
return@useEffectRaw {
job.cancel()
scope.cancel()
}
}, arrayOf(viewModel.layouts))
val LayoutListItem = div.styled {
display = Display.flex
alignItems = AlignItems.center
justifyContent = JustifyContent.spaceBetween
padding = Padding(8.px, 24.px)
backgroundColor = if (it.id == selectedId) SharedStyles.lightColor else Color("white")
borderRadius = 6.px
fontSize = 1.rem
color = SharedStyles.darkColor
boxShadow = SharedStyles.shadows.small
}
Is something else preffered? (but probably it’s not best solution in your case)turansky
05/21/2025, 4:07 PMMartin Janči
05/21/2025, 4:08 PMturansky
05/21/2025, 4:08 PMturansky
05/21/2025, 4:09 PMuseEffect
already do all cancellations on cleanupturansky
05/21/2025, 4:10 PMuseEffect(viewModel.layouts) {
viewModel.layouts.collectLatest { latestList ->
setItems(latestList.map { layout -> LayoutItem(layout.id!!, layout.name) })
editingId = null
}
}
}