Skip to content

Commit

Permalink
Merge pull request #80 from Nexters/fix/board-back-to-onboarding-error
Browse files Browse the repository at this point in the history
보드판 화면에서 미션 조회 실패 시 무한 반복 오류 수정
  • Loading branch information
eshc123 authored Dec 4, 2024
2 parents 2dee184 + 750c24a commit 847b766
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation(project(":core:domain:mission"))
implementation(project(":core:domain:common"))
implementation(project(":core:domain:auth"))
implementation(project(":core:domain:onboarding"))
implementation(project(":core:ui"))

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.goalpanzi.mission_mate.feature.board.component.dialog

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.DialogProperties
import com.goalpanzi.mission_mate.core.designsystem.component.MissionMateDialog
import com.goalpanzi.mission_mate.feature.board.R

@Composable
fun InvalidMissionErrorDialog(
onDismissRequest: () -> Unit,
onClickOk: () -> Unit,
modifier: Modifier = Modifier
) {
MissionMateDialog(
titleId = R.string.board_mission_not_exist,
onDismissRequest = onDismissRequest,
onClickOk = onClickOk,
okTextId = R.string.retry,
dialogProperties = DialogProperties(
usePlatformDefaultWidth = false,
dismissOnBackPress = false,
dismissOnClickOutside = false
)
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.goalpanzi.mission_mate.feature.board.model

enum class MissionError {
NOT_EXIST,
}
NOT_EXIST, INVALID_MISSION
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import com.goalpanzi.mission_mate.feature.board.model.uimodel.MissionBoardUiMode
import com.goalpanzi.mission_mate.feature.board.model.uimodel.MissionUiModel
import com.goalpanzi.mission_mate.feature.board.model.uimodel.MissionVerificationUiModel
import com.goalpanzi.mission_mate.core.designsystem.component.StableImage
import com.goalpanzi.mission_mate.feature.board.component.dialog.InvalidMissionErrorDialog
import com.goalpanzi.mission_mate.feature.board.model.MissionError
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -83,6 +85,7 @@ fun BoardRoute(
onRefresh = viewModel::refreshMissionData
)
var isShownDeleteMissionDialog by remember { mutableStateOf(false) }
var isShownNotLoadedErrorDialog by remember { mutableStateOf(false) }
var isShownBoardRewardDialog by remember { mutableStateOf<BoardReward?>(null) }
var isShownInvitationCodeDialog by remember { mutableStateOf(false) }

Expand Down Expand Up @@ -123,11 +126,19 @@ fun BoardRoute(
}
}
launch {
viewModel.missionError.collect {
if(it != null){
Toast.makeText(context,context.getString(R.string.board_mission_not_exist), Toast.LENGTH_SHORT).show()
onNavigateOnboarding()
return@collect
viewModel.missionError.collect { error ->
when(error){
MissionError.INVALID_MISSION -> {
isShownNotLoadedErrorDialog = true
viewModel.resetMissionError()
}
MissionError.NOT_EXIST -> {
Toast.makeText(context,context.getString(R.string.board_mission_not_exist), Toast.LENGTH_SHORT).show()
viewModel.resetMissionError()
onNavigateOnboarding()
return@collect
}
else -> { }
}
}
}
Expand All @@ -141,6 +152,18 @@ fun BoardRoute(
}
}

if (isShownNotLoadedErrorDialog) {
InvalidMissionErrorDialog(
onDismissRequest = {
isShownNotLoadedErrorDialog = false
},
onClickOk = {
isShownNotLoadedErrorDialog = false
viewModel.fetchMissionData()
}
)
}

if (isShownDeleteMissionDialog) {
DeleteMissionDialog(
onDismissRequest = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.goalpanzi.mission_mate.core.domain.common.DomainResult
import com.goalpanzi.mission_mate.core.domain.common.model.mission.MissionStatus.Companion.statusString
import com.goalpanzi.mission_mate.core.domain.mission.model.BoardReward
import com.goalpanzi.mission_mate.core.domain.mission.usecase.DeleteMissionUseCase
import com.goalpanzi.mission_mate.core.domain.mission.usecase.GetMissionBoardsUseCase
import com.goalpanzi.mission_mate.core.domain.mission.usecase.GetMissionUseCase
import com.goalpanzi.mission_mate.core.domain.mission.usecase.GetMissionVerificationsUseCase
import com.goalpanzi.mission_mate.core.domain.mission.usecase.GetMyMissionVerificationUseCase
import com.goalpanzi.mission_mate.core.domain.mission.usecase.VerifyMissionUseCase
import com.goalpanzi.mission_mate.core.domain.mission.usecase.ViewVerificationUseCase
import com.goalpanzi.mission_mate.core.domain.onboarding.usecase.GetJoinedMissionsUseCase
import com.goalpanzi.mission_mate.core.domain.setting.usecase.GetViewedTooltipUseCase
import com.goalpanzi.mission_mate.core.domain.setting.usecase.SetViewedTooltipUseCase
import com.goalpanzi.mission_mate.core.domain.user.usecase.GetCachedMemberIdUseCase
Expand Down Expand Up @@ -43,6 +44,7 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
Expand All @@ -59,16 +61,16 @@ class BoardViewModel @Inject constructor(
private val deleteMissionUseCase: DeleteMissionUseCase,
private val profileUseCase: ProfileUseCase,
private val setViewedTooltipUseCase: SetViewedTooltipUseCase,
private val verifyMissionUseCase: VerifyMissionUseCase,
private val getMyMissionVerificationUseCase : GetMyMissionVerificationUseCase,
private val getJoinedMissionsUseCase: GetJoinedMissionsUseCase,
private val getMyMissionVerificationUseCase: GetMyMissionVerificationUseCase,
private val viewVerificationUseCase: ViewVerificationUseCase
) : ViewModel() {

val missionId: Long = savedStateHandle.get<Long>("missionId")!!

val viewedToolTip: StateFlow<Boolean> = getViewedTooltipUseCase().stateIn(
viewModelScope,
started = SharingStarted.WhileSubscribed(500),
started = SharingStarted.WhileSubscribed(5_000),
initialValue = true
)

Expand Down Expand Up @@ -106,7 +108,7 @@ class BoardViewModel @Inject constructor(
memberId == mission.missionDetail.hostMemberId
}.stateIn(
viewModelScope,
started = SharingStarted.WhileSubscribed(500),
started = SharingStarted.WhileSubscribed(5_000),
initialValue = false
)

Expand All @@ -119,7 +121,7 @@ class BoardViewModel @Inject constructor(
getMissionState(missionBoard, mission, missionVerification)
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(500),
started = SharingStarted.WhileSubscribed(5_000),
initialValue = MissionState.LOADING
)
private val _boardRewardEvent = MutableSharedFlow<BoardReward?>()
Expand Down Expand Up @@ -157,7 +159,13 @@ class BoardViewModel @Inject constructor(
is DomainResult.Success -> {
val myMemberId = getCachedMemberIdUseCase().first()

_missionBoardUiModel.emit(MissionBoardUiModel.Success(it.data.toUiModel(myMemberId)))
_missionBoardUiModel.emit(
MissionBoardUiModel.Success(
it.data.toUiModel(
myMemberId
)
)
)

val boardPieceList =
it.data.toUiModel(myMemberId).toBoardPieces(profileUseCase.getProfile())
Expand All @@ -166,7 +174,7 @@ class BoardViewModel @Inject constructor(
_boardPieces.emit(boardPieceList)
} else {
val isMoved =
boardPieces.value.find { it.isMe }?.index?.plus(1) == boardPieceList.find { it.isMe }?.index
boardPieces.value.find { it.isMe }?.index?.plus(1) == boardPieceList.find { it.isMe }?.index

val newList = PieceManager.getBoardPieces(
boardPieces.value,
Expand All @@ -175,7 +183,7 @@ class BoardViewModel @Inject constructor(
_boardPieces.emit(
newList
)
if(isMoved){
if (isMoved) {
delay(550)
_boardRewardEvent.emit(
it.data.missionBoards.find { it.isMyPosition }?.reward
Expand All @@ -186,7 +194,7 @@ class BoardViewModel @Inject constructor(

else -> {
_missionBoardUiModel.emit(MissionBoardUiModel.Error)
_missionError.emit(MissionError.NOT_EXIST)
handleMissionError(isSameAsLastMission())
}
}
}
Expand All @@ -203,7 +211,7 @@ class BoardViewModel @Inject constructor(

else -> {
_missionUiModel.emit(MissionUiModel.Error)
_missionError.emit(MissionError.NOT_EXIST)
handleMissionError(isSameAsLastMission())
}
}
}
Expand All @@ -220,7 +228,7 @@ class BoardViewModel @Inject constructor(

else -> {
_missionVerificationUiModel.emit(MissionVerificationUiModel.Error)
_missionError.emit(MissionError.NOT_EXIST)
handleMissionError(isSameAsLastMission())
}
}
}
Expand Down Expand Up @@ -275,13 +283,32 @@ class BoardViewModel @Inject constructor(
}
}
}
fun viewVerification(missionVerificationId : Long){

fun viewVerification(missionVerificationId: Long) {
viewModelScope.launch {
viewVerificationUseCase(missionVerificationId)
.collectLatest {
getMissionVerification()
.collectLatest {
getMissionVerification()
}
}
}

fun resetMissionError() {
_missionError.value = null
}

private suspend fun handleMissionError(isSameAsLastMission : Boolean){
if(isSameAsLastMission) _missionError.emit(MissionError.INVALID_MISSION)
else _missionError.emit(MissionError.NOT_EXIST)
}

private suspend fun isSameAsLastMission(): Boolean {
return when (val result = getJoinedMissionsUseCase(filter = statusString).firstOrNull()) {
is DomainResult.Success -> {
result.data.missions.lastOrNull()?.missionId == missionId
}

else -> false
}
}
}
4 changes: 3 additions & 1 deletion feature/board/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@
<string name="board_mission_detail_description_color_target">인증횟수(보드판 수)는 총 %d개</string>
<string name="board_mission_detail_delete">삭제하기</string>

<string name="board_mission_not_exist">미션을 불러올 수 없습니다.</string>
<string name="board_mission_not_exist">미션을 불러올 수 없어요.</string>
<string name="board_complete_error">에러가 발생하였습니다.</string>

<string name="ok">확인</string>
<string name="cancel">취소</string>
<string name="close">닫기</string>
<string name="upload">업로드</string>

<string name="retry">재시도</string>
</resources>

0 comments on commit 847b766

Please sign in to comment.