Edit view's Edit layout waits for a name and skips a deleted view (#59)

This commit is contained in:
makiolaj committed 2026-11-27 15:11:41 +01:00
1 parent 70a70c327c
commit 2a63487c08
2 files changed
+9 -3

No files matched your search

@@ -125,13 +125,16 @@ fun EditViewScreen(
GroupedSectionHeader(stringResource(R.string.view_section_layout))
// A new view has no layout stored to open yet.
if (!isNew) {
// Opening it saves the view first, which a blank name can't be.
val canSave = view.id == View.HOME_ID || view.name.isNotBlank()
GroupedRow(
title = stringResource(R.string.view_edit_layout),
summary = pluralStringResource(R.plurals.view_blocks, view.blocks.size, view.blocks.size),
position = Position.Top,
leading = { Icon(Icons.Rounded.Dashboard, contentDescription = null) },
trailing = { Icon(Icons.Rounded.ChevronRight, contentDescription = null) },
onClick = { viewModel.saveAndEditLayout(onEditLayout) },
dimmed = !canSave,
onClick = if (canSave) ({ viewModel.saveAndEditLayout(onEditLayout) }) else null,
)
}
GroupedSwitchRow(
@@ -127,8 +127,11 @@ class EditViewViewModel @Inject constructor(
fun saveAndEditLayout(onDone: () -> Unit) {
val id = _draft.value?.id?.takeIf { it > 0 } ?: return
save {
session.editLayout(id)
onDone()
viewModelScope.launch {
// A view deleted while this was open stays deleted; there is no layout to open.
if (settingsPrefs.views.first().any { it.id == id }) session.editLayout(id)
onDone()
}
}
}