temporal potentially working variant (bot not building
This commit is contained in:
@@ -14,9 +14,6 @@ val loader = AuthorizedModuleLoader {
|
||||
WritePostsService::class
|
||||
)
|
||||
|
||||
UIFSMStateSerializer.include("posts_create", PostsCreateUIFSMState.serializer())
|
||||
UIFSMStateSerializer.include("posts_list", PostsListUIFSMState.serializer())
|
||||
|
||||
factory<PostCreateUIModel> { DefaultPostCreateUIModel(get(), get()) }
|
||||
factory { PostCreateUIViewModel(get()) }
|
||||
}
|
||||
|
@@ -1,9 +1,7 @@
|
||||
package dev.inmo.postssystem.services.posts.client.ui.create
|
||||
|
||||
import dev.inmo.postssystem.features.common.common.ui.fsm.UIFSMState
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PostsCreateUIFSMState(
|
||||
override val from: UIFSMState? = null,
|
||||
override val context: String = "main"
|
||||
|
@@ -1,9 +1,7 @@
|
||||
package dev.inmo.postssystem.services.posts.client.ui.list
|
||||
|
||||
import dev.inmo.postssystem.features.common.common.ui.fsm.UIFSMState
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PostsListUIFSMState(
|
||||
override val from: UIFSMState? = null,
|
||||
override val context: String = "main"
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package dev.inmo.postssystem.services.posts.client.ui.list
|
||||
|
||||
import dev.inmo.postssystem.features.posts.common.Post
|
||||
import dev.inmo.postssystem.features.posts.common.RegisteredPostWithContent
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@@ -10,7 +10,7 @@ sealed class PostsListUIState {
|
||||
|
||||
@Serializable
|
||||
data class Show(
|
||||
val posts: List<Post>
|
||||
val posts: List<RegisteredPostWithContent>
|
||||
) : PostsListUIState()
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
package dev.inmo.postssystem.services.posts.client.ui.list
|
||||
|
||||
import dev.inmo.postssystem.features.common.common.ui.UIViewModel
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
class PostsListUIViewModel(
|
||||
private val model: PostsListUIModel
|
||||
) : UIViewModel<PostsListUIState> {
|
||||
override val currentState: StateFlow<PostsListUIState>
|
||||
get() = model.currentState
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
package dev.inmo.postssystem.services.posts.client
|
||||
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import dev.inmo.jsuikit.elements.*
|
||||
import dev.inmo.micro_utils.common.applyDiff
|
||||
import dev.inmo.micro_utils.coroutines.compose.renderComposableAndLinkToContextAndRoot
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
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.DateTimeView
|
||||
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.posts.common.RegisteredPostWithContent
|
||||
import dev.inmo.postssystem.services.posts.client.ui.create.PostsCreateUIFSMState
|
||||
import dev.inmo.postssystem.services.posts.client.ui.list.*
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.w3c.dom.HTMLElement
|
||||
|
||||
val postsListViewLoader = DefaultModuleLoader {
|
||||
factory { PostsListView(get(), getAllDistinct(), get(), getAllDistinct()) }
|
||||
|
||||
singleWithRandomQualifier <UIFSMHandler.Registrator> {
|
||||
UIFSMHandler.Registrator {
|
||||
registerAfterAuthHandler(getKoin(), PostsListView::class)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PostsListView(
|
||||
private val model: PostsListUIViewModel,
|
||||
private val contentClientProviders: List<ContentClientProvider>,
|
||||
private val uiScope: CoroutineScope,
|
||||
defaultExceptionsHandlers: Iterable<UIFSMExceptionHandler>
|
||||
) : JSView<PostsCreateUIFSMState>(defaultExceptionsHandlers) {
|
||||
override suspend fun StatesMachine<in UIFSMState>.safeHandleState(
|
||||
htmlElement: HTMLElement,
|
||||
state: PostsCreateUIFSMState
|
||||
): UIFSMState? {
|
||||
val result = CompletableDeferred<UIFSMState?>()
|
||||
|
||||
val loadingState = mutableStateOf(true)
|
||||
val postsState = mutableStateListOf<RegisteredPostWithContent>()
|
||||
|
||||
renderComposableAndLinkToContextAndRoot(htmlElement) {
|
||||
if (loadingState.value) {
|
||||
Spinner()
|
||||
} else {
|
||||
postsState.forEach {
|
||||
Card(
|
||||
header = {
|
||||
CardTitle {
|
||||
DateTimeView.Simple(it.post.creationDate)
|
||||
}
|
||||
Icon.App.Plus.drawAsButton {
|
||||
uiScope.launchSafelyWithoutExceptions {
|
||||
startChain(PostsCreateUIFSMState(state))
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
it.content.forEach {
|
||||
for (provider in contentClientProviders) {
|
||||
if (provider.renderPreview(it)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model.currentState.subscribeSafelyWithoutExceptions(uiScope) {
|
||||
loadingState.value = it == PostsListUIState.Loading
|
||||
when (it) {
|
||||
PostsListUIState.Loading -> {}
|
||||
is PostsListUIState.Show -> {
|
||||
postsState.applyDiff(it.posts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.await()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user