mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 16:30:49 +00:00
Moves reaction calls to the viewModelScope
This commit is contained in:
parent
dc73843447
commit
a706b71d7c
@ -1366,18 +1366,14 @@ private fun ActionableReactionButton(
|
|||||||
onChangeAmount: () -> Unit,
|
onChangeAmount: () -> Unit,
|
||||||
toRemove: Set<String>
|
toRemove: Set<String>
|
||||||
) {
|
) {
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
modifier = Modifier.padding(horizontal = 3.dp),
|
modifier = Modifier.padding(horizontal = 3.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
scope.launch(Dispatchers.IO) {
|
accountViewModel.reactToOrDelete(
|
||||||
accountViewModel.reactToOrDelete(
|
baseNote,
|
||||||
baseNote,
|
reactionType
|
||||||
reactionType
|
)
|
||||||
)
|
onDismiss()
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
shape = ButtonBorder,
|
shape = ButtonBorder,
|
||||||
colors = ButtonDefaults
|
colors = ButtonDefaults
|
||||||
@ -1388,13 +1384,11 @@ private fun ActionableReactionButton(
|
|||||||
val thisModifier = remember(reactionType) {
|
val thisModifier = remember(reactionType) {
|
||||||
Modifier.combinedClickable(
|
Modifier.combinedClickable(
|
||||||
onClick = {
|
onClick = {
|
||||||
scope.launch(Dispatchers.IO) {
|
accountViewModel.reactToOrDelete(
|
||||||
accountViewModel.reactToOrDelete(
|
baseNote,
|
||||||
baseNote,
|
reactionType
|
||||||
reactionType
|
)
|
||||||
)
|
onDismiss()
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onLongClick = {
|
onLongClick = {
|
||||||
onChangeAmount()
|
onChangeAmount()
|
||||||
|
@ -117,11 +117,13 @@ class AccountViewModel(val account: Account) : ViewModel(), Dao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun reactToOrDelete(note: Note, reaction: String) {
|
fun reactToOrDelete(note: Note, reaction: String) {
|
||||||
val currentReactions = account.reactionTo(note, reaction)
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
if (currentReactions.isNotEmpty()) {
|
val currentReactions = account.reactionTo(note, reaction)
|
||||||
account.delete(currentReactions)
|
if (currentReactions.isNotEmpty()) {
|
||||||
} else {
|
account.delete(currentReactions)
|
||||||
account.reactTo(note, reaction)
|
} else {
|
||||||
|
account.reactTo(note, reaction)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user