make it possible to connect modules in project
This commit is contained in:
client/src/jsMain/kotlin/dev/inmo/postssystem/client/fsm/ui
features/content
server
@ -4,7 +4,6 @@ import androidx.compose.runtime.*
|
||||
import dev.inmo.jsuikit.elements.*
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import dev.inmo.micro_utils.common.compose.DefaultDisposableEffectResult
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.fsm.common.StatesMachine
|
||||
import dev.inmo.postssystem.client.ui.fsm.CreatePostUIFSMState
|
||||
@ -15,7 +14,6 @@ import dev.inmo.postssystem.features.content.common.Content
|
||||
import dev.inmo.postssystem.services.posts.client.ui.create.PostCreateUIViewModel
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import org.jetbrains.compose.web.dom.Div
|
||||
import org.jetbrains.compose.web.dom.Text
|
||||
import org.w3c.dom.HTMLElement
|
||||
@ -31,27 +29,16 @@ class PostCreateView(
|
||||
): UIFSMState? {
|
||||
val result = CompletableDeferred<UIFSMState?>()
|
||||
|
||||
val contentProvidersList = mutableStateListOf<ContentClientProvider>()
|
||||
val statesList = mutableListOf<StateFlow<Content>>()
|
||||
val contentProvidersList = mutableStateListOf<Pair<ContentClientProvider, MutableState<Content?>>>()
|
||||
|
||||
renderComposableAndLinkToContext(htmlElement) {
|
||||
Flex(
|
||||
UIKitFlex.Alignment.Horizontal.Center
|
||||
) {
|
||||
Div ({ include(UIKitWidth.Fixed.XLarge) }) {
|
||||
contentProvidersList.forEachIndexed { i, renderer ->
|
||||
contentProvidersList.forEachIndexed { i, (provider, state) ->
|
||||
Flex(UIKitWidth.Expand) {
|
||||
Div(
|
||||
{
|
||||
ref {
|
||||
val flow = renderer.drawNewContent(it)
|
||||
statesList.add(i, flow)
|
||||
DefaultDisposableEffectResult {
|
||||
statesList.removeAt(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
provider.renderNewInstance(state)
|
||||
|
||||
DefaultButton("Remove") {
|
||||
contentProvidersList.removeAt(i)
|
||||
@ -65,7 +52,8 @@ class PostCreateView(
|
||||
NavItemElement(
|
||||
attributesCustomizer = {
|
||||
onClick { _ ->
|
||||
contentProvidersList.add(it)
|
||||
val newContentState = mutableStateOf<Content?>(null)
|
||||
contentProvidersList.add(it to newContentState)
|
||||
}
|
||||
}
|
||||
) {
|
||||
@ -81,7 +69,7 @@ class PostCreateView(
|
||||
it.preventDefault()
|
||||
uiScope.launchSafelyWithoutExceptions {
|
||||
createPostCreateUIModel.create(
|
||||
statesList.map { it.value }
|
||||
contentProvidersList.mapNotNull { it.second.value }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user