Make the button to send problem enable, but show an error if the decription is too short to prevent users from being blocked.
This commit is contained in:
parent
d5bc611b75
commit
3e80629f6b
6 changed files with 40 additions and 4 deletions
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.rageshake.impl.bugreport
|
||||||
|
|
||||||
|
sealed class BugReportFormError: Exception() {
|
||||||
|
data object DescriptionTooShort : BugReportFormError()
|
||||||
|
}
|
||||||
|
|
@ -91,7 +91,13 @@ class BugReportPresenter @Inject constructor(
|
||||||
|
|
||||||
fun handleEvents(event: BugReportEvents) {
|
fun handleEvents(event: BugReportEvents) {
|
||||||
when (event) {
|
when (event) {
|
||||||
BugReportEvents.SendBugReport -> appCoroutineScope.sendBugReport(formState.value, crashInfo.isNotEmpty(), uploadListener)
|
BugReportEvents.SendBugReport -> {
|
||||||
|
if (formState.value.description.length < 10) {
|
||||||
|
sendingAction.value = AsyncAction.Failure(BugReportFormError.DescriptionTooShort)
|
||||||
|
} else {
|
||||||
|
appCoroutineScope.sendBugReport(formState.value, crashInfo.isNotEmpty(), uploadListener)
|
||||||
|
}
|
||||||
|
}
|
||||||
BugReportEvents.ResetAll -> appCoroutineScope.resetAll()
|
BugReportEvents.ResetAll -> appCoroutineScope.resetAll()
|
||||||
is BugReportEvents.SetDescription -> updateFormState(formState) {
|
is BugReportEvents.SetDescription -> updateFormState(formState) {
|
||||||
copy(description = event.description)
|
copy(description = event.description)
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,9 @@ data class BugReportState(
|
||||||
val sending: AsyncAction<Unit>,
|
val sending: AsyncAction<Unit>,
|
||||||
val eventSink: (BugReportEvents) -> Unit
|
val eventSink: (BugReportEvents) -> Unit
|
||||||
) {
|
) {
|
||||||
val submitEnabled =
|
val submitEnabled = sending !is AsyncAction.Loading
|
||||||
formState.description.length > 10 && sending !is AsyncAction.Loading
|
val isDescriptionInError = sending is AsyncAction.Failure &&
|
||||||
|
sending.error is BugReportFormError.DescriptionTooShort
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ open class BugReportStateProvider : PreviewParameterProvider<BugReportState> {
|
||||||
),
|
),
|
||||||
aBugReportState().copy(sending = AsyncAction.Loading),
|
aBugReportState().copy(sending = AsyncAction.Loading),
|
||||||
aBugReportState().copy(sending = AsyncAction.Success(Unit)),
|
aBugReportState().copy(sending = AsyncAction.Success(Unit)),
|
||||||
|
aBugReportState().copy(sending = AsyncAction.Failure(BugReportFormError.DescriptionTooShort)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ fun BugReportView(
|
||||||
imeAction = ImeAction.Next
|
imeAction = ImeAction.Next
|
||||||
),
|
),
|
||||||
minLines = 3,
|
minLines = 3,
|
||||||
// TODO Error text too short
|
isError = state.isDescriptionInError,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
@ -167,6 +167,12 @@ fun BugReportView(
|
||||||
eventSink(BugReportEvents.ResetAll)
|
eventSink(BugReportEvents.ResetAll)
|
||||||
onDone()
|
onDone()
|
||||||
},
|
},
|
||||||
|
errorMessage = { error ->
|
||||||
|
when (error) {
|
||||||
|
BugReportFormError.DescriptionTooShort -> stringResource(id = R.string.screen_bug_report_error_description_too_short)
|
||||||
|
else -> error.message ?: error.toString()
|
||||||
|
}
|
||||||
|
},
|
||||||
onErrorDismiss = { eventSink(BugReportEvents.ClearError) },
|
onErrorDismiss = { eventSink(BugReportEvents.ClearError) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
<string name="screen_bug_report_editor_description">"Please describe the problem. What did you do? What did you expect to happen? What actually happened. Please go into as much detail as you can."</string>
|
<string name="screen_bug_report_editor_description">"Please describe the problem. What did you do? What did you expect to happen? What actually happened. Please go into as much detail as you can."</string>
|
||||||
<string name="screen_bug_report_editor_placeholder">"Describe the problem…"</string>
|
<string name="screen_bug_report_editor_placeholder">"Describe the problem…"</string>
|
||||||
<string name="screen_bug_report_editor_supporting">"If possible, please write the description in English."</string>
|
<string name="screen_bug_report_editor_supporting">"If possible, please write the description in English."</string>
|
||||||
|
<string name="screen_bug_report_error_description_too_short">"The description is too short, please provide more details about what happened. Thanks!"</string>
|
||||||
<string name="screen_bug_report_include_crash_logs">"Send crash logs"</string>
|
<string name="screen_bug_report_include_crash_logs">"Send crash logs"</string>
|
||||||
<string name="screen_bug_report_include_logs">"Allow logs"</string>
|
<string name="screen_bug_report_include_logs">"Allow logs"</string>
|
||||||
<string name="screen_bug_report_include_screenshot">"Send screenshot"</string>
|
<string name="screen_bug_report_include_screenshot">"Send screenshot"</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue