mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-22 21:51:57 +02:00
Faster Galleries
This commit is contained in:
@@ -412,65 +412,97 @@ private fun ReactionDetailGallery(
|
|||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
accountViewModel: AccountViewModel
|
accountViewModel: AccountViewModel
|
||||||
) {
|
) {
|
||||||
val zapsState by baseNote.live().zaps.observeAsState()
|
|
||||||
val boostsState by baseNote.live().boosts.observeAsState()
|
|
||||||
val reactionsState by baseNote.live().reactions.observeAsState()
|
|
||||||
|
|
||||||
val defaultBackgroundColor = MaterialTheme.colors.background
|
val defaultBackgroundColor = MaterialTheme.colors.background
|
||||||
val backgroundColor = remember { mutableStateOf<Color>(defaultBackgroundColor) }
|
val backgroundColor = remember { mutableStateOf<Color>(defaultBackgroundColor) }
|
||||||
|
|
||||||
val hasReactions by remember(zapsState, boostsState, reactionsState) {
|
val hasReactions by baseNote.live().zaps.combineWith(
|
||||||
derivedStateOf {
|
baseNote.live().boosts,
|
||||||
baseNote.zaps.isNotEmpty() ||
|
baseNote.live().reactions
|
||||||
baseNote.boosts.isNotEmpty() ||
|
) { zapState, boostState, reactionState ->
|
||||||
baseNote.reactions.isNotEmpty()
|
zapState?.note?.zaps?.isNotEmpty() ?: false ||
|
||||||
}
|
boostState?.note?.boosts?.isNotEmpty() ?: false ||
|
||||||
}
|
reactionState?.note?.reactions?.isNotEmpty() ?: false
|
||||||
|
}.distinctUntilChanged().observeAsState(
|
||||||
|
baseNote.zaps.isNotEmpty() || baseNote.boosts.isNotEmpty() || baseNote.reactions.isNotEmpty()
|
||||||
|
)
|
||||||
|
|
||||||
if (hasReactions) {
|
if (hasReactions) {
|
||||||
Row(verticalAlignment = CenterVertically, modifier = Modifier.padding(start = 10.dp, top = 5.dp)) {
|
Row(verticalAlignment = CenterVertically, modifier = Modifier.padding(start = 10.dp, top = 5.dp)) {
|
||||||
Column() {
|
Column() {
|
||||||
val zapEvents by remember(zapsState) { derivedStateOf { baseNote.zaps.mapNotNull { it.value?.let { zapEvent -> CombinedZap(it.key, zapEvent) } }.toImmutableList() } }
|
// WatchZapAndRenderGallery(baseNote, backgroundColor, nav, accountViewModel)
|
||||||
val boostEvents by remember(boostsState) { derivedStateOf { baseNote.boosts.toImmutableList() } }
|
// WatchBoostsAndRenderGallery(baseNote, nav, accountViewModel)
|
||||||
val likeEvents by remember(reactionsState) { derivedStateOf { baseNote.reactions.toImmutableMap() } }
|
WatchReactionsAndRenderGallery(baseNote, nav, accountViewModel)
|
||||||
|
|
||||||
val hasZapEvents by remember(zapsState) { derivedStateOf { baseNote.zaps.isNotEmpty() } }
|
|
||||||
val hasBoostEvents by remember(boostsState) { derivedStateOf { baseNote.boosts.isNotEmpty() } }
|
|
||||||
val hasLikeEvents by remember(reactionsState) { derivedStateOf { baseNote.reactions.isNotEmpty() } }
|
|
||||||
|
|
||||||
if (hasZapEvents) {
|
|
||||||
RenderZapGallery(
|
|
||||||
zapEvents,
|
|
||||||
backgroundColor,
|
|
||||||
nav,
|
|
||||||
accountViewModel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasBoostEvents) {
|
|
||||||
RenderBoostGallery(
|
|
||||||
boostEvents,
|
|
||||||
nav,
|
|
||||||
accountViewModel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasLikeEvents) {
|
|
||||||
likeEvents.forEach {
|
|
||||||
val reactions = remember(it.value) { it.value.toImmutableList() }
|
|
||||||
RenderLikeGallery(
|
|
||||||
it.key,
|
|
||||||
reactions,
|
|
||||||
nav,
|
|
||||||
accountViewModel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun WatchBoostsAndRenderGallery(
|
||||||
|
baseNote: Note,
|
||||||
|
nav: (String) -> Unit,
|
||||||
|
accountViewModel: AccountViewModel
|
||||||
|
) {
|
||||||
|
val boostsState by baseNote.live().boosts.observeAsState()
|
||||||
|
val boostsEvents by remember(boostsState) {
|
||||||
|
derivedStateOf { baseNote.boosts.toImmutableList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (boostsEvents.isNotEmpty()) {
|
||||||
|
RenderBoostGallery(
|
||||||
|
boostsEvents,
|
||||||
|
nav,
|
||||||
|
accountViewModel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun WatchReactionsAndRenderGallery(
|
||||||
|
baseNote: Note,
|
||||||
|
nav: (String) -> Unit,
|
||||||
|
accountViewModel: AccountViewModel
|
||||||
|
) {
|
||||||
|
val reactionsState by baseNote.live().reactions.observeAsState()
|
||||||
|
val reactionEvents by remember(reactionsState) {
|
||||||
|
derivedStateOf { baseNote.reactions.toImmutableMap() }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reactionEvents.isNotEmpty()) {
|
||||||
|
reactionEvents.forEach {
|
||||||
|
val reactions = remember(it.value) { it.value.toImmutableList() }
|
||||||
|
RenderLikeGallery(
|
||||||
|
it.key,
|
||||||
|
reactions,
|
||||||
|
nav,
|
||||||
|
accountViewModel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun WatchZapAndRenderGallery(
|
||||||
|
baseNote: Note,
|
||||||
|
backgroundColor: MutableState<Color>,
|
||||||
|
nav: (String) -> Unit,
|
||||||
|
accountViewModel: AccountViewModel
|
||||||
|
) {
|
||||||
|
val zapsState by baseNote.live().zaps.observeAsState()
|
||||||
|
val zapEvents by remember(zapsState) {
|
||||||
|
derivedStateOf { baseNote.zaps.mapNotNull { it.value?.let { zapEvent -> CombinedZap(it.key, zapEvent) } }.toImmutableList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zapEvents.isNotEmpty()) {
|
||||||
|
RenderZapGallery(
|
||||||
|
zapEvents,
|
||||||
|
backgroundColor,
|
||||||
|
nav,
|
||||||
|
accountViewModel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun BoostWithDialog(
|
private fun BoostWithDialog(
|
||||||
baseNote: Note,
|
baseNote: Note,
|
||||||
|
Reference in New Issue
Block a user