add default post create ui model

This commit is contained in:
InsanusMokrassar 2022-03-09 20:08:48 +06:00
parent 38cd186e60
commit d15ace3c49
3 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,25 @@
package dev.inmo.postssystem.services.posts.client.ui.create
import dev.inmo.postssystem.features.common.common.AbstractUIModel
import dev.inmo.postssystem.features.content.common.Content
import dev.inmo.postssystem.services.posts.common.FullNewPost
import dev.inmo.postssystem.services.posts.common.WritePostsService
class DefaultPostCreateUIModel(
private val postCreationService: WritePostsService
) : PostCreateUIModel, AbstractUIModel<PostCreateUIState>(
PostCreateUIState.Init
) {
override suspend fun create(content: List<Content>) {
runCatching {
_currentState.value = PostCreateUIState.Uploading
postCreationService.create(
FullNewPost(content)
)
}.onFailure {
_currentState.value = PostCreateUIState.Fail
}.onSuccess {
_currentState.value = PostCreateUIState.Completed
}
}
}

View File

@ -1,8 +1,9 @@
package dev.inmo.postssystem.services.posts.client.ui.create package dev.inmo.postssystem.services.posts.client.ui.create
import dev.inmo.postssystem.features.common.common.UIModel import dev.inmo.postssystem.features.common.common.UIModel
import dev.inmo.postssystem.features.common.common.UIViewModel
import dev.inmo.postssystem.features.content.common.Content import dev.inmo.postssystem.features.content.common.Content
interface PostCreateUIModel : UIModel<PostCreateUIState> { interface PostCreateUIModel : UIModel<PostCreateUIState>, UIViewModel<PostCreateUIState> {
suspend fun create(content: List<Content>) suspend fun create(content: List<Content>)
} }

View File

@ -9,6 +9,8 @@ sealed class PostCreateUIState {
@Serializable @Serializable
object Uploading : PostCreateUIState() object Uploading : PostCreateUIState()
@Serializable @Serializable
object Fail : PostCreateUIState()
@Serializable
object Completed : PostCreateUIState() object Completed : PostCreateUIState()
} }