diff --git a/data/src/main/java/com/whyranoid/data/API.kt b/data/src/main/java/com/whyranoid/data/API.kt index 9a2061b..844951b 100644 --- a/data/src/main/java/com/whyranoid/data/API.kt +++ b/data/src/main/java/com/whyranoid/data/API.kt @@ -1,7 +1,7 @@ package com.whyranoid.data object API { - const val BASE_URL = "https://walkie-tsvdh.run.goorm.site/" + const val BASE_URL = "http://3.35.102.89:8080/" const val CHECK_NICKNAME = "api/walkies/signup/check" diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt index 2187693..2c90df1 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt @@ -1,12 +1,16 @@ package com.whyranoid.presentation.screens import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.Icon import androidx.compose.material.Scaffold import androidx.compose.material.Text @@ -14,6 +18,9 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.Search +import androidx.compose.material.pullrefresh.PullRefreshIndicator +import androidx.compose.material.pullrefresh.pullRefresh +import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier @@ -28,6 +35,7 @@ import com.whyranoid.presentation.viewmodel.CommunityScreenViewModel import org.koin.androidx.compose.koinViewModel import org.orbitmvi.orbit.compose.collectAsState +@OptIn(ExperimentalMaterialApi::class) @Composable fun CommunityScreen(navController: NavController) { val viewModel = koinViewModel() @@ -47,9 +55,9 @@ fun CommunityScreen(navController: NavController) { Icon( modifier = - Modifier - .clickable { - }, + Modifier + .clickable { + }, imageVector = Icons.Filled.KeyboardArrowDown, contentDescription = "Down Arrow", ) @@ -59,10 +67,10 @@ fun CommunityScreen(navController: NavController) { Row { Icon( modifier = - Modifier - .clickable { - navController.navigate(Screen.AddPostScreen.route) - }, + Modifier + .clickable { + navController.navigate(Screen.AddPostScreen.route) + }, imageVector = Icons.Filled.Add, contentDescription = "추가 버튼", ) @@ -71,10 +79,10 @@ fun CommunityScreen(navController: NavController) { Icon( modifier = - Modifier - .clickable { - navController.navigate(Screen.SearchFriendScreen.route) - }, + Modifier + .clickable { + navController.navigate(Screen.SearchFriendScreen.route) + }, imageVector = Icons.Filled.Search, contentDescription = "검색 버튼", ) @@ -83,36 +91,61 @@ fun CommunityScreen(navController: NavController) { ) }, ) { - LazyColumn( - modifier = Modifier.padding(it), + + Column( + modifier = Modifier.padding(it) ) { - item { - LazyRow { - repeat(10) { - item { RunningFollowerItemWithLikable(isDisplayName = true) } - } + LazyRow { + repeat(10) { + item { RunningFollowerItemWithLikable(isDisplayName = true) } } } - state.posts.getDataOrNull()?.forEach { post -> - item { - PostItem( - post = post, - onLikeClicked = { postId -> - viewModel.likePost(postId) - }, - onProfileClicked = { user -> - state.following.getDataOrNull()?.let { followings -> - val isFollowing = followings.contains(user) - navController.navigate("userPage/${user.uid}/${user.nickname}/$isFollowing") - } - }, - onCommentClicked = { post -> - navController.currentBackStackEntry?.savedStateHandle?.set("post", post) - navController.navigate(Screen.CommentScreen.route) - }, - ) + val refreshing = state.posts.getDataOrNull() == null + + val pullRefreshState = rememberPullRefreshState( + refreshing = refreshing, + onRefresh = { + viewModel.getPosts() + } + ) + + Box( + modifier = Modifier + .fillMaxSize() + .pullRefresh(pullRefreshState) + ) { + LazyColumn { + state.posts.getDataOrNull()?.forEach { post -> + item { + PostItem( + post = post, + onLikeClicked = { postId -> + viewModel.likePost(postId) + }, + onProfileClicked = { user -> + state.following.getDataOrNull()?.let { followings -> + val isFollowing = followings.contains(user) + navController.navigate("userPage/${user.uid}/${user.nickname}/$isFollowing") + } + }, + onCommentClicked = { post -> + navController.currentBackStackEntry?.savedStateHandle?.set( + "post", + post + ) + navController.navigate(Screen.CommentScreen.route) + }, + ) + } + } } + + PullRefreshIndicator( + refreshing = refreshing, + state = pullRefreshState, + modifier = Modifier.align(androidx.compose.ui.Alignment.TopCenter) + ) } } } diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt new file mode 100644 index 0000000..52f7978 --- /dev/null +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt @@ -0,0 +1,101 @@ +package com.whyranoid.presentation.screens.community + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.whyranoid.domain.model.post.Post +import com.whyranoid.domain.model.user.User +import com.whyranoid.presentation.component.community.PostItem +import com.whyranoid.presentation.theme.WalkieTheme +import com.whyranoid.presentation.theme.WalkieTypography +import com.whyranoid.presentation.viewmodel.CommunityScreenViewModel +import org.koin.androidx.compose.koinViewModel + +@Composable +fun UserPostScreen( + user: User, + postPreviews: List, + startIndex: Int, + onBackPressed: () -> Unit = {}, + +) { + + val viewModel = koinViewModel() + + Column( + modifier = Modifier + .fillMaxWidth() + .wrapContentHeight(), + verticalArrangement = Arrangement.Top, + ) { + Column( + Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp) + .padding(top = 20.dp), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Box( + contentAlignment = Alignment.CenterStart, + ) { + Column( + modifier = Modifier.align(Alignment.Center), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + style = WalkieTypography.Body1_Normal, + text = user.nickname, + modifier = Modifier + .padding(bottom = 24.dp), + ) + Text( + style = WalkieTypography.Title, + text = "게시물", + modifier = Modifier + .padding(bottom = 24.dp), + ) + } + + } + + + Column { + postPreviews.forEach { post -> + PostItem( + post = post, + onLikeClicked = { postId -> + viewModel.likePost(postId) + }, + onProfileClicked = { user -> + // navController.back + }, + onCommentClicked = { post -> +// navController.currentBackStackEntry?.savedStateHandle?.set( +// "post", +// post +// ) +// navController.navigate(Screen.CommentScreen.route) + }, + ) + } + } + } + } +} + +@Composable +@Preview +fun UserPostsScreenPreview() { + WalkieTheme { + UserPostScreen(User.DUMMY, listOf(Post.DUMMY), 0) + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt b/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt index cb74f61..6406e29 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt @@ -43,6 +43,9 @@ class CommunityScreenViewModel( } fun getPosts() = intent { + reduce { + state.copy(posts = UiState.Loading) + } val result = getFollowingsPostsUseCase() result.onSuccess { posts -> reduce {