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/#231] 스크랩 다이얼로그 수정 #235

Merged
merged 4 commits into from
Sep 10, 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
13 changes: 7 additions & 6 deletions core/src/main/java/com/terning/core/type/ColorType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ import com.terning.core.designsystem.theme.CalRedBc
import com.terning.core.designsystem.theme.CalRedLi

enum class ColorType(
val typeName: String,
val main: Color,
val border: Color,
val sub: Color
) {
RED(main = CalRed, border = CalRedLi, sub = CalRedBc),
ORANGE(main = CalOrange2, border = CalOrangeLi, sub = CalOrangeBc),
GREEN(main = CalGreen2, border = CalGreenLi, sub = CalGreenBc),
BLUE(main = CalBlue2, border = CalBlueLi, sub = CalBlueBc),
PURPLE(main = CalPurple, border = CalPurpleLi, sub = CalPurpleBc),
PINK(main = CalPink, border = CalPinkLi, sub = CalPinkBc);
RED(typeName = "red", main = CalRed, border = CalRedLi, sub = CalRedBc),
ORANGE(typeName = "orange", main = CalOrange2, border = CalOrangeLi, sub = CalOrangeBc),
GREEN(typeName = "green", main = CalGreen2, border = CalGreenLi, sub = CalGreenBc),
BLUE(typeName = "blue", main = CalBlue2, border = CalBlueLi, sub = CalBlueBc),
PURPLE(typeName = "purple", main = CalPurple, border = CalPurpleLi, sub = CalPurpleBc),
PINK(typeName = "pink", main = CalPink, border = CalPinkLi, sub = CalPinkBc);

companion object {
fun findColorType(mainColor: Color): ColorType? = entries.find { it.main == mainColor }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable
@Serializable
data class ScrapColorRequestDto(
@SerialName("color")
val color: Int? = null,
val color: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.terning.domain.entity.calendar

data class CalendarScrapRequest(
val id: Long,
val color: Int? = 0,
val color: String? = "red",
)
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ fun ScrapDialog(
internshipAnnouncementId: Long,
companyImage: String,
isScrapped: Boolean,
onDismissRequest: () -> Unit,
onClickChangeColor: () -> Unit,
onClickNavigateButton: (Long) -> Unit,
onDismissRequest: () -> Unit = {},
onScrapAnnouncement: () -> Unit = {},
onClickChangeColor: () -> Unit = {},
onClickNavigateButton: (Long) -> Unit = {},
viewModel: ScrapDialogViewModel = hiltViewModel()
) {
val context = LocalContext.current
Expand All @@ -79,6 +80,7 @@ fun ScrapDialog(
is ScrapDialogSideEffect.ShowToast -> {
context.toast(sideEffect.message)
}

is ScrapDialogSideEffect.DismissDialog -> {
viewModel.initUiState()
onDismissRequest()
Expand All @@ -90,6 +92,8 @@ fun ScrapDialog(
)

is ScrapDialogSideEffect.ScrappedAnnouncement -> {
onScrapAnnouncement()
onDismissRequest()
}
}
}
Expand All @@ -115,8 +119,11 @@ fun ScrapDialog(
isColorChangedOnce = uiState.isColorChangedOnce,
onClickColorButton = viewModel::changeSelectedColor,
onClickColorChangeButton = {
if(uiState.isColorChanged)
viewModel.patchScrap(scrapId = internshipAnnouncementId, color = uiState.selectedColorType)
if (uiState.isColorChanged)
viewModel.patchScrap(
scrapId = internshipAnnouncementId,
color = uiState.selectedColorType
)
},
onClickNavigateButton = viewModel::navigateToDetail,
onClickScrapButton = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
package com.terning.feature.dialog.detail

import androidx.compose.ui.graphics.Color
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.terning.core.designsystem.theme.CalBlue1
import com.terning.core.designsystem.theme.CalBlue2
import com.terning.core.designsystem.theme.CalGreen1
import com.terning.core.designsystem.theme.CalGreen2
import com.terning.core.designsystem.theme.CalOrange1
import com.terning.core.designsystem.theme.CalOrange2
import com.terning.core.designsystem.theme.CalPink
import com.terning.core.designsystem.theme.CalPurple
import com.terning.core.designsystem.theme.CalRed
import com.terning.core.designsystem.theme.CalYellow
import com.terning.core.type.ColorType
import com.terning.domain.entity.calendar.CalendarScrapRequest
import com.terning.domain.repository.ScrapRepository
Expand Down Expand Up @@ -76,9 +65,8 @@ class ScrapDialogViewModel @Inject constructor(
}

fun postScrap(id: Long, color: ColorType) {
val colorIndex = getColorIndex(color.main)
viewModelScope.launch {
scrapRepository.postScrap(CalendarScrapRequest(id, colorIndex))
scrapRepository.postScrap(CalendarScrapRequest(id, color.typeName))
.onSuccess {
with(_sideEffect) {
emit(ScrapDialogSideEffect.ShowToast(R.string.dialog_scrap_scrapped))
Expand All @@ -91,8 +79,7 @@ class ScrapDialogViewModel @Inject constructor(
}

fun patchScrap(scrapId: Long, color: ColorType) = viewModelScope.launch {
val colorIndex = getColorIndex(color.main)
scrapRepository.patchScrap(CalendarScrapRequest(scrapId, colorIndex))
scrapRepository.patchScrap(CalendarScrapRequest(scrapId, color.typeName))
.onSuccess {
_sideEffect.emit(ScrapDialogSideEffect.PatchedScrap)
_uiState.update { currentState ->
Expand All @@ -106,17 +93,4 @@ class ScrapDialogViewModel @Inject constructor(
_sideEffect.emit(ScrapDialogSideEffect.ShowToast(R.string.server_failure))
}
}

private fun getColorIndex(color: Color): Int = listOf(
CalRed,
CalOrange1,
CalOrange2,
CalYellow,
CalGreen1,
CalGreen2,
CalBlue1,
CalBlue2,
CalPurple,
CalPink
).indexOf(color)
}
Loading