Skip to content

Commit

Permalink
Fix deleting metadata in the example app
Browse files Browse the repository at this point in the history
  • Loading branch information
hichamboushaba committed Sep 9, 2024
1 parent 6fc4a04 commit b4061b6
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CustomFieldsViewModel(
parentItemType = parentItemType,
insertedMetadata = emptyList(),
updatedMetadata = emptyList(),
deletedMetadata = emptyList()
deletedMetadataIds = emptyList()
)
)

Expand All @@ -51,7 +51,7 @@ class CustomFieldsViewModel(
),
pendingUpdateRequest
) { customFields, pendingUpdateRequest ->
customFields.filterNot { it in pendingUpdateRequest.deletedMetadata }
customFields.filterNot { it.id in pendingUpdateRequest.deletedMetadataIds }
.map { field ->
pendingUpdateRequest.updatedMetadata.find { it.key == field.key }
?: field
Expand All @@ -64,7 +64,7 @@ class CustomFieldsViewModel(
pendingUpdateRequest.map {
it.insertedMetadata.isNotEmpty() ||
it.updatedMetadata.isNotEmpty() ||
it.deletedMetadata.isNotEmpty()
it.deletedMetadataIds.isNotEmpty()
}
) { loadingState, metaData, hasChanges ->
when (loadingState) {
Expand All @@ -74,7 +74,7 @@ class CustomFieldsViewModel(
onDelete = { field ->
pendingUpdateRequest.update {
it.copy(
deletedMetadata = it.deletedMetadata + field
deletedMetadataIds = it.deletedMetadataIds + field.id
)
}
},
Expand Down Expand Up @@ -136,7 +136,7 @@ class CustomFieldsViewModel(
it.copy(
insertedMetadata = emptyList(),
updatedMetadata = emptyList(),
deletedMetadata = emptyList()
deletedMetadataIds = emptyList()
)
}
loadingState.value = LoadingState.Loaded
Expand Down

0 comments on commit b4061b6

Please sign in to comment.