Ignores unloaded notes in the MultiComposeSet renderer.
This commit is contained in:
@@ -63,92 +63,85 @@ import kotlinx.coroutines.launch
|
|||||||
fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
||||||
val baseNote = remember { multiSetCard.note }
|
val baseNote = remember { multiSetCard.note }
|
||||||
|
|
||||||
val noteState by baseNote.live().metadata.observeAsState()
|
|
||||||
val note = remember(noteState) { noteState?.note } ?: return
|
|
||||||
|
|
||||||
var popupExpanded by remember { mutableStateOf(false) }
|
var popupExpanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
if (note.event == null) {
|
var isNew by remember { mutableStateOf(false) }
|
||||||
BlankNote(Modifier, false)
|
|
||||||
|
LaunchedEffect(key1 = multiSetCard.createdAt()) {
|
||||||
|
launch(Dispatchers.IO) {
|
||||||
|
val newIsNew = multiSetCard.maxCreatedAt > NotificationCache.load(routeForLastRead)
|
||||||
|
|
||||||
|
NotificationCache.markAsRead(routeForLastRead, multiSetCard.maxCreatedAt)
|
||||||
|
|
||||||
|
if (newIsNew != isNew) {
|
||||||
|
isNew = newIsNew
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val primaryColor = MaterialTheme.colors.newItemBackgroundColor
|
||||||
|
val defaultBackgroundColor = MaterialTheme.colors.background
|
||||||
|
|
||||||
|
val backgroundColor = if (isNew) {
|
||||||
|
primaryColor.compositeOver(defaultBackgroundColor)
|
||||||
} else {
|
} else {
|
||||||
var isNew by remember { mutableStateOf(false) }
|
defaultBackgroundColor
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(key1 = multiSetCard.createdAt()) {
|
val columnModifier = Modifier
|
||||||
scope.launch(Dispatchers.IO) {
|
.background(backgroundColor)
|
||||||
val newIsNew = multiSetCard.maxCreatedAt > NotificationCache.load(routeForLastRead)
|
.padding(
|
||||||
|
start = 12.dp,
|
||||||
NotificationCache.markAsRead(routeForLastRead, multiSetCard.maxCreatedAt)
|
end = 12.dp,
|
||||||
|
top = 10.dp
|
||||||
if (newIsNew != isNew) {
|
)
|
||||||
isNew = newIsNew
|
.combinedClickable(
|
||||||
|
onClick = {
|
||||||
|
scope.launch {
|
||||||
|
routeFor(baseNote, accountViewModel.userProfile())?.let { nav(it) }
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
onLongClick = { popupExpanded = true }
|
||||||
|
)
|
||||||
|
.fillMaxWidth()
|
||||||
|
|
||||||
|
val zapEvents by remember { derivedStateOf { multiSetCard.zapEvents } }
|
||||||
|
val boostEvents by remember { derivedStateOf { multiSetCard.boostEvents } }
|
||||||
|
val likeEvents by remember { derivedStateOf { multiSetCard.likeEvents } }
|
||||||
|
|
||||||
|
val hasZapEvents by remember { derivedStateOf { multiSetCard.zapEvents.isNotEmpty() } }
|
||||||
|
val hasBoostEvents by remember { derivedStateOf { multiSetCard.boostEvents.isNotEmpty() } }
|
||||||
|
val hasLikeEvents by remember { derivedStateOf { multiSetCard.likeEvents.isNotEmpty() } }
|
||||||
|
|
||||||
|
Column(modifier = columnModifier) {
|
||||||
|
if (hasZapEvents) {
|
||||||
|
RenderZapGallery(zapEvents, backgroundColor, nav, accountViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
val primaryColor = MaterialTheme.colors.newItemBackgroundColor
|
if (hasBoostEvents) {
|
||||||
val defaultBackgroundColor = MaterialTheme.colors.background
|
RenderBoostGallery(boostEvents, backgroundColor, nav, accountViewModel)
|
||||||
|
|
||||||
val backgroundColor = if (isNew) {
|
|
||||||
primaryColor.compositeOver(defaultBackgroundColor)
|
|
||||||
} else {
|
|
||||||
defaultBackgroundColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val columnModifier = Modifier
|
if (hasLikeEvents) {
|
||||||
.background(backgroundColor)
|
RenderLikeGallery(likeEvents, backgroundColor, nav, accountViewModel)
|
||||||
.padding(
|
}
|
||||||
start = 12.dp,
|
|
||||||
end = 12.dp,
|
Row(Modifier.fillMaxWidth()) {
|
||||||
top = 10.dp
|
Spacer(modifier = Modifier.width(65.dp))
|
||||||
|
|
||||||
|
NoteCompose(
|
||||||
|
baseNote = baseNote,
|
||||||
|
routeForLastRead = null,
|
||||||
|
modifier = Modifier.padding(top = 5.dp),
|
||||||
|
isBoostedNote = true,
|
||||||
|
parentBackgroundColor = backgroundColor,
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav
|
||||||
)
|
)
|
||||||
.combinedClickable(
|
|
||||||
onClick = {
|
|
||||||
scope.launch {
|
|
||||||
routeFor(baseNote, accountViewModel.userProfile())?.let { nav(it) }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onLongClick = { popupExpanded = true }
|
|
||||||
)
|
|
||||||
.fillMaxWidth()
|
|
||||||
|
|
||||||
val zapEvents by remember { derivedStateOf { multiSetCard.zapEvents } }
|
NoteDropDownMenu(baseNote, popupExpanded, { popupExpanded = false }, accountViewModel)
|
||||||
val boostEvents by remember { derivedStateOf { multiSetCard.boostEvents } }
|
|
||||||
val likeEvents by remember { derivedStateOf { multiSetCard.likeEvents } }
|
|
||||||
|
|
||||||
val hasZapEvents by remember { derivedStateOf { multiSetCard.zapEvents.isNotEmpty() } }
|
|
||||||
val hasBoostEvents by remember { derivedStateOf { multiSetCard.boostEvents.isNotEmpty() } }
|
|
||||||
val hasLikeEvents by remember { derivedStateOf { multiSetCard.likeEvents.isNotEmpty() } }
|
|
||||||
|
|
||||||
Column(modifier = columnModifier) {
|
|
||||||
if (hasZapEvents) {
|
|
||||||
RenderZapGallery(zapEvents, backgroundColor, nav, accountViewModel)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasBoostEvents) {
|
|
||||||
RenderBoostGallery(boostEvents, backgroundColor, nav, accountViewModel)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasLikeEvents) {
|
|
||||||
RenderLikeGallery(likeEvents, backgroundColor, nav, accountViewModel)
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(Modifier.fillMaxWidth()) {
|
|
||||||
Spacer(modifier = Modifier.width(65.dp))
|
|
||||||
|
|
||||||
NoteCompose(
|
|
||||||
baseNote = baseNote,
|
|
||||||
routeForLastRead = null,
|
|
||||||
modifier = Modifier.padding(top = 5.dp),
|
|
||||||
isBoostedNote = true,
|
|
||||||
parentBackgroundColor = backgroundColor,
|
|
||||||
accountViewModel = accountViewModel,
|
|
||||||
nav = nav
|
|
||||||
)
|
|
||||||
|
|
||||||
NoteDropDownMenu(note, popupExpanded, { popupExpanded = false }, accountViewModel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,10 +91,9 @@ private fun WatchZapsAndUpdateTallies(
|
|||||||
pollViewModel: PollNoteViewModel
|
pollViewModel: PollNoteViewModel
|
||||||
) {
|
) {
|
||||||
val zapsState by baseNote.live().zaps.observeAsState()
|
val zapsState by baseNote.live().zaps.observeAsState()
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
LaunchedEffect(key1 = zapsState) {
|
LaunchedEffect(key1 = zapsState) {
|
||||||
scope.launch(Dispatchers.IO) {
|
launch(Dispatchers.Default) {
|
||||||
pollViewModel.refreshTallies()
|
pollViewModel.refreshTallies()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ private fun ZapIcon(
|
|||||||
val zapsState by baseNote.live().zaps.observeAsState()
|
val zapsState by baseNote.live().zaps.observeAsState()
|
||||||
|
|
||||||
LaunchedEffect(key1 = zapsState) {
|
LaunchedEffect(key1 = zapsState) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.Default) {
|
||||||
zapsState?.note?.let {
|
zapsState?.note?.let {
|
||||||
if (!wasZappedByLoggedInUser) {
|
if (!wasZappedByLoggedInUser) {
|
||||||
val newWasZapped = accountViewModel.calculateIfNoteWasZappedByAccount(it)
|
val newWasZapped = accountViewModel.calculateIfNoteWasZappedByAccount(it)
|
||||||
@@ -561,7 +561,7 @@ private fun ZapAmountText(
|
|||||||
var zapAmountTxt by remember { mutableStateOf("") }
|
var zapAmountTxt by remember { mutableStateOf("") }
|
||||||
|
|
||||||
LaunchedEffect(key1 = zapsState) {
|
LaunchedEffect(key1 = zapsState) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.Default) {
|
||||||
zapsState?.note?.let {
|
zapsState?.note?.let {
|
||||||
val newZapAmount = showAmount(accountViewModel.calculateZapAmount(it))
|
val newZapAmount = showAmount(accountViewModel.calculateZapAmount(it))
|
||||||
if (newZapAmount != zapAmountTxt) {
|
if (newZapAmount != zapAmountTxt) {
|
||||||
|
|||||||
@@ -153,10 +153,18 @@ fun UserActionOptions(
|
|||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
val accountState by accountViewModel.accountLiveData.observeAsState()
|
||||||
val isHidden = remember(accountState) { accountState?.account?.isHidden(baseAuthor) } ?: return
|
val isHidden by remember(accountState) {
|
||||||
|
derivedStateOf {
|
||||||
|
accountState?.account?.isHidden(baseAuthor) ?: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val userState by accountViewModel.account.userProfile().live().follows.observeAsState()
|
val userState by accountViewModel.account.userProfile().live().follows.observeAsState()
|
||||||
val isFollowing = remember(userState) { userState?.user?.isFollowingCached(baseAuthor) } ?: return
|
val isFollowing by remember(userState) {
|
||||||
|
derivedStateOf {
|
||||||
|
userState?.user?.isFollowingCached(baseAuthor) ?: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isHidden) {
|
if (isHidden) {
|
||||||
ShowUserButton {
|
ShowUserButton {
|
||||||
|
|||||||
Reference in New Issue
Block a user