now it is possible to publish different content based on web post created

This commit is contained in:
InsanusMokrassar 2022-03-12 01:44:41 +06:00
parent 369dcb12f5
commit 634d954465
5 changed files with 88 additions and 43 deletions

View File

@ -1,26 +1,21 @@
package dev.inmo.postssystem.client.fsm.ui package dev.inmo.postssystem.client.fsm.ui
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateListOf
import dev.inmo.jsuikit.elements.DefaultButton import dev.inmo.jsuikit.elements.*
import dev.inmo.jsuikit.elements.DropArea import dev.inmo.jsuikit.modifiers.*
import dev.inmo.jsuikit.utils.InputAttrs import dev.inmo.micro_utils.common.*
import dev.inmo.micro_utils.common.MPPFile
import dev.inmo.micro_utils.common.filename
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
import dev.inmo.micro_utils.fsm.common.StatesMachine import dev.inmo.micro_utils.fsm.common.StatesMachine
import dev.inmo.postssystem.client.ui.fsm.CreatePostUIFSMState import dev.inmo.postssystem.client.ui.fsm.CreatePostUIFSMState
import dev.inmo.postssystem.client.ui.fsm.UIFSMState import dev.inmo.postssystem.client.ui.fsm.UIFSMState
import dev.inmo.postssystem.client.utils.renderComposableAndLinkToContext import dev.inmo.postssystem.client.utils.renderComposableAndLinkToContext
import dev.inmo.postssystem.features.common.common.* import dev.inmo.postssystem.features.content.common.*
import dev.inmo.postssystem.features.content.common.BinaryContent
import dev.inmo.postssystem.features.content.text.common.TextContent 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 dev.inmo.postssystem.services.posts.client.ui.create.PostCreateUIViewModel
import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import org.jetbrains.compose.web.dom.* import org.jetbrains.compose.web.dom.*
import org.w3c.dom.HTMLElement import org.w3c.dom.HTMLElement
import org.w3c.files.get
class PostCreateView( class PostCreateView(
private val createPostCreateUIModel: PostCreateUIViewModel, private val createPostCreateUIModel: PostCreateUIViewModel,
@ -32,46 +27,71 @@ class PostCreateView(
): UIFSMState? { ): UIFSMState? {
val result = CompletableDeferred<UIFSMState?>() val result = CompletableDeferred<UIFSMState?>()
val textContent = mutableStateOf("") val contentStatesList = mutableStateListOf<Content>()
val fileState = mutableStateOf<MPPFile?>(null)
renderComposableAndLinkToContext(htmlElement) { renderComposableAndLinkToContext(htmlElement) {
Form { Flex(
TextArea(textContent.value) { UIKitFlex.Alignment.Horizontal.Center
onInput { textContent.value = it.value } ) {
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) }
} }
DropArea ( }
inputAttrs = InputAttrs { is BinaryContent -> {
onInput { DefaultButton(it.filename.name, UIKitWidth.Expand) {
it.target.files ?.get(0) ?.let { selectFile {
fileState.value = it contentStatesList[i] = it.binaryContent()
}
}
}
}
DefaultButton("Remove") {
contentStatesList.removeAt(i)
}
}
}
DefaultButton("Add content")
Dropdown {
DefaultNav {
NavItemElement(
attributesCustomizer = {
onClick {
contentStatesList.add(TextContent(""))
}
}
) {
Text("Text")
}
NavItemElement(
attributesCustomizer = {
onClick {
selectFile {
contentStatesList.add(it.binaryContent())
}
}
}
) {
Text("File")
} }
} }
} }
)
DefaultButton( DefaultButton(
"Upload", "Upload",
disabled = fileState.value == null || textContent.value.isBlank() disabled = contentStatesList.isEmpty()
) { ) {
it.preventDefault() it.preventDefault()
fileState.value ?.let { file ->
uiScope.launchSafelyWithoutExceptions { uiScope.launchSafelyWithoutExceptions {
createPostCreateUIModel.create( createPostCreateUIModel.create(
listOf( contentStatesList.toList()
TextContent(
textContent.value
),
BinaryContent(
file.filename,
file.mimeType,
file.inputProvider()
)
)
) )
} }
} }
console.log("")
} }
} }
} }

View File

@ -0,0 +1,12 @@
package dev.inmo.postssystem.features.content.common
import dev.inmo.micro_utils.common.MPPFile
import dev.inmo.micro_utils.common.filename
import dev.inmo.postssystem.features.common.common.inputProvider
import dev.inmo.postssystem.features.common.common.mimeType
fun MPPFile.binaryContent() = BinaryContent(
filename,
mimeType,
inputProvider()
)

View File

@ -2,9 +2,9 @@
kotlin = "1.6.10" kotlin = "1.6.10"
kotlin-serialization = "1.3.2" kotlin-serialization = "1.3.2"
jsuikit = "0.0.42" jsuikit = "0.0.43"
compose = "1.1.0" compose = "1.1.0"
microutils = "0.9.10" microutils = "0.9.12"
tgbotapi = "0.38.6" tgbotapi = "0.38.6"
ktor = "1.6.7" ktor = "1.6.7"
klock = "2.6.1" klock = "2.6.1"

View File

@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="true" name="EntranceKt" type="JetRunConfigurationType" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="dev.inmo.postssystem.server.EntranceKt" />
<module name="postssystem.postssystem.server.main" />
<option name="PROGRAM_PARAMETERS" value="$PROJECT_DIR$/server/local.config.json" />
<shortenClasspath name="NONE" />
<method v="2">
<option name="Gradle.BeforeRunTask" enabled="true" tasks="build" externalProjectPath="$PROJECT_DIR$/client" vmOptions="" scriptParameters="" />
<option name="Gradle.BeforeRunTask" enabled="true" tasks="copyClient" externalProjectPath="$PROJECT_DIR$/server" vmOptions="" scriptParameters="" />
<option name="Gradle.BeforeRunTask" enabled="true" tasks="build" externalProjectPath="$PROJECT_DIR$/server" vmOptions="" scriptParameters="" />
</method>
</configuration>
</component>

File diff suppressed because one or more lines are too long