now it is possible to publish different content based on web post created
This commit is contained in:
client/src/jsMain/kotlin/dev/inmo/postssystem/client/fsm/ui
features/content/common/src/jsMain/kotlin/dev/inmo/postssystem/features/content/common
gradle
idea/DefaultEntrance
server/src/main/resources/web
@ -1,26 +1,21 @@
|
||||
package dev.inmo.postssystem.client.fsm.ui
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import dev.inmo.jsuikit.elements.DefaultButton
|
||||
import dev.inmo.jsuikit.elements.DropArea
|
||||
import dev.inmo.jsuikit.utils.InputAttrs
|
||||
import dev.inmo.micro_utils.common.MPPFile
|
||||
import dev.inmo.micro_utils.common.filename
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import dev.inmo.jsuikit.elements.*
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.micro_utils.common.*
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.fsm.common.StatesMachine
|
||||
import dev.inmo.postssystem.client.ui.fsm.CreatePostUIFSMState
|
||||
import dev.inmo.postssystem.client.ui.fsm.UIFSMState
|
||||
import dev.inmo.postssystem.client.utils.renderComposableAndLinkToContext
|
||||
import dev.inmo.postssystem.features.common.common.*
|
||||
import dev.inmo.postssystem.features.content.common.BinaryContent
|
||||
import dev.inmo.postssystem.features.content.common.*
|
||||
import dev.inmo.postssystem.features.content.text.common.TextContent
|
||||
import dev.inmo.postssystem.services.posts.client.ui.create.PostCreateUIModel
|
||||
import dev.inmo.postssystem.services.posts.client.ui.create.PostCreateUIViewModel
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLElement
|
||||
import org.w3c.files.get
|
||||
|
||||
class PostCreateView(
|
||||
private val createPostCreateUIModel: PostCreateUIViewModel,
|
||||
@ -32,46 +27,71 @@ class PostCreateView(
|
||||
): UIFSMState? {
|
||||
val result = CompletableDeferred<UIFSMState?>()
|
||||
|
||||
val textContent = mutableStateOf("")
|
||||
val fileState = mutableStateOf<MPPFile?>(null)
|
||||
val contentStatesList = mutableStateListOf<Content>()
|
||||
|
||||
renderComposableAndLinkToContext(htmlElement) {
|
||||
Form {
|
||||
TextArea(textContent.value) {
|
||||
onInput { textContent.value = it.value }
|
||||
}
|
||||
DropArea (
|
||||
inputAttrs = InputAttrs {
|
||||
onInput {
|
||||
it.target.files ?.get(0) ?.let {
|
||||
fileState.value = it
|
||||
Flex(
|
||||
UIKitFlex.Alignment.Horizontal.Center
|
||||
) {
|
||||
Div({ include(UIKitWidth.Fixed.XLarge) }) {
|
||||
contentStatesList.forEachIndexed { i, it ->
|
||||
Flex(UIKitWidth.Expand) {
|
||||
when (it) {
|
||||
is TextContent -> {
|
||||
TextArea(it.text) {
|
||||
include(UIKitWidth.Expand)
|
||||
onInput { contentStatesList[i] = TextContent(it.value) }
|
||||
}
|
||||
}
|
||||
is BinaryContent -> {
|
||||
DefaultButton(it.filename.name, UIKitWidth.Expand) {
|
||||
selectFile {
|
||||
contentStatesList[i] = it.binaryContent()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DefaultButton("Remove") {
|
||||
contentStatesList.removeAt(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
DefaultButton(
|
||||
"Upload",
|
||||
disabled = fileState.value == null || textContent.value.isBlank()
|
||||
) {
|
||||
it.preventDefault()
|
||||
fileState.value ?.let { file ->
|
||||
DefaultButton("Add content")
|
||||
Dropdown {
|
||||
DefaultNav {
|
||||
NavItemElement(
|
||||
attributesCustomizer = {
|
||||
onClick {
|
||||
contentStatesList.add(TextContent(""))
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text("Text")
|
||||
}
|
||||
NavItemElement(
|
||||
attributesCustomizer = {
|
||||
onClick {
|
||||
selectFile {
|
||||
contentStatesList.add(it.binaryContent())
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text("File")
|
||||
}
|
||||
}
|
||||
}
|
||||
DefaultButton(
|
||||
"Upload",
|
||||
disabled = contentStatesList.isEmpty()
|
||||
) {
|
||||
it.preventDefault()
|
||||
uiScope.launchSafelyWithoutExceptions {
|
||||
createPostCreateUIModel.create(
|
||||
listOf(
|
||||
TextContent(
|
||||
textContent.value
|
||||
),
|
||||
BinaryContent(
|
||||
file.filename,
|
||||
file.mimeType,
|
||||
file.inputProvider()
|
||||
)
|
||||
)
|
||||
|
||||
contentStatesList.toList()
|
||||
)
|
||||
}
|
||||
}
|
||||
console.log("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user