refactor: observe pairingUrl state

This commit is contained in:
2026-06-10 18:38:15 +02:00
parent a121d40bbd
commit 2bc92fca06
3 changed files with 9 additions and 14 deletions
@@ -36,20 +36,9 @@ private class AddConnectionState {
var nextBudgetId by mutableIntStateOf(0)
var budgets by mutableStateOf(emptyList<BudgetDraft>())
// Converts the LocalDateTime expiry to a Unix epoch in seconds (#10)
// Converts the LocalDateTime expiry to a Unix epoch in seconds
fun expiryEpochSeconds(): Long =
expiry.atZone(ZoneId.systemDefault()).toEpochSecond()
fun reset() {
description = ""
selectedPermissions = ALL_PERMISSIONS.filter { it.default }.map { it.serverKey }.toSet()
neverExpires = false
expiry = LocalDateTime.now().plusDays(30).withSecond(0).withNano(0)
showDatePicker = false
showTimePicker = false
nextBudgetId = 0
budgets = emptyList()
}
}
// ── Sheet ─────────────────────────────────────────────────────────────────────
@@ -67,7 +56,7 @@ internal fun NwcAddConnectionSheet(
onDismiss : () -> Unit
) {
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val state = remember { AddConnectionState() } // #9
val state = remember { AddConnectionState() }
if (state.showDatePicker) {
val initialMillis = state.expiry
@@ -33,6 +33,12 @@ fun NwcScreen(
val refresh = { viewModel.loadConnections(includeExpired = true) }
LaunchedEffect(pairingUrl) {
if (pairingUrl != null) {
viewModel.closeAddSheet()
}
}
Scaffold(
topBar = {
TopAppBar(
@@ -120,7 +126,6 @@ fun NwcScreen(
expiresAt = expiresAt,
budgets = budgets
)
viewModel.closeAddSheet()
},
onDismiss = { viewModel.closeAddSheet() }
)