Skip to content

Commit

Permalink
feat: 미션 조회 실패 다이얼로그 추가
Browse files Browse the repository at this point in the history
eshc123 committed Nov 18, 2024
1 parent f099d3b commit 750c24a
Showing 5 changed files with 74 additions and 14 deletions.
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
@@ -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

@@ -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) }

@@ -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 -> { }
}
}
}
@@ -141,6 +152,18 @@ fun BoardRoute(
}
}

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

if (isShownDeleteMissionDialog) {
DeleteMissionDialog(
onDismissRequest = {
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ class BoardViewModel @Inject constructor(

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

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

@@ -121,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?>()
@@ -194,7 +194,7 @@ class BoardViewModel @Inject constructor(

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

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

else -> {
_missionVerificationUiModel.emit(MissionVerificationUiModel.Error)
if(!isSameAsLastMission()) _missionError.emit(MissionError.NOT_EXIST)
handleMissionError(isSameAsLastMission())
}
}
}
@@ -293,6 +293,15 @@ class BoardViewModel @Inject constructor(
}
}

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 -> {
4 changes: 3 additions & 1 deletion feature/board/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -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 750c24a

Please sign in to comment.