From 3c71303aafa2e45681225b656627ec573220bf31 Mon Sep 17 00:00:00 2001 From: TaewoongR Date: Wed, 4 Dec 2024 14:14:00 +0900 Subject: [PATCH] =?UTF-8?q?fix/#220=20:=20=EC=B0=B8=EC=97=AC=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20state=20immutable=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - core:model의 모델을 state로 사용 -> 화면 전용 immutable 모델 선언 및 state 사용 - uiState 선언시 등호 대신 by 사용하여 State 내부 타입 바로 접근 --- .../mapisode/mygroup/screen/GroupJoinScreen.kt | 13 ++++++------- .../mapisode/mygroup/state/GroupJoinState.kt | 4 ++-- .../mygroup/viewmodel/GroupJoinViewModel.kt | 3 ++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/screen/GroupJoinScreen.kt b/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/screen/GroupJoinScreen.kt index 24ca8a07..11585cbe 100644 --- a/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/screen/GroupJoinScreen.kt +++ b/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/screen/GroupJoinScreen.kt @@ -17,7 +17,6 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.State import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable @@ -59,7 +58,7 @@ fun GroupJoinScreen( viewModel: GroupJoinViewModel = hiltViewModel(), ) { val context = LocalContext.current - val uiState = viewModel.uiState.collectAsStateWithLifecycle() + val uiState by viewModel.uiState.collectAsStateWithLifecycle() val effect = rememberFlowWithLifecycle( flow = viewModel.sideEffect, initialValue = GroupJoinSideEffect.Idle, @@ -95,7 +94,7 @@ fun GroupJoinScreen( @Composable fun GroupJoinContent( - uiState: State, + uiState: GroupJoinState, onBackClick: () -> Unit, onGetGroup: (String) -> Unit, onJoinGroup: () -> Unit, @@ -193,13 +192,13 @@ fun GroupJoinContent( MapisodeDivider(direction = Direction.Horizontal, thickness = Thickness.Thin) Spacer(modifier = Modifier.padding(10.dp)) } - if (uiState.value.isGroupExist && uiState.value.group != null) { + if (uiState.isGroupExist && uiState.group != null) { item { - ConfirmJoinGroup(uiState.value.group!!) + ConfirmJoinGroup(uiState.group.toGroupModel()) Spacer(modifier = Modifier.padding(bottom = 70.dp)) } } - if (uiState.value.isGroupExist.not() || uiState.value.group == null) { + if (uiState.isGroupExist.not() || uiState.group == null) { item { MapisodeText( text = "존재하지 않는 그룹입니다.", @@ -208,7 +207,7 @@ fun GroupJoinContent( } } } - if (uiState.value.isGroupExist && uiState.value.group != null) { + if (uiState.isGroupExist && uiState.group != null) { Column( modifier = Modifier .fillMaxWidth() diff --git a/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/state/GroupJoinState.kt b/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/state/GroupJoinState.kt index b634870a..824d81f0 100644 --- a/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/state/GroupJoinState.kt +++ b/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/state/GroupJoinState.kt @@ -1,7 +1,7 @@ package com.boostcamp.mapisode.mygroup.state import androidx.compose.runtime.Immutable -import com.boostcamp.mapisode.model.GroupModel +import com.boostcamp.mapisode.mygroup.model.GroupCreationModel import com.boostcamp.mapisode.ui.base.UiState @Immutable @@ -9,5 +9,5 @@ data class GroupJoinState( val isGroupExist: Boolean = false, val isGroupLoading: Boolean = false, val isJoinedSuccess: Boolean = false, - val group: GroupModel? = null, + val group: GroupCreationModel? = null, ) : UiState diff --git a/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/viewmodel/GroupJoinViewModel.kt b/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/viewmodel/GroupJoinViewModel.kt index ffb5cf54..f301c3f3 100644 --- a/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/viewmodel/GroupJoinViewModel.kt +++ b/feature/mygroup/src/main/java/com/boostcamp/mapisode/mygroup/viewmodel/GroupJoinViewModel.kt @@ -5,6 +5,7 @@ import com.boostcamp.mapisode.datastore.UserPreferenceDataStore import com.boostcamp.mapisode.mygroup.GroupRepository import com.boostcamp.mapisode.mygroup.R import com.boostcamp.mapisode.mygroup.intent.GroupJoinIntent +import com.boostcamp.mapisode.mygroup.model.toGroupCreationModel import com.boostcamp.mapisode.mygroup.sideeffect.GroupJoinSideEffect import com.boostcamp.mapisode.mygroup.state.GroupJoinState import com.boostcamp.mapisode.ui.base.BaseViewModel @@ -54,7 +55,7 @@ class GroupJoinViewModel @Inject constructor( intent { copy(isGroupLoading = true) } try { val group = groupRepository.getGroupByInviteCodes(inviteCodes) - intent { copy(isGroupExist = true, group = group) } + intent { copy(isGroupExist = true, group = group.toGroupCreationModel()) } } catch (e: Exception) { intent { copy(isGroupExist = false) } postSideEffect(GroupJoinSideEffect.ShowToast(R.string.group_join_not_exist))