Edit view opens the view's layout for editing (#59)

This commit is contained in:
makiolaj committed 2026-11-27 14:48:51 +01:00
1 parent 8abbe79ab6
commit 7fa244c3a0
3 files changed
+26 -1

No files matched your search

@@ -167,6 +167,8 @@ fun AgendulaNavHost(
EditViewScreen(
viewModel = vm,
onBack = { nav.popBackStack() },
// Home shows the view with its layout open, under whatever led here.
onEditLayout = { nav.popBackStack(Dest.LISTS, inclusive = false) },
)
}
}
@@ -13,6 +13,7 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ChevronRight
import androidx.compose.material.icons.rounded.Dashboard
import androidx.compose.material.icons.rounded.Delete
import androidx.compose.material.icons.rounded.FilterList
import androidx.compose.material.icons.rounded.PostAdd
@@ -30,6 +31,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
@@ -60,6 +62,7 @@ import de.jeanlucmakiola.floret.components.Position
fun EditViewScreen(
viewModel: EditViewViewModel,
onBack: () -> Unit,
onEditLayout: () -> Unit = {},
) {
val draft by viewModel.draft.collectAsStateWithLifecycle()
val listNames by viewModel.listNames.collectAsStateWithLifecycle()
@@ -120,11 +123,22 @@ fun EditViewScreen(
SettingsHint(stringResource(R.string.view_scope_blocks_hint))
GroupedSectionHeader(stringResource(R.string.view_section_layout))
// A new view has no layout stored to open yet.
if (!isNew) {
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) },
)
}
GroupedSwitchRow(
title = stringResource(R.string.view_quick_add),
checked = view.quickAdd,
onCheckedChange = viewModel::setQuickAdd,
position = Position.Alone,
position = if (isNew) Position.Alone else Position.Bottom,
summary = stringResource(R.string.view_quick_add_hint),
leading = { Icon(Icons.Rounded.PostAdd, contentDescription = null) },
)
@@ -123,6 +123,15 @@ class EditViewViewModel @Inject constructor(
}
}
/** Saves the view as [save] does, then shows it with its layout open for editing. */
fun saveAndEditLayout(onDone: () -> Unit) {
val id = _draft.value?.id?.takeIf { it > 0 } ?: return
save {
session.editLayout(id)
onDone()
}
}
fun delete(onDeleted: () -> Unit) {
val id = _draft.value?.id?.takeIf { it > 0 && it != View.HOME_ID } ?: return
viewModelScope.launch {