Skip to content

Commit

Permalink
✨ 마이페이지 하위 첼리지 탭 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghanJu committed Jun 20, 2024
1 parent f980433 commit d8d7ee5
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/whyranoid/walkie/KoinModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ val viewModelModule =
single { ChallengeMainViewModel(get(), get(), get(), get(), get()) }
single { ChallengeDetailViewModel(get(), get()) }
single { ChallengeExitViewModel(get()) }
factory { UserPageViewModel(get(), get(), get(), get(), get(), get(), get(), get()) }
factory { UserPageViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get()) }
factory { RunningViewModel(get(), get(), get(), get(), get(), get()) }
factory { RunningEditViewModel() }
factory { SplashViewModel(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import coil.compose.AsyncImage
import com.whyranoid.domain.util.EMPTY
import com.whyranoid.presentation.component.badge.PlaceholderBadge
Expand Down Expand Up @@ -89,6 +90,7 @@ fun MyPageScreen(
viewModel.getUserDetail(myUid, null)
viewModel.getUserBadges(myUid)
viewModel.getUserPostPreviews(myUid)
viewModel.getChallengingPreviews(myUid)
}

val state by viewModel.collectAsState()
Expand Down Expand Up @@ -126,6 +128,19 @@ fun MyPageScreen(
)
}
},
onChallengePreviewClicked = { challengeId: Long ->
val route = "challengeDetail/$challengeId/true"
navController.navigate(route)
},
goChallengeMainScreen = {
navController.navigate(Screen.ChallengeMainScreen.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
)
}

Expand All @@ -145,6 +160,8 @@ fun UserPageContent(
onUnFollowButtonClicked: () -> Unit = {},
onFollowerCountClicked: () -> Unit = {},
onFollowingCountClicked: () -> Unit = {},
onChallengePreviewClicked: (challengeId: Long) -> Unit = {},
goChallengeMainScreen: () -> Unit = {},
) {
Scaffold(
topBar = {
Expand Down Expand Up @@ -376,9 +393,11 @@ fun UserPageContent(
}
}

2 -> ChallengePage {

}
2 -> ChallengePage(
state.challengingPreviewsState.getDataOrNull() ?: emptyList(),
onChallengePreviewClicked,
goChallengeMainScreen
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fun UserPageScreen(
viewModel.getUserDetail(uid, isFollowing)
viewModel.getUserBadges(uid)
viewModel.getUserPostPreviews(uid)
viewModel.getChallengingPreviews(uid)
}

val state by viewModel.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.whyranoid.presentation.screens.mypage.tabs

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
Expand All @@ -14,11 +14,16 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.whyranoid.domain.model.challenge.ChallengePreview
import com.whyranoid.presentation.component.ChallengeItem
import com.whyranoid.presentation.component.button.WalkiePositiveButton
import com.whyranoid.presentation.theme.ChallengeColor.getColor
import com.whyranoid.presentation.theme.WalkieTypography

@Composable
fun ChallengePage(
challengePreviews: List<ChallengePreview>,
onChallengePreviewClicked: (challengeId: Long) -> Unit,
onGotoChallengeClicked: () -> Unit
) {

Expand All @@ -29,19 +34,33 @@ fun ChallengePage(
horizontalAlignment = Alignment.CenterHorizontally
) {

Column {
Spacer(modifier = Modifier.height(30.dp))
Text(
text = "챌린지에 도전하고 프로필에 뱃지를 채워보세요!",
style = WalkieTypography.Body1_Normal.copy(color = Color.Black.copy(alpha = 0.5f))
)
}
if (challengePreviews.isEmpty()) {

Box(modifier = Modifier.padding(20.dp)) {
WalkiePositiveButton(text = "도전하러 가기") {
onGotoChallengeClicked()
Column {
Spacer(modifier = Modifier.height(30.dp))
Text(
text = "챌린지에 도전하고 프로필에 뱃지를 채워보세요!",
style = WalkieTypography.Body1_Normal.copy(color = Color.Black.copy(alpha = 0.5f))
)
}
}

Box(modifier = Modifier.padding(20.dp)) {
WalkiePositiveButton(text = "도전하러 가기") {
onGotoChallengeClicked()
}
}
} else {
Column(Modifier.fillMaxWidth()) {
challengePreviews.forEach {
ChallengeItem(
Modifier.padding(horizontal = 20.dp),
it.type.getColor(),
text = it.title
) {
onChallengePreviewClicked(it.id)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.whyranoid.domain.model.challenge.Badge
import com.whyranoid.domain.model.challenge.ChallengePreview
import com.whyranoid.domain.model.post.PostPreview
import com.whyranoid.domain.model.user.User
import com.whyranoid.domain.model.user.UserDetail
import com.whyranoid.domain.repository.AccountRepository
import com.whyranoid.domain.usecase.GetChallengingPreviewsUseCase
import com.whyranoid.domain.usecase.GetPostUseCase
import com.whyranoid.domain.usecase.GetUserBadgesUseCase
import com.whyranoid.domain.usecase.GetUserDetailUseCase
Expand All @@ -32,6 +34,7 @@ data class UserPageState(
val userBadgesState: UiState<List<Badge>> = UiState.Idle,
val userPostPreviewsState: UiState<List<PostPreview>> = UiState.Idle,
val calendarPreviewsState: UiState<List<PostPreview>> = UiState.Idle,
val challengingPreviewsState: UiState<List<ChallengePreview>> = UiState.Idle,
)

class UserPageViewModel(
Expand All @@ -43,6 +46,7 @@ class UserPageViewModel(
private val signOutUseCase: SignOutUseCase,
private val followUseCase: FollowUseCase,
private val unFollowUseCase: UnFollowUseCase,
private val getChallengingPreviewsUseCase: GetChallengingPreviewsUseCase,
) : ViewModel(), ContainerHost<UserPageState, UserPageSideEffect> {

override val container = container<UserPageState, UserPageSideEffect>(UserPageState())
Expand Down Expand Up @@ -132,9 +136,9 @@ class UserPageViewModel(
requireNotNull(state.userDetailState.getDataOrNull()).copy(
isFollowing = true,
followerCount = (
state.userDetailState.getDataOrNull()?.followerCount
?: 0
) + 1,
state.userDetailState.getDataOrNull()?.followerCount
?: 0
) + 1,
),
),
)
Expand All @@ -152,9 +156,9 @@ class UserPageViewModel(
requireNotNull(state.userDetailState.getDataOrNull()).copy(
isFollowing = false,
followerCount = (
state.userDetailState.getDataOrNull()?.followerCount
?: 0
) - 1,
state.userDetailState.getDataOrNull()?.followerCount
?: 0
) - 1,
),
),
)
Expand All @@ -163,6 +167,23 @@ class UserPageViewModel(
}
}

fun getChallengingPreviews(uid: Long) = intent {
reduce {
state.copy(challengingPreviewsState = UiState.Loading)
}
getChallengingPreviewsUseCase(uid.toInt()).onSuccess { list ->
reduce {
state.copy(
challengingPreviewsState = UiState.Success(list),
)
}
}.onFailure {
reduce {
state.copy(challengingPreviewsState = UiState.Error(it.message.toString()))
}
}
}

fun signOut() {
viewModelScope.launch {
signOutUseCase()
Expand Down

0 comments on commit d8d7ee5

Please sign in to comment.