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 28, 2023
1 parent 89b781c commit 0bf46fa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
Expand Down Expand Up @@ -75,6 +76,7 @@ internal fun Feed(
)

LaunchedEffect(Unit) {
feedViewModel.clearPost()
feedViewModel.fetchPosts()
}

Expand Down Expand Up @@ -252,7 +254,7 @@ private fun Posts(
moveToFeedDetails: (feedId: UUID) -> Unit,
moveToReport: () -> Unit,
showDropDown: (feedId: UUID) -> Unit,
posts: () -> List<PostsEntity.PostEntity>,
posts: () -> SnapshotStateList<PostsEntity.PostEntity>,
onDismissRequest: () -> Unit,
expanded: UUID,
onDelete: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.signal.domain.enums.Tag
import java.util.UUID

data class FeedState(
val posts: List<PostsEntity.PostEntity>,
val posts: SnapshotStateList<PostsEntity.PostEntity>,
val tag: Tag,
val page: Long,
val size: Long,
Expand All @@ -25,7 +25,7 @@ data class FeedState(
) {
companion object {
fun getDefaultState() = FeedState(
posts = emptyList(),
posts = mutableStateListOf(),
tag = Tag.GENERAL,
page = 0,
size = 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ internal class FeedViewModel(
}
}

internal fun clearPost() {
_posts.clear()
setState(state.value.copy(posts = _posts))
}

internal fun editPost(imageUrl: String? = null) {
with(state.value) {
if (feedId != null) {
Expand All @@ -160,11 +165,9 @@ internal class FeedViewModel(
title = title,
image = imageUrl ?: image.ifEmpty { postDetailsEntity.image },
content = content,
).onSuccess {
postSideEffect(FeedSideEffect.PostSuccess)
fetchPosts()
}.onFailure {
).onFailure {
if (it is KotlinNullPointerException) {
clearPost()
postSideEffect(FeedSideEffect.PostSuccess)
}
}
Expand Down

0 comments on commit 0bf46fa

Please sign in to comment.