feat: implement soft delete for fields and clear items if last field is removed

This commit is contained in:
2025-11-12 00:03:39 +01:00
parent 532e0ff459
commit cb5880f861
@@ -207,7 +207,15 @@ class ListDetailViewModel(
viewModelScope.launch { viewModelScope.launch {
val ts = System.currentTimeMillis() val ts = System.currentTimeMillis()
database.withTransaction { database.withTransaction {
// Soft delete the field
database.fieldDao().softDeleteField(fieldId, ts) database.fieldDao().softDeleteField(fieldId, ts)
// Determine remaining active fields by consulting the current state flow (already up-to-date via collector)
// Fields state already excludes soft-deleted ones (query filters isDeleted = 0), so just check size after removal
val remainingFields = _fields.value
if (remainingFields.isEmpty()) {
// Last column deleted: soft-delete all items for this list to clear table content
database.itemDao().softDeleteItemsByList(listId, ts)
}
database.listDao().getListById(listId)?.let { l -> database.listDao().getListById(listId)?.let { l ->
database.listDao().updateList(l.copy(updatedAt = ts)) database.listDao().updateList(l.copy(updatedAt = ts))
} }