Skip to content

Commit

Permalink
Merge pull request #116 from snuhcs-course/feat/android-my-posts
Browse files Browse the repository at this point in the history
Show my postList at `CreatedPostListView`
  • Loading branch information
thisisWooyeol authored Dec 7, 2023
2 parents 9ebd767 + df23bb2 commit a024b1e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 18 deletions.
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

0 comments on commit a024b1e

Please sign in to comment.