Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX/#220] Group / state 변경 #224

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.boostcamp.mapisode.mygroup.model

import androidx.compose.runtime.Immutable
import com.boostcamp.mapisode.model.GroupModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import java.util.Date

@Immutable
data class GroupUiModel(
val id: String,
val adminUser: String,
val createdAt: Date,
val description: String,
val imageUrl: String,
val name: String,
val members: ImmutableList<String>,
) {
Comment on lines +9 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GroupUiModel에 꼭 Immutable을 붙여야 하는 이유가 Date 때문인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 Immutable을 선언해도 해도 Date 객체가 java.util 에서 제공하는 거라 객체는 unstable이겠네요.
java.util 의 Date 대신 kotlinx 에서 제공하는 LocalDate 타입 쓰면 immutable 타입으로 사용 가능하다 하는데 이거로 대체하기에는 시간이 없네요 ㅠㅠ

fun toGroupModel(): GroupModel = GroupModel(
id = id,
adminUser = adminUser,
createdAt = createdAt,
description = description,
imageUrl = imageUrl,
name = name,
members = members.toList(),
)
}

fun GroupModel.toGroupUiModel(): GroupUiModel = GroupUiModel(
id = id,
adminUser = adminUser,
createdAt = createdAt,
description = description,
imageUrl = imageUrl,
name = name,
members = members.toImmutableList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fun GroupDetailContent(
0 -> {
if (uiState.group != null) {
GroupDetailContent(
group = uiState.group,
group = uiState.group.toGroupModel(),
members = uiState.membersInfo,
onIssueCodeClick = onIssueCodeClick,
onGroupOutClick = onGroupOutClick,
Expand Down
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,17 +1,19 @@
package com.boostcamp.mapisode.mygroup.state

import androidx.compose.runtime.Immutable
import com.boostcamp.mapisode.model.GroupModel
import com.boostcamp.mapisode.mygroup.model.GroupUiEpisodeModel
import com.boostcamp.mapisode.mygroup.model.GroupUiMemberModel
import com.boostcamp.mapisode.mygroup.model.GroupUiModel
import com.boostcamp.mapisode.ui.base.UiState
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf

@Immutable
data class GroupDetailState(
val isGroupIdCaching: Boolean = true,
val isGroupLoading: Boolean = false,
val isGroupOwner: Boolean = false,
val group: GroupModel? = null,
val membersInfo: List<GroupUiMemberModel> = emptyList(),
val episodes: List<GroupUiEpisodeModel> = emptyList(),
val group: GroupUiModel? = null,
val membersInfo: ImmutableList<GroupUiMemberModel> = persistentListOf(),
val episodes: ImmutableList<GroupUiEpisodeModel> = persistentListOf(),
) : UiState
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 @@ -9,10 +9,12 @@ import com.boostcamp.mapisode.mygroup.R
import com.boostcamp.mapisode.mygroup.intent.GroupDetailIntent
import com.boostcamp.mapisode.mygroup.model.GroupUiMemberModel
import com.boostcamp.mapisode.mygroup.model.toGroupUiEpisodeModel
import com.boostcamp.mapisode.mygroup.model.toGroupUiModel
import com.boostcamp.mapisode.mygroup.sideeffect.GroupDetailSideEffect
import com.boostcamp.mapisode.mygroup.state.GroupDetailState
import com.boostcamp.mapisode.ui.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -97,7 +99,7 @@ class GroupDetailViewModel @Inject constructor(
intent {
copy(
isGroupLoading = false,
group = group,
group = group.toGroupUiModel(),
)
}
if (group.adminUser == userPreferenceDataStore.getUserId().first()) {
Expand Down Expand Up @@ -154,7 +156,7 @@ class GroupDetailViewModel @Inject constructor(

intent {
copy(
membersInfo = memberInfo,
membersInfo = memberInfo.toImmutableList(),
)
}
}
Expand Down Expand Up @@ -186,7 +188,7 @@ class GroupDetailViewModel @Inject constructor(
member.id == it.createdBy
}?.name ?: ""
it.toGroupUiEpisodeModel(name)
},
}.toImmutableList(),
)
}
} catch (e: Exception) {
Expand Down
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
Loading