Skip to content

Commit

Permalink
Fix error not being displayed on post creation failing (#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV-GH authored Feb 12, 2024
1 parent c7f3f9a commit f2f2665
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/src/main/java/com/jerboa/model/CreatePostViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jerboa.model

import android.content.Context
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand All @@ -8,6 +9,7 @@ import androidx.lifecycle.viewModelScope
import com.jerboa.api.API
import com.jerboa.api.ApiState
import com.jerboa.api.toApiState
import com.jerboa.ui.components.common.apiErrorToast
import it.vercruysse.lemmyapi.v0x19.datatypes.CreatePost
import it.vercruysse.lemmyapi.v0x19.datatypes.GetSiteMetadata
import it.vercruysse.lemmyapi.v0x19.datatypes.GetSiteMetadataResponse
Expand All @@ -23,6 +25,7 @@ class CreatePostViewModel : ViewModel() {

fun createPost(
form: CreatePost,
ctx: Context,
onSuccess: (postId: PostId) -> Unit,
) {
viewModelScope.launch {
Expand All @@ -33,6 +36,11 @@ class CreatePostViewModel : ViewModel() {
is ApiState.Success -> {
onSuccess(postRes.data.post_view.post.id)
}

is ApiState.Failure -> {
apiErrorToast(ctx, postRes.msg)
}

else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jerboa.ui.components.post.create

import android.content.Context
import android.net.Uri
import android.util.Log
import android.util.Patterns
Expand Down Expand Up @@ -138,6 +139,7 @@ fun CreatePostActivity(
body = body,
url = url,
isNsfw = isNsfw,
ctx = ctx,
createPostViewModel = createPostViewModel,
selectedCommunity = selectedCommunity,
onSuccess = appState::toPostWithPopUpTo,
Expand Down Expand Up @@ -212,6 +214,7 @@ fun CreatePostActivity(
fun onSubmitClick(
name: String,
body: TextFieldValue,
ctx: Context,
url: String,
isNsfw: Boolean,
selectedCommunity: Community?,
Expand All @@ -231,6 +234,7 @@ fun onSubmitClick(
body = bodyOut,
nsfw = isNsfw,
),
ctx = ctx,
onSuccess = onSuccess,
)
}
Expand Down

0 comments on commit f2f2665

Please sign in to comment.