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

[커뮤니티] 게시글 스와이프 리프레시 적용 및 baseUrl 변경 #84

Merged
merged 10 commits into from
Aug 26, 2024
2 changes: 1 addition & 1 deletion data/src/main/java/com/whyranoid/data/API.kt
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
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
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
Expand All @@ -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<CommunityScreenViewModel>()
Expand All @@ -47,9 +55,9 @@ fun CommunityScreen(navController: NavController) {

Icon(
modifier =
Modifier
.clickable {
},
Modifier
.clickable {
},
imageVector = Icons.Filled.KeyboardArrowDown,
contentDescription = "Down Arrow",
)
Expand All @@ -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 = "추가 버튼",
)
Expand All @@ -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 = "검색 버튼",
)
Expand All @@ -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)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Post>,
startIndex: Int,
onBackPressed: () -> Unit = {},

) {

val viewModel = koinViewModel<CommunityScreenViewModel>()

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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class CommunityScreenViewModel(
}

fun getPosts() = intent {
reduce {
state.copy(posts = UiState.Loading)
}
val result = getFollowingsPostsUseCase()
result.onSuccess { posts ->
reduce {
Expand Down
Loading