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

Commit

Permalink
πŸ”€ :: (#94) ν”Όλ“œ 쑰회 λ¦¬νŒ©ν† λ§
Browse files Browse the repository at this point in the history
πŸ”€ :: (#94) ν”Όλ“œ 쑰회 λ¦¬νŒ©ν† λ§
  • Loading branch information
Tmdhoon2 authored Nov 16, 2023
2 parents f181bba + abe94ba commit f6e004a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion data/src/main/kotlin/com/signal/data/api/SignalUrl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object SignalUrl {
object Feed {
const val CreatePost = "$feed/user"
const val List = "$feed/user/list"
const val Details = "$feed/{feed_id}"
const val Details = "$feed/user/{feed_id}"
const val Comments = "$feed/comment/{feed_id}"
const val FeedId = "$feed/{feed_id}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ data class CreatePostRequest(
@SerializedName("title") val title: String,
@SerializedName("content") val content: String,
@SerializedName("image") val image: String?,
@SerializedName("tag") val tag: Tag,
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ class FeedRepositoryImpl(
title: String,
content: String,
image: String?,
tag: Tag,
) = runCatching {
feedDataSource.createPost(
CreatePostRequest(
title = title,
content = content,
image = image,
tag = tag,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface FeedRepository {
title: String,
content: String,
image: String?,
tag: Tag,
): Result<Unit>

suspend fun fetchPostDetails(feedId: Long): Result<PostDetailsEntity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ internal fun Feed(
var showDialog by remember { mutableStateOf(false) }

val alpha by animateFloatAsState(
targetValue = if (state.isPostsEmpty) 1f else 0f,
targetValue = if (state.posts.isEmpty()) 1f else 0f,
label = "",
)

LaunchedEffect(Unit) {
if (state.isPostsEmpty) {
feedViewModel.fetchPosts()
}
feedViewModel.fetchPosts()
}

if (showDialog) {
Expand Down Expand Up @@ -108,6 +106,7 @@ internal fun Feed(
)
Filter(
expanded = { filterExpanded },
onDismissRequest = { filterExpanded = it },
currentTag = { state.tag },
onSelect = {
feedViewModel.setTag(it)
Expand All @@ -119,7 +118,7 @@ internal fun Feed(
Posts(
moveToFeedDetails = moveToFeedDetails,
moveToReport = moveToReport,
posts = state.posts,
posts = { state.posts },
showDropDown = {
feedViewModel.setFeedId(it)
expanded = it
Expand Down Expand Up @@ -151,7 +150,7 @@ internal fun Feed(
Body(
modifier = Modifier.signalClickable(
onClick = moveToCreatePost,
enabled = state.isPostsEmpty
enabled = state.posts.isEmpty()
),
text = stringResource(id = R.string.feed_posts_add),
color = SignalColor.Primary100,
Expand All @@ -176,6 +175,7 @@ internal fun Feed(
@Composable
private fun Filter(
expanded: () -> Boolean,
onDismissRequest: (Boolean) -> Unit,
currentTag: () -> Tag,
onSelect: (Tag) -> Unit,
onClick: () -> Unit,
Expand All @@ -200,7 +200,7 @@ private fun Filter(
}
DropdownMenu(
expanded = expanded(),
onDismissRequest = { /*TODO*/ },
onDismissRequest = { onDismissRequest(!expanded()) },
) {
DropdownMenuItem(
text = {
Expand Down Expand Up @@ -242,13 +242,13 @@ 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,
) {
LazyColumn(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
@@ -1,16 +1,17 @@
package com.signal.signal_android.feature.main.feed

import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.snapshots.SnapshotStateList
import com.signal.domain.entity.PostsEntity
import com.signal.domain.entity.PostCommentsEntity
import com.signal.domain.entity.PostDetailsEntity
import com.signal.domain.enums.Tag

data class FeedState(
val posts: List<PostsEntity.PostEntity>,
val posts: SnapshotStateList<PostsEntity.PostEntity>,
val tag: Tag,
val page: Long,
val size: Long,
val isPostsEmpty: Boolean,
val title: String,
val content: String,
val postDetailsEntity: PostDetailsEntity,
Expand All @@ -21,11 +22,10 @@ data class FeedState(
) {
companion object {
fun getDefaultState() = FeedState(
posts = listOf(),
posts = mutableStateListOf(),
tag = Tag.GENERAL,
page = 0,
size = 8,
isPostsEmpty = true,
title = "",
content = "",
postDetailsEntity = PostDetailsEntity(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.signal.signal_android.feature.main.feed

import androidx.compose.runtime.toMutableStateList
import androidx.lifecycle.viewModelScope
import com.signal.domain.entity.PostCommentsEntity
import com.signal.domain.entity.PostDetailsEntity
Expand All @@ -26,15 +27,9 @@ internal class FeedViewModel(
size = size,
)
}.onSuccess {
_posts.clear()
_posts.addAll(it.postEntities)
setState(
copy(
posts = _posts,
isPostsEmpty = _posts.isEmpty(),
)
)
}.onFailure {
setState(copy(isPostsEmpty = _posts.isEmpty()))
setState(copy(posts = _posts.toMutableStateList()))
}
}
}
Expand All @@ -47,9 +42,9 @@ internal class FeedViewModel(
title = title,
content = content,
image = imageUrl,
tag = tag,
).onSuccess {
postSideEffect(FeedSideEffect.PostSuccess)
fetchPosts()
}
}
}
Expand Down Expand Up @@ -108,11 +103,17 @@ internal class FeedViewModel(

internal fun deletePost() {
with(state.value) {
val remove = {
_posts.remove(_posts.find { it.id == feedId })
setState(copy(posts = _posts.toMutableStateList()))
}
viewModelScope.launch(Dispatchers.IO) {
feedRepository.deletePost(feedId = feedId).onSuccess {

remove()
}.onFailure {

if (it is KotlinNullPointerException) {
remove()
}
}
}
}
Expand Down

0 comments on commit f6e004a

Please sign in to comment.