Skip to content

Commit

Permalink
Add option to update a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Oct 23, 2024
1 parent 13e82e2 commit 918ccd1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1254,14 +1254,12 @@ public final class io/getstream/chat/android/compose/ui/components/poll/Composab
public static field lambda-1 Lkotlin/jvm/functions/Function3;
public static field lambda-2 Lkotlin/jvm/functions/Function3;
public static field lambda-3 Lkotlin/jvm/functions/Function3;
public static field lambda-4 Lkotlin/jvm/functions/Function2;
public static field lambda-5 Lkotlin/jvm/functions/Function3;
public static field lambda-4 Lkotlin/jvm/functions/Function3;
public fun <init> ()V
public final fun getLambda-1$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
public final fun getLambda-2$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
public final fun getLambda-3$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
public final fun getLambda-4$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-5$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
public final fun getLambda-4$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
}

public final class io/getstream/chat/android/compose/ui/components/poll/ComposableSingletons$PollDialogHeaderKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private fun PollMessageContent(

if (showAddAnswerDialog.value) {
AddAnswerDialog(
initMessage = "",
onDismiss = { showAddAnswerDialog.value = false },
onNewAnswer = { newAnswer -> onAddAnswer.invoke(newAnswer) },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import androidx.compose.material.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -73,6 +75,8 @@ public fun PollAnswersDialog(
onDismissRequest: () -> Unit,
onBackPressed: () -> Unit,
) {
val user by listViewModel.user.collectAsState()
val currentUserAnswer = selectedPoll.poll.answers.firstOrNull { it.user?.id == user?.id }
val state = remember {
MutableTransitionState(false).apply {
// Start the animation immediately.
Expand All @@ -82,6 +86,7 @@ public fun PollAnswersDialog(
val showAddAnswerDialog = remember { mutableStateOf(false) }
if (showAddAnswerDialog.value) {
AddAnswerDialog(
initMessage = currentUserAnswer?.text ?: "",
onDismiss = { showAddAnswerDialog.value = false },
onNewAnswer = { newAnswer ->
listViewModel.castAnswer(selectedPoll.message, selectedPoll.poll, newAnswer)
Expand Down Expand Up @@ -127,6 +132,7 @@ public fun PollAnswersDialog(
answer = answer,
showAvatar = (poll.votingVisibility == VotingVisibility.PUBLIC) || showAnonymousAvatar,
)
Spacer(modifier = Modifier.height(8.dp))
}

item { Spacer(modifier = Modifier.height(16.dp)) }
Expand All @@ -153,7 +159,12 @@ public fun PollAnswersDialog(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 11.dp),
text = stringResource(id = R.string.stream_compose_add_answer),
text = stringResource(
id = when (currentUserAnswer == null) {
true -> R.string.stream_compose_add_answer
false -> R.string.stream_compose_edit_answer
},
),
textAlign = TextAlign.Center,
color = ChatTheme.colors.primaryAccent,
fontSize = 16.sp,
Expand Down Expand Up @@ -231,13 +242,23 @@ internal fun PollAnswersItem(

@Composable
internal fun AddAnswerDialog(
initMessage: String,
onDismiss: () -> Unit,
onNewAnswer: (newOption: String) -> Unit,
) {
val newOption = remember { mutableStateOf("") }
val newOption = remember { mutableStateOf(initMessage) }
val focusRequester = remember { FocusRequester() }
AlertDialog(
title = { Text(text = stringResource(R.string.stream_compose_add_answer)) },
title = {
Text(
text = stringResource(
when (initMessage.isBlank()) {
true -> R.string.stream_compose_add_answer
false -> R.string.stream_compose_edit_answer
},
),
)
},
text = {
InputField(
value = newOption.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<string name="stream_compose_poll_results" translatable="false">Poll Results</string>
<string name="stream_compose_poll_answers">Poll Comments</string>
<string name="stream_compose_add_answer">Add a Comment</string>
<string name="stream_compose_edit_answer">Update Comment</string>
<string name="stream_compose_poll_vote_counts" translatable="false">%d votes</string>
<string name="stream_compose_poll_created_preview" translatable="false">📊 Poll created: %s</string>
<string name="stream_compose_poll_closed_preview" translatable="false">📊 Poll closed: %s</string>
Expand Down

0 comments on commit 918ccd1

Please sign in to comment.