Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
♻️ :: 피드 새로고침 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Tmdhoon2 committed Nov 20, 2023
1 parent 30880ee commit 41aa5cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ internal fun Feed(
)

LaunchedEffect(Unit) {
if (state.posts.isEmpty()) {
feedViewModel.fetchPosts()
}
feedViewModel.fetchPosts()
}

if (showDialog) {
Expand Down Expand Up @@ -124,7 +122,7 @@ internal fun Feed(
Posts(
moveToFeedDetails = moveToFeedDetails,
moveToReport = moveToReport,
posts = feedViewModel._posts,
posts = { state.posts },
showDropDown = {
feedViewModel.setFeedId(it)
expanded = it
Expand Down Expand Up @@ -254,7 +252,7 @@ private fun Posts(
moveToFeedDetails: (feedId: Long) -> Unit,
moveToReport: () -> Unit,
showDropDown: (feedId: Long) -> Unit,
posts: List<PostsEntity.PostEntity>,
posts: () -> List<PostsEntity.PostEntity>,
onDismissRequest: () -> Unit,
expanded: Long,
onDelete: () -> Unit,
Expand All @@ -274,7 +272,7 @@ private fun Posts(
state = lazyListState,
modifier = Modifier.fillMaxSize(),
) {
items(posts) {
items(posts()) {
Post(
moveToFeedDetails = { moveToFeedDetails(it.id) },
imageUrl = it.image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlinx.coroutines.launch
internal class FeedViewModel(
private val feedRepository: FeedRepository,
) : BaseViewModel<FeedState, FeedSideEffect>(FeedState.getDefaultState()) {
internal val _posts: SnapshotStateList<PostsEntity.PostEntity> = mutableStateListOf()
private val _posts: SnapshotStateList<PostsEntity.PostEntity> = mutableStateListOf()
private val _comments: SnapshotStateList<PostCommentsEntity.CommentEntity> =
mutableStateListOf()

Expand All @@ -31,16 +31,18 @@ internal class FeedViewModel(
)
}.onSuccess {
with(it.postEntities) {
when (_posts.contains(firstOrNull())) {
true -> _posts.add(last())
else -> _posts.addAll(this)
}
setState(
copy(
posts = _posts,
hasNextPage = isNotEmpty()
if (_posts.size != it.postEntities.size) {
when (_posts.contains(firstOrNull())) {
true -> _posts.add(last())
else -> _posts.addAll(this)
}
setState(
copy(
posts = _posts,
hasNextPage = isNotEmpty()
)
)
)
}
}
}
}
Expand All @@ -56,7 +58,6 @@ internal class FeedViewModel(
image = imageUrl,
).onSuccess {
postSideEffect(FeedSideEffect.PostSuccess)
fetchPosts()
}
}
}
Expand Down

0 comments on commit 41aa5cb

Please sign in to comment.