From df23bb2c89870fcb3ff82d0f963cfb75ee1f7919 Mon Sep 17 00:00:00 2001 From: peng-u-0807 Date: Thu, 7 Dec 2023 14:33:10 +0900 Subject: [PATCH] feat: show my postList at `CreatedPostListView` --- .../java/com/goliath/emojihub/RootActivity.kt | 6 ++- .../emojihub/viewmodels/ReactionViewModel.kt | 3 +- .../com/goliath/emojihub/views/FeedPage.kt | 8 +--- .../views/components/CreatedPostListView.kt | 48 +++++++++++++++++-- .../views/components/CustomBottomSheet.kt | 8 ++-- 5 files changed, 55 insertions(+), 18 deletions(-) diff --git a/android/app/src/main/java/com/goliath/emojihub/RootActivity.kt b/android/app/src/main/java/com/goliath/emojihub/RootActivity.kt index cb763934..13920094 100644 --- a/android/app/src/main/java/com/goliath/emojihub/RootActivity.kt +++ b/android/app/src/main/java/com/goliath/emojihub/RootActivity.kt @@ -142,7 +142,11 @@ class RootActivity : ComponentActivity() { } composable(NavigationDestination.MyPostList) { - CreatedPostListView() + val parentEntry = remember(it) { + navController.getBackStackEntry(NavigationDestination.MainPage) + } + val postViewModel = hiltViewModel(parentEntry) + CreatedPostListView(postViewModel.myPostList) } composable(NavigationDestination.MyEmojiList) { diff --git a/android/app/src/main/java/com/goliath/emojihub/viewmodels/ReactionViewModel.kt b/android/app/src/main/java/com/goliath/emojihub/viewmodels/ReactionViewModel.kt index 7605c3bb..ab5d67f1 100644 --- a/android/app/src/main/java/com/goliath/emojihub/viewmodels/ReactionViewModel.kt +++ b/android/app/src/main/java/com/goliath/emojihub/viewmodels/ReactionViewModel.kt @@ -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) diff --git a/android/app/src/main/java/com/goliath/emojihub/views/FeedPage.kt b/android/app/src/main/java/com/goliath/emojihub/views/FeedPage.kt index cffaa34a..a81a9b63 100644 --- a/android/app/src/main/java/com/goliath/emojihub/views/FeedPage.kt +++ b/android/app/src/main/java/com/goliath/emojihub/views/FeedPage.kt @@ -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 + ) } } \ No newline at end of file diff --git a/android/app/src/main/java/com/goliath/emojihub/views/components/CreatedPostListView.kt b/android/app/src/main/java/com/goliath/emojihub/views/components/CreatedPostListView.kt index c3d3510e..c804c55a 100644 --- a/android/app/src/main/java/com/goliath/emojihub/views/components/CreatedPostListView.kt +++ b/android/app/src/main/java/com/goliath/emojihub/views/components/CreatedPostListView.kt @@ -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> ) { val navController = LocalNavController.current + val bottomSheetController = LocalBottomSheetController.current + + val emojiViewModel = hiltViewModel() + + + 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 + ) } } \ No newline at end of file diff --git a/android/app/src/main/java/com/goliath/emojihub/views/components/CustomBottomSheet.kt b/android/app/src/main/java/com/goliath/emojihub/views/components/CustomBottomSheet.kt index c00bf717..b5938eb8 100644 --- a/android/app/src/main/java/com/goliath/emojihub/views/components/CustomBottomSheet.kt +++ b/android/app/src/main/java/com/goliath/emojihub/views/components/CustomBottomSheet.kt @@ -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 @@ -51,9 +51,7 @@ enum class BottomSheetContent { @OptIn(ExperimentalMaterial3Api::class) @Composable fun CustomBottomSheet ( - bottomSheetContent: BottomSheetContent, - emojiList: List, - emojiCellClicked: (Emoji) -> Unit + bottomSheetContent: BottomSheetContent ){ val bottomSheetState = LocalBottomSheetController.current val coroutineScope = rememberCoroutineScope()