Moves zapProgress to inside the IO update to make sure it only updates when needed.

This commit is contained in:
Vitor Pamplona
2023-05-22 17:52:46 -04:00
parent 0a8c79dacd
commit 6437a2106a
@@ -331,15 +331,15 @@ fun ZapReaction(
animationSize: Dp = 14.dp animationSize: Dp = 14.dp
) { ) {
val accountState by accountViewModel.accountLiveData.observeAsState() val accountState by accountViewModel.accountLiveData.observeAsState()
val account = accountState?.account ?: return val account = remember(accountState) { accountState?.account } ?: return
val zapsState by baseNote.live().zaps.observeAsState() val zapsState by baseNote.live().zaps.observeAsState()
val zappedNote = zapsState?.note ?: return val zappedNote = remember(zapsState) { zapsState?.note } ?: return
val zapMessage = ""
var wantsToZap by remember { mutableStateOf(false) } var wantsToZap by remember { mutableStateOf(false) }
var wantsToChangeZapAmount by remember { mutableStateOf(false) } var wantsToChangeZapAmount by remember { mutableStateOf(false) }
var wantsToSetCustomZap by remember { mutableStateOf(false) } var wantsToSetCustomZap by remember { mutableStateOf(false) }
val context = LocalContext.current val context = LocalContext.current
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
@@ -352,6 +352,7 @@ fun ZapReaction(
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
if (!wasZappedByLoggedInUser) { if (!wasZappedByLoggedInUser) {
wasZappedByLoggedInUser = accountViewModel.calculateIfNoteWasZappedByAccount(zappedNote) wasZappedByLoggedInUser = accountViewModel.calculateIfNoteWasZappedByAccount(zappedNote)
zappingProgress = 1f
} }
zapAmountTxt = showAmount(account.calculateZappedAmount(zappedNote)) zapAmountTxt = showAmount(account.calculateZappedAmount(zappedNote))
@@ -393,7 +394,7 @@ fun ZapReaction(
baseNote, baseNote,
account.zapAmountChoices.first() * 1000, account.zapAmountChoices.first() * 1000,
null, null,
zapMessage, "",
context, context,
onError = { onError = {
scope.launch { scope.launch {
@@ -457,7 +458,6 @@ fun ZapReaction(
} }
if (wasZappedByLoggedInUser) { if (wasZappedByLoggedInUser) {
zappingProgress = 1f
Icon( Icon(
imageVector = Icons.Default.Bolt, imageVector = Icons.Default.Bolt,
contentDescription = stringResource(R.string.zaps), contentDescription = stringResource(R.string.zaps),