Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show my postList at CreatedPostListView #116

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ class RootActivity : ComponentActivity() {
}

composable(NavigationDestination.MyPostList) {
CreatedPostListView()
val parentEntry = remember(it) {
navController.getBackStackEntry(NavigationDestination.MainPage)
}
val postViewModel = hiltViewModel<PostViewModel>(parentEntry)
CreatedPostListView(postViewModel.myPostList)
}

composable(NavigationDestination.MyEmojiList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class ReactionViewModel @Inject constructor(

val reactionList = reactionUseCase.reactionList


fun fetchReactionList(postId: String, emojiUnicode: String) {
suspend fun fetchReactionList(postId: String, emojiUnicode: String) {
viewModelScope.launch {
reactionUseCase.fetchReactionList(postId, emojiUnicode)
.cachedIn(viewModelScope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ fun FeedPage() {

if (bottomSheetController.isVisible) {
CustomBottomSheet(
bottomSheetContent = emojiViewModel.bottomSheetContent,
emojiList = emojiList
) { emoji ->
emojiViewModel.currentEmoji = emoji
navController.navigate(NavigationDestination.PlayEmojiVideo)
}
bottomSheetContent = emojiViewModel.bottomSheetContent
)
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,64 @@
package com.goliath.emojihub.views.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Divider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.paging.PagingData
import androidx.paging.compose.collectAsLazyPagingItems
import com.goliath.emojihub.LocalBottomSheetController
import com.goliath.emojihub.LocalNavController
import com.goliath.emojihub.models.Post
import com.goliath.emojihub.ui.theme.Color
import com.goliath.emojihub.viewmodels.EmojiViewModel
import kotlinx.coroutines.flow.StateFlow

@Composable
fun CreatedPostListView(

postList: StateFlow<PagingData<Post>>
) {
val navController = LocalNavController.current
val bottomSheetController = LocalBottomSheetController.current

val emojiViewModel = hiltViewModel<EmojiViewModel>()


val pagingPostList = postList.collectAsLazyPagingItems()

Column (
Modifier.background(Color.White)
) {
Column (Modifier.background(Color.White)) {
TopNavigationBar(
title = "내가 작성한 포스트",
navigate = { navController.popBackStack() }
)

Box(
Modifier
.weight(1f)
.fillMaxWidth()) {
LazyColumn(
modifier = Modifier.fillMaxWidth(),
contentPadding = PaddingValues(horizontal = 16.dp)
) {
items(pagingPostList.itemCount) { index ->
pagingPostList[index]?.let {
PostCell(post = it)
Divider(color = Color.EmojiHubDividerColor, thickness = 0.5.dp)
}
}
}
}
}

if (bottomSheetController.isVisible) {
CustomBottomSheet(
bottomSheetContent = emojiViewModel.bottomSheetContent
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ import androidx.paging.compose.collectAsLazyPagingItems
import com.goliath.emojihub.LocalBottomSheetController
import com.goliath.emojihub.LocalNavController
import com.goliath.emojihub.NavigationDestination
import com.goliath.emojihub.ui.theme.Color.EmojiHubDividerColor
import com.goliath.emojihub.extensions.toEmoji
import com.goliath.emojihub.models.Emoji
import com.goliath.emojihub.ui.theme.Color.EmojiHubDividerColor
import com.goliath.emojihub.ui.theme.Color.LightGray
import kotlinx.coroutines.launch
import com.goliath.emojihub.ui.theme.Color.White
import com.goliath.emojihub.viewmodels.EmojiViewModel
import com.goliath.emojihub.viewmodels.PostViewModel
import com.goliath.emojihub.viewmodels.ReactionViewModel
import kotlinx.coroutines.launch

enum class BottomSheetContent {
VIEW_REACTION, ADD_REACTION, EMPTY
Expand All @@ -51,9 +51,7 @@ enum class BottomSheetContent {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CustomBottomSheet (
bottomSheetContent: BottomSheetContent,
emojiList: List<Emoji>,
emojiCellClicked: (Emoji) -> Unit
bottomSheetContent: BottomSheetContent
){
val bottomSheetState = LocalBottomSheetController.current
val coroutineScope = rememberCoroutineScope()
Expand Down