now it is possible to publish different content based on web post created
This commit is contained in:
parent
369dcb12f5
commit
634d954465
@ -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) }) {
|
||||||
DropArea (
|
contentStatesList.forEachIndexed { i, it ->
|
||||||
inputAttrs = InputAttrs {
|
Flex(UIKitWidth.Expand) {
|
||||||
onInput {
|
when (it) {
|
||||||
it.target.files ?.get(0) ?.let {
|
is TextContent -> {
|
||||||
fileState.value = it
|
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("Add content")
|
||||||
DefaultButton(
|
Dropdown {
|
||||||
"Upload",
|
DefaultNav {
|
||||||
disabled = fileState.value == null || textContent.value.isBlank()
|
NavItemElement(
|
||||||
) {
|
attributesCustomizer = {
|
||||||
it.preventDefault()
|
onClick {
|
||||||
fileState.value ?.let { file ->
|
contentStatesList.add(TextContent(""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text("Text")
|
||||||
|
}
|
||||||
|
NavItemElement(
|
||||||
|
attributesCustomizer = {
|
||||||
|
onClick {
|
||||||
|
selectFile {
|
||||||
|
contentStatesList.add(it.binaryContent())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text("File")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DefaultButton(
|
||||||
|
"Upload",
|
||||||
|
disabled = contentStatesList.isEmpty()
|
||||||
|
) {
|
||||||
|
it.preventDefault()
|
||||||
uiScope.launchSafelyWithoutExceptions {
|
uiScope.launchSafelyWithoutExceptions {
|
||||||
createPostCreateUIModel.create(
|
createPostCreateUIModel.create(
|
||||||
listOf(
|
contentStatesList.toList()
|
||||||
TextContent(
|
|
||||||
textContent.value
|
|
||||||
),
|
|
||||||
BinaryContent(
|
|
||||||
file.filename,
|
|
||||||
file.mimeType,
|
|
||||||
file.inputProvider()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
|
)
|
@ -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"
|
||||||
|
13
idea/DefaultEntrance/EntranceKt.run.xml
Normal file
13
idea/DefaultEntrance/EntranceKt.run.xml
Normal 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
Loading…
Reference in New Issue
Block a user