Skip to content

Commit

Permalink
fix/#220 : 참여 화면 state immutable 로 변경
Browse files Browse the repository at this point in the history
- core:model의 모델을 state로 사용 -> 화면 전용 immutable 모델 선언 및 state 사용
- uiState 선언시 등호 대신 by 사용하여 State 내부 타입 바로 접근
  • Loading branch information
TaewoongR committed Dec 5, 2024
1 parent 4ec647a commit 3c71303
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -95,7 +94,7 @@ fun GroupJoinScreen(

@Composable
fun GroupJoinContent(
uiState: State<GroupJoinState>,
uiState: GroupJoinState,
onBackClick: () -> Unit,
onGetGroup: (String) -> Unit,
onJoinGroup: () -> Unit,
Expand Down Expand Up @@ -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 = "존재하지 않는 그룹입니다.",
Expand All @@ -208,7 +207,7 @@ fun GroupJoinContent(
}
}
}
if (uiState.value.isGroupExist && uiState.value.group != null) {
if (uiState.isGroupExist && uiState.group != null) {
Column(
modifier = Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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
data class GroupJoinState(
val isGroupExist: Boolean = false,
val isGroupLoading: Boolean = false,
val isJoinedSuccess: Boolean = false,
val group: GroupModel? = null,
val group: GroupCreationModel? = null,
) : UiState
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 3c71303

Please sign in to comment.