From 77c944d33bbd447205bf7912f9fba16eb44aa7e4 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 6 Sep 2024 15:00:02 +0200 Subject: [PATCH] Fixed initializing RecipientFinder (which is quite expensive) only once --- .../banking/ui/dialogs/TransferMoneyDialog.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt index a8d4ef0..c18118f 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/TransferMoneyDialog.kt @@ -68,7 +68,7 @@ fun TransferMoneyDialog( } - val recipientFinder = RecipientFinder(DI.bankFinder) + val recipientFinder = remember { RecipientFinder(DI.bankFinder) } var isTransferringMoney by remember { mutableStateOf(false) } @@ -77,14 +77,11 @@ fun TransferMoneyDialog( val verticalSpace = 8.dp + var isInitialized by remember { mutableStateOf(false) } + val coroutineScope = rememberCoroutineScope() - coroutineScope.launch { - recipientFinder.updateData(bankingService.getAllAccountTransactions()) // only a bit problematic: if in the meantime new transactions are retrieved, then RecipientFinder doesn't contain the newly retrieved transactions - } - - fun confirmCalled() { isTransferringMoney = true @@ -229,4 +226,15 @@ fun TransferMoneyDialog( } } } + + + LaunchedEffect(isInitialized) { + if (isInitialized == false) { + isInitialized = true + + coroutineScope.launch { + recipientFinder.updateData(bankingService.getAllAccountTransactions()) // only a bit problematic: if in the meantime new transactions are retrieved, then RecipientFinder doesn't contain the newly retrieved transactions + } + } + } } \ No newline at end of file