almost complete rework of ui up to module ui
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package dev.inmo.postssystem.services.posts.client
|
||||
|
||||
import dev.inmo.postssystem.features.auth.client.AuthorizedModuleLoader
|
||||
import dev.inmo.postssystem.features.auth.client.AuthorizedQualifiers
|
||||
import dev.inmo.postssystem.features.common.common.DefaultQualifiers
|
||||
import dev.inmo.postssystem.features.common.common.getAllDistinct
|
||||
import dev.inmo.postssystem.services.posts.client.ui.create.*
|
||||
import dev.inmo.postssystem.services.posts.common.*
|
||||
import org.koin.core.qualifier.Qualifier
|
||||
import org.koin.dsl.binds
|
||||
|
||||
val loader = AuthorizedModuleLoader {
|
||||
single<PostsService> { ClientPostsService(get(AuthorizedQualifiers.ServerUrlQualifier), get()) } binds arrayOf(
|
||||
ReadPostsService::class,
|
||||
WritePostsService::class
|
||||
)
|
||||
|
||||
factory<PostCreateUIModel> { DefaultPostCreateUIModel(get(), get()) }
|
||||
factory { PostCreateUIViewModel(get()) }
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package dev.inmo.postssystem.services.posts.client.ui.create
|
||||
|
||||
import dev.inmo.postssystem.features.common.common.AbstractUIModel
|
||||
import dev.inmo.postssystem.features.common.common.ui.AbstractUIModel
|
||||
import dev.inmo.postssystem.features.content.common.Content
|
||||
import dev.inmo.postssystem.publicators.simple.client.SimplePublicatorService
|
||||
import dev.inmo.postssystem.services.posts.common.FullNewPost
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package dev.inmo.postssystem.services.posts.client.ui.create
|
||||
|
||||
import dev.inmo.postssystem.features.common.common.UIModel
|
||||
import dev.inmo.postssystem.features.common.common.UIViewModel
|
||||
import dev.inmo.postssystem.features.common.common.ui.UIModel
|
||||
import dev.inmo.postssystem.features.common.common.ui.UIViewModel
|
||||
import dev.inmo.postssystem.features.content.common.Content
|
||||
|
||||
interface PostCreateUIModel : UIModel<PostCreateUIState>, UIViewModel<PostCreateUIState> {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package dev.inmo.postssystem.services.posts.client.ui.create
|
||||
|
||||
import dev.inmo.postssystem.features.common.common.*
|
||||
import dev.inmo.postssystem.features.common.common.ui.UIViewModel
|
||||
import dev.inmo.postssystem.features.content.common.Content
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
|
@@ -0,0 +1,102 @@
|
||||
package dev.inmo.postssystem.services.posts.client
|
||||
|
||||
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.coroutines.compose.renderComposableAndLinkToContextAndRoot
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.fsm.common.StatesMachine
|
||||
import dev.inmo.postssystem.features.auth.client.registerAfterAuthHandler
|
||||
import dev.inmo.postssystem.features.common.common.*
|
||||
import dev.inmo.postssystem.features.common.common.ui.JSView
|
||||
import dev.inmo.postssystem.features.common.common.ui.fsm.*
|
||||
import dev.inmo.postssystem.features.content.client.ContentClientProvider
|
||||
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.serialization.Serializable
|
||||
import org.jetbrains.compose.web.dom.Div
|
||||
import org.jetbrains.compose.web.dom.Text
|
||||
import org.w3c.dom.HTMLElement
|
||||
|
||||
val jsLoader = DefaultModuleLoader {
|
||||
factory { PostCreateView(get(), getAllDistinct(), get(DefaultQualifiers.UIScopeQualifier), getAllDistinct()) }
|
||||
|
||||
singleWithRandomQualifier<UIFSMHandler.Registrator> {
|
||||
UIFSMHandler.Registrator {
|
||||
registerAfterAuthHandler(getKoin(), PostCreateView::class)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CreatePostUIFSMState(
|
||||
override val from: UIFSMState? = null,
|
||||
override val context: String = "main"
|
||||
) : UIFSMState
|
||||
|
||||
class PostCreateView(
|
||||
private val createPostCreateUIModel: PostCreateUIViewModel,
|
||||
private val contentClientProviders: List<ContentClientProvider>,
|
||||
private val uiScope: CoroutineScope,
|
||||
defaultExceptionsHandlers: Iterable<UIFSMExceptionHandler>
|
||||
) : JSView<CreatePostUIFSMState>(defaultExceptionsHandlers) {
|
||||
override suspend fun StatesMachine<in UIFSMState>.safeHandleState(
|
||||
htmlElement: HTMLElement,
|
||||
state: CreatePostUIFSMState
|
||||
): UIFSMState? {
|
||||
val result = CompletableDeferred<UIFSMState?>()
|
||||
|
||||
val contentProvidersList = mutableStateListOf<Pair<ContentClientProvider, MutableState<Content?>>>()
|
||||
|
||||
renderComposableAndLinkToContextAndRoot(htmlElement) {
|
||||
Flex(
|
||||
UIKitFlex.Alignment.Horizontal.Center
|
||||
) {
|
||||
Div ({ include(UIKitWidth.Fixed.XLarge) }) {
|
||||
contentProvidersList.forEachIndexed { i, (provider, state) ->
|
||||
Flex(UIKitWidth.Expand) {
|
||||
provider.renderNewInstance(state)
|
||||
|
||||
DefaultButton("Remove") {
|
||||
contentProvidersList.removeAt(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
Label("Add content", Attrs.empty())
|
||||
Dropdown {
|
||||
DefaultNav {
|
||||
contentClientProviders.forEach {
|
||||
NavItemElement(
|
||||
attributesCustomizer = {
|
||||
onClick { _ ->
|
||||
val newContentState = mutableStateOf<Content?>(null)
|
||||
contentProvidersList.add(it to newContentState)
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(it.contentTypeNameForUser())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DefaultButton(
|
||||
"Upload",
|
||||
disabled = contentProvidersList.isEmpty()
|
||||
) {
|
||||
it.preventDefault()
|
||||
uiScope.launchSafelyWithoutExceptions {
|
||||
createPostCreateUIModel.create(
|
||||
contentProvidersList.mapNotNull { it.second.value }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.await()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user