add default post create ui model
This commit is contained in:
parent
38cd186e60
commit
d15ace3c49
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
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.content.common.Content
|
||||
|
||||
interface PostCreateUIModel : UIModel<PostCreateUIState> {
|
||||
interface PostCreateUIModel : UIModel<PostCreateUIState>, UIViewModel<PostCreateUIState> {
|
||||
suspend fun create(content: List<Content>)
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ sealed class PostCreateUIState {
|
||||
@Serializable
|
||||
object Uploading : PostCreateUIState()
|
||||
@Serializable
|
||||
object Fail : PostCreateUIState()
|
||||
@Serializable
|
||||
object Completed : PostCreateUIState()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user