mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 09:57: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 java.time.Month
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.mapLatest
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class ClawViewModel
|
class ClawViewModel
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -56,10 +53,7 @@ constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun isPostSaved(post: SavedPost): Boolean {
|
suspend fun isPostSaved(post: SavedPost): Boolean {
|
||||||
return savedPostsFlow
|
return savedPostsFlow.first().any { savedPost -> savedPost.shortId == post.shortId }
|
||||||
.mapLatest { posts -> posts.map { it.shortId } }
|
|
||||||
.mapLatest { shortIds -> post.shortId in shortIds }
|
|
||||||
.first()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleSave(post: SavedPost) {
|
fun toggleSave(post: SavedPost) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue