mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-09 12:58:43 +01:00
chore: avoid showing read post after "clear read" option
This commit is contained in:
parent
e4ec9e6606
commit
6c8d335394
@ -38,6 +38,7 @@ class CommunityDetailViewModel(
|
||||
|
||||
private var currentPage: Int = 1
|
||||
private var pageCursor: String? = null
|
||||
private var hideReadPosts = false
|
||||
|
||||
override fun onStarted() {
|
||||
mvi.onStarted()
|
||||
@ -120,6 +121,7 @@ class CommunityDetailViewModel(
|
||||
private fun refresh() {
|
||||
currentPage = 1
|
||||
pageCursor = null
|
||||
hideReadPosts = false
|
||||
mvi.updateState { it.copy(canFetchMore = true, refreshing = true) }
|
||||
val auth = identityRepository.authToken.value
|
||||
mvi.scope?.launch(Dispatchers.IO) {
|
||||
@ -177,6 +179,12 @@ class CommunityDetailViewModel(
|
||||
pageCursor = pageCursor,
|
||||
sort = sort,
|
||||
)
|
||||
}?.let {
|
||||
if (hideReadPosts) {
|
||||
it.copy(first = it.first.filter { p -> !p.read })
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}?.let {
|
||||
if (refreshing) {
|
||||
it
|
||||
@ -470,6 +478,7 @@ class CommunityDetailViewModel(
|
||||
}
|
||||
|
||||
private fun clearRead() {
|
||||
hideReadPosts = true
|
||||
mvi.updateState {
|
||||
val newPosts = it.posts.filter { e -> !e.read }
|
||||
it.copy(
|
||||
|
@ -42,6 +42,7 @@ class PostListViewModel(
|
||||
private var currentPage: Int = 1
|
||||
private var pageCursor: String? = null
|
||||
private var firstLoad = true
|
||||
private var hideReadPosts = false
|
||||
|
||||
init {
|
||||
notificationCenter.addObserver({
|
||||
@ -158,6 +159,7 @@ class PostListViewModel(
|
||||
private fun refresh() {
|
||||
currentPage = 1
|
||||
pageCursor = null
|
||||
hideReadPosts = false
|
||||
mvi.updateState { it.copy(canFetchMore = true, refreshing = true) }
|
||||
loadNextPage()
|
||||
}
|
||||
@ -183,6 +185,12 @@ class PostListViewModel(
|
||||
type = type,
|
||||
sort = sort,
|
||||
)?.let {
|
||||
if (hideReadPosts) {
|
||||
it.copy(first = it.first.filter { p -> !p.read })
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}?.let {
|
||||
if (refreshing) {
|
||||
it
|
||||
} else {
|
||||
@ -459,6 +467,7 @@ class PostListViewModel(
|
||||
}
|
||||
|
||||
private fun clearRead() {
|
||||
hideReadPosts = true
|
||||
mvi.updateState {
|
||||
val newPosts = it.posts.filter { e -> !e.read }
|
||||
it.copy(
|
||||
|
Loading…
x
Reference in New Issue
Block a user