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
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 }
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) }
}
DropArea (
inputAttrs = InputAttrs {
onInput {
it.target.files ?.get(0) ?.let {
fileState.value = it
}
is BinaryContent -> {
DefaultButton(it.filename.name, UIKitWidth.Expand) {
selectFile {
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(
"Upload",
disabled = fileState.value == null || textContent.value.isBlank()
disabled = contentStatesList.isEmpty()
) {
it.preventDefault()
fileState.value ?.let { file ->
uiScope.launchSafelyWithoutExceptions {
createPostCreateUIModel.create(
listOf(
TextContent(
textContent.value
),
BinaryContent(
file.filename,
file.mimeType,
file.inputProvider()
)
)
contentStatesList.toList()
)
}
}
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-serialization = "1.3.2"
jsuikit = "0.0.42"
jsuikit = "0.0.43"
compose = "1.1.0"
microutils = "0.9.10"
microutils = "0.9.12"
tgbotapi = "0.38.6"
ktor = "1.6.7"
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