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

Commit

Permalink
πŸ”€ :: (#74) ν”Όλ“œ νŽ˜μ΄μ§• κ΅¬ν˜„
Browse files Browse the repository at this point in the history
πŸ”€ :: (#74) ν”Όλ“œ νŽ˜μ΄μ§• κ΅¬ν˜„
  • Loading branch information
Tmdhoon2 authored Nov 18, 2023
2 parents 0d72eb9 + ee5bf52 commit 4d7f97b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ internal fun CreatePost(
alignment = Alignment.Top,
showLength = true,
singleLine = false,
maxLength = 100,
maxLength = 300,
)
PostImage(
uri = { imagePreview },
imageUrl = { details.image },
) {
focusManager.clearFocus()
launcher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
}
Spacer(modifier = Modifier.weight(1f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.DropdownMenu
Expand Down Expand Up @@ -130,6 +131,11 @@ internal fun Feed(
onDismissRequest = { expanded = -1 },
onDelete = { showDialog = true },
onEdit = { moveToCreatePost(state.feedId) },
nextPage = {
if (state.hasNextPage) {
feedViewModel.nextPage()
}
},
)

Column(
Expand Down Expand Up @@ -251,8 +257,21 @@ private fun Posts(
expanded: Long,
onDelete: () -> Unit,
onEdit: () -> Unit,
nextPage: () -> Unit,
) {
LazyColumn(modifier = Modifier.fillMaxSize()) {
val lazyListState = remember { LazyListState() }

LaunchedEffect(lazyListState.layoutInfo.visibleItemsInfo.lastIndex) {
val visibleItemsInfo = lazyListState.layoutInfo.visibleItemsInfo
if (visibleItemsInfo.lastIndex != -1 && (visibleItemsInfo.last().index % 7 == 0)) {
nextPage()
}
}

LazyColumn(
state = lazyListState,
modifier = Modifier.fillMaxSize(),
) {
items(posts()) {
Post(
moveToFeedDetails = { moveToFeedDetails(it.id) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ data class FeedState(
val comments: List<PostCommentsEntity.CommentEntity>,
val comment: String,
val buttonEnabled: Boolean,
val hasNextPage: Boolean,
) {
companion object {
fun getDefaultState() = FeedState(
posts = mutableStateListOf(),
tag = Tag.GENERAL,
page = 0,
size = 8,
size = 10,
title = "",
content = "",
postDetailsEntity = PostDetailsEntity(
Expand All @@ -44,6 +45,7 @@ data class FeedState(
comments = listOf(),
comment = "",
buttonEnabled = false,
hasNextPage = false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ internal class FeedViewModel(
size = size,
)
}.onSuccess {
_posts.clear()
_posts.addAll(it.postEntities)
setState(copy(posts = _posts.toMutableStateList()))
setState(
copy(
posts = _posts.toMutableStateList(),
hasNextPage = it.postEntities.isNotEmpty()
)
)
}
}
}
Expand Down Expand Up @@ -141,6 +145,13 @@ internal class FeedViewModel(
}
}

internal fun nextPage() {
with(state.value) {
setState(copy(page = page + 1))
}
fetchPosts()
}

internal fun setTitle(title: String) {
setState(state.value.copy(title = title))
setButtonEnabled()
Expand Down

0 comments on commit 4d7f97b

Please sign in to comment.