mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
feat(folio): show current balance on the add-transaction screen
renders the account's balance (testTag TxnCurrentBalance) below the account name, above the credit/debit toggle, so before/after screenshots carry comparison data.
This commit is contained in:
1 parent
133ce17d72
commit
e6b9f6db3c
2 files changed
+23
-2
No files matched your search
+14
@@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -15,10 +16,12 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import app.folio.core.data.TxnType
|
||||
import app.folio.di.LocalAppGraph
|
||||
import app.folio.util.formatCents
|
||||
import app.folio.ui.BackHandler
|
||||
import app.folio.ui.component.AppButton
|
||||
import app.folio.ui.component.BackButton
|
||||
import app.folio.ui.component.ButtonStyle
|
||||
import app.folio.ui.component.Card
|
||||
import app.folio.ui.component.EmptyState
|
||||
import app.folio.ui.component.ErrorText
|
||||
import app.folio.ui.component.FieldLabel
|
||||
@@ -26,6 +29,7 @@ import app.folio.ui.component.Header
|
||||
import app.folio.ui.component.Screen
|
||||
import app.folio.ui.component.Segmented
|
||||
import app.folio.ui.component.TextInput
|
||||
import app.folio.ui.theme.LocalTokens
|
||||
import app.folio.ui.theme.Type
|
||||
|
||||
@Composable
|
||||
@@ -78,10 +82,20 @@ fun AddTransactionScreen(state: AddTransactionUiState, onEvent: (AddTransactionE
|
||||
)
|
||||
},
|
||||
) {
|
||||
val t = LocalTokens.current
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
Card {
|
||||
Text("CURRENT BALANCE", style = Type.label, color = t.textMuted)
|
||||
Text(
|
||||
formatCents(state.balanceCents),
|
||||
style = Type.balance,
|
||||
color = t.text,
|
||||
modifier = Modifier.testTag("TxnCurrentBalance"),
|
||||
)
|
||||
}
|
||||
Segmented(
|
||||
selected = if (state.type == TxnType.credit) 0 else 1,
|
||||
labels = listOf("Credit", "Debit"),
|
||||
|
||||
+9
-2
@@ -7,6 +7,7 @@ import app.folio.core.data.Repository
|
||||
import app.folio.core.data.TxnType
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import app.folio.util.balanceOf
|
||||
import app.folio.util.parseCents
|
||||
import dev.zacsweers.metro.Assisted
|
||||
import dev.zacsweers.metro.AssistedFactory
|
||||
@@ -24,6 +25,7 @@ private val AMOUNT_REGEX = Regex("""^\d*(\.\d{0,2})?$""")
|
||||
|
||||
data class AddTransactionUiState(
|
||||
val account: Account? = null,
|
||||
val balanceCents: Long = 0,
|
||||
val type: TxnType = TxnType.credit,
|
||||
val amount: String = "",
|
||||
val note: String = "",
|
||||
@@ -50,8 +52,13 @@ class AddTransactionViewModel(
|
||||
val state: StateFlow<AddTransactionUiState> = combine(
|
||||
form,
|
||||
repository.accounts.map { accounts -> accounts.firstOrNull { it.id == accountId } },
|
||||
) { f, account -> f.copy(account = account) }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, AddTransactionUiState())
|
||||
repository.transactions,
|
||||
) { f, account, transactions ->
|
||||
f.copy(
|
||||
account = account,
|
||||
balanceCents = balanceOf(transactions.filter { it.accountId == accountId }),
|
||||
)
|
||||
}.stateIn(viewModelScope, SharingStarted.Eagerly, AddTransactionUiState())
|
||||
|
||||
fun onEvent(event: AddTransactionEvent) {
|
||||
when (event) {
|
||||
|
||||
Reference in new issue
Block a user