Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error not being displayed on post creation failing #1374

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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