-
Notifications
You must be signed in to change notification settings - Fork 654
Profile photo not refreshing after upload in Client Profile #2519
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
base: development
Are you sure you want to change the base?
Changes from 14 commits
c91ad3d
1a1ae20
8dfdf65
749f570
c907031
586119e
83c574c
931df6e
503e411
4f00921
507ab52
b4fbffe
ca2f132
3289eb5
8007673
a8073d8
ee52926
24b4601
8e927b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,10 @@ import androidclient.feature.client.generated.resources.choose_from_option | |
| import androidclient.feature.client.generated.resources.delete_dialog_message | ||
| import androidclient.feature.client.generated.resources.delete_dialog_title | ||
| import androidclient.feature.client.generated.resources.delete_photo | ||
| import androidclient.feature.client.generated.resources.dialog_continue | ||
| import androidclient.feature.client.generated.resources.edit_profile_title | ||
| import androidclient.feature.client.generated.resources.feature_client_Image_Upload_Failed | ||
| import androidclient.feature.client.generated.resources.feature_client_Image_Upload_Successful | ||
| import androidclient.feature.client.generated.resources.from_camera | ||
| import androidclient.feature.client.generated.resources.from_gallery | ||
| import androidclient.feature.client.generated.resources.remove | ||
|
|
@@ -48,8 +51,10 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle | |
| import androidx.navigation.NavController | ||
| import com.mifos.core.designsystem.component.BasicDialogState | ||
| import com.mifos.core.designsystem.component.MifosBasicDialog | ||
| import com.mifos.core.designsystem.component.MifosDialogStatus | ||
| import com.mifos.core.designsystem.component.MifosOutlinedButton | ||
| import com.mifos.core.designsystem.component.MifosScaffold | ||
| import com.mifos.core.designsystem.component.MifosStatusDialog | ||
| import com.mifos.core.designsystem.component.MifosTextButton | ||
| import com.mifos.core.designsystem.icon.MifosIcons | ||
| import com.mifos.core.designsystem.theme.DesignToken | ||
|
|
@@ -76,14 +81,14 @@ internal fun ClientProfileEditScreen( | |
| ) { | ||
| val state by viewModel.stateFlow.collectAsStateWithLifecycle() | ||
|
|
||
| EventsEffect(viewModel.eventFlow) { event -> | ||
| /*EventsEffect(viewModel.eventFlow) { event -> | ||
| when (event) { | ||
| ClientProfileEditEvent.NavigateBack -> onNavigateBack() | ||
| ClientProfileEditEvent.OnSaveSuccess -> { | ||
| onNavigateBack() | ||
|
||
| } | ||
| } | ||
| } | ||
| }*/ | ||
|
|
||
| ClientProfileEditScaffold( | ||
| modifier = modifier, | ||
|
|
@@ -198,11 +203,18 @@ private fun ClientProfileEditDialogs( | |
| is ClientProfileEditState.DialogState.Loading -> MifosProgressIndicator() | ||
|
|
||
| is ClientProfileEditState.DialogState.Error -> { | ||
| MifosErrorComponent( | ||
| isNetworkConnected = state.networkConnection, | ||
| message = state.dialogState.message, | ||
| isRetryEnabled = true, | ||
| onRetry = onRetry, | ||
| MifosStatusDialog( | ||
| status = MifosDialogStatus.FAILURE, | ||
| message = stringResource(Res.string.feature_client_Image_Upload_Failed), | ||
| onDismissRequest = { onAction(ClientProfileEditAction.DismissModalBottomSheet) } | ||
| ) | ||
| } | ||
|
|
||
| is ClientProfileEditState.DialogState.Success -> { | ||
| MifosStatusDialog( | ||
| status = MifosDialogStatus.SUCCESS, | ||
| message = stringResource(Res.string.feature_client_profile_update_success_message), | ||
| onDismissRequest = { onAction(ClientProfileEditAction.DismissModalBottomSheet) } | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ import com.mifos.core.ui.util.BaseViewModel | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.mifos.core.ui.util.imageToByteArray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.mifos.core.ui.util.multipartRequestBody | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.mifos.feature.client.utils.toPlatformFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.delay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.flow.update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.launch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -123,6 +124,7 @@ internal class ClientProfileEditViewModel( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is DataState.Loading -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutableStateFlow.update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it.copy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -132,13 +134,22 @@ internal class ClientProfileEditViewModel( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is DataState.Success -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutableStateFlow.update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it.copy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dialogState = ClientProfileEditState.DialogState.Loading, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| openImagePicker = false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| viewModelScope.launch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clientDetailsRepo.getImage(route.id).collect { result -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when (result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is DataState.Success -> mutableStateFlow.update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it.copy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| profileImage = imageToByteArray(result.data), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dialogState = ClientProfileEditState.DialogState.Success, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is DataState.Loading -> mutableStateFlow.update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it.copy(dialogState = ClientProfileEditState.DialogState.Loading) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else -> Unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+138
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surface an error when the refresh fetch fails. Inside the success branch we collect when (result) {
is DataState.Success -> mutableStateFlow.update {
it.copy(
profileImage = imageToByteArray(result.data),
dialogState = ClientProfileEditState.DialogState.Success,
)
}
is DataState.Loading -> mutableStateFlow.update {
it.copy(dialogState = ClientProfileEditState.DialogState.Loading)
}
+ is DataState.Error -> mutableStateFlow.update {
+ it.copy(
+ dialogState = ClientProfileEditState.DialogState.Error(
+ result.message ?: "Unknown Error",
+ ),
+ )
+ }
else -> Unit📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| loadImage(route.id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -179,14 +190,18 @@ data class ClientProfileEditState( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sealed interface DialogState { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data class Error(val message: String) : DialogState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data object Loading : DialogState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data object Success : DialogState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data object ShowDeleteDialog : DialogState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data object ShowUploadOptions : DialogState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sealed interface ClientProfileEditEvent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data object NavigateBack : ClientProfileEditEvent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data object OnSaveSuccess : ClientProfileEditEvent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data class OnError(val message: String) : ClientProfileEditEvent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sealed interface ClientProfileEditAction { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added to feature:client's commonMain strings.xml (
android-client\feature\client\src\commonMain\composeResources\values\strings.xml)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay, I will do that and push it