mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 08:17:04 +05:30
android: reduce transformation steps for saved state check
This commit is contained in:
parent
4124cdcd1b
commit
733cae4815
1 changed files with 1 additions and 7 deletions
|
@ -12,14 +12,11 @@ import dev.msfjarvis.claw.database.local.SavedPost
|
|||
import java.time.Month
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@HiltViewModel
|
||||
class ClawViewModel
|
||||
@Inject
|
||||
|
@ -56,10 +53,7 @@ constructor(
|
|||
}
|
||||
|
||||
suspend fun isPostSaved(post: SavedPost): Boolean {
|
||||
return savedPostsFlow
|
||||
.mapLatest { posts -> posts.map { it.shortId } }
|
||||
.mapLatest { shortIds -> post.shortId in shortIds }
|
||||
.first()
|
||||
return savedPostsFlow.first().any { savedPost -> savedPost.shortId == post.shortId }
|
||||
}
|
||||
|
||||
fun toggleSave(post: SavedPost) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue