Skip to content

Commit

Permalink
[FEAT/#220] 공고 상세 페이지 스크랩 다이어로그 띄우기
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Sep 9, 2024
1 parent fdd3033 commit 2dfd5b7
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ fun ScrapDialog(
title: String,
scrapColor: Color,
deadline: String,
startYear: Int,
startMonth: Int,
startYear: Int = 0,
startMonth: Int = 0,
startDate: String = "",
workingPeriod: String,
scrapId: Long,
internshipAnnouncementId: Long,
scrapId: Long = -1,
internshipAnnouncementId: Long = -1,
companyImage: String,
isScrapped: Boolean,
onDismissRequest: () -> Unit,
onClickChangeColor: () -> Unit,
onClickNavigateButton: (Long) -> Unit,
viewModel: ScrapDialogViewModel = hiltViewModel()
onClickChangeColor: () -> Unit = {},
onClickNavigateButton: (Long) -> Unit = {},
viewModel: ScrapDialogViewModel = hiltViewModel(),
) {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
Expand All @@ -81,6 +82,7 @@ fun ScrapDialog(
is ScrapDialogSideEffect.ShowToast -> {
context.toast(sideEffect.message)
}

is ScrapDialogSideEffect.DismissDialog -> {
viewModel.initUiState()
onDismissRequest()
Expand Down Expand Up @@ -110,6 +112,7 @@ fun ScrapDialog(
deadline = deadline,
startYear = startYear,
startMonth = startMonth,
startDate = startDate,
workingPeriod = workingPeriod,
isScrapped = isScrapped,
companyImage = companyImage,
Expand All @@ -118,8 +121,8 @@ fun ScrapDialog(
isColorChangedOnce = uiState.isColorChangedOnce,
onClickColorButton = viewModel::changeSelectedColor,
onClickColorChangeButton = {
if(uiState.isColorChanged)
viewModel.patchScrap(scrapId = scrapId, color = uiState.selectedColorType)
if (uiState.isColorChanged)
viewModel.patchScrap(scrapId = scrapId, color = uiState.selectedColorType)
},
onClickNavigateButton = viewModel::navigateToDetail,
onClickScrapButton = {
Expand All @@ -136,6 +139,7 @@ private fun ScrapDialogScreen(
deadline: String,
startYear: Int,
startMonth: Int,
startDate: String,
workingPeriod: String,
isScrapped: Boolean,
companyImage: String,
Expand All @@ -145,7 +149,7 @@ private fun ScrapDialogScreen(
onClickColorButton: (ColorType) -> Unit,
onClickNavigateButton: () -> Unit,
onClickColorChangeButton: () -> Unit,
onClickScrapButton: () -> Unit
onClickScrapButton: () -> Unit,
) {
Box(
modifier = Modifier
Expand Down Expand Up @@ -176,6 +180,7 @@ private fun ScrapDialogScreen(
)

Spacer(modifier = Modifier.height(15.dp))

Box(
modifier = Modifier
.height(TerningTheme.typography.title4.getFixHeightByMaxLine(3))
Expand Down Expand Up @@ -250,10 +255,17 @@ private fun ScrapDialogScreen(
title = stringResource(id = R.string.intern_info_working),
value = workingPeriod
)
InternInfoRow(
title = stringResource(id = R.string.intern_info_start_date),
value = "${startYear}${startMonth}"
)
if (startDate == "") {
InternInfoRow(
title = stringResource(id = R.string.intern_info_start_date),
value = "${startYear}${startMonth}"
)
} else {
InternInfoRow(
title = stringResource(id = R.string.intern_info_start_date),
value = startDate
)
}
}
}

Expand All @@ -277,7 +289,7 @@ private fun ScrapDialogScreen(
@Composable
private fun NewScrapButton(
onClickScrapButton: () -> Unit,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
) {
RoundButton(
style = TerningTheme.typography.button3,
Expand All @@ -295,7 +307,7 @@ private fun DetailScrapButton(
isColorChangedOnce: Boolean,
onClickNavigateButton: () -> Unit,
onClickColorChangeButton: () -> Unit,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
) {
Row(
modifier = modifier
Expand Down Expand Up @@ -329,6 +341,7 @@ private fun ScrapDialogPreview() {
deadline = "2024/09/07",
startYear = 2024,
startMonth = 11,
startDate = "",
workingPeriod = "2개월",
companyImage = "",
isScrapped = false,
Expand Down
50 changes: 40 additions & 10 deletions feature/src/main/java/com/terning/feature/intern/InternRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.navigation.NavHostController
import com.terning.core.designsystem.component.dialog.TerningBasicDialog
import com.terning.core.designsystem.component.topappbar.BackButtonTopAppBar
import com.terning.core.designsystem.theme.CalRed
import com.terning.core.designsystem.theme.Grey200
import com.terning.core.designsystem.theme.Grey400
import com.terning.core.designsystem.theme.TerningTheme
Expand All @@ -32,6 +32,8 @@ import com.terning.core.extension.toast
import com.terning.core.state.UiState
import com.terning.domain.entity.intern.InternInfo
import com.terning.feature.R
import com.terning.feature.dialog.cancel.ScrapCancelDialog
import com.terning.feature.dialog.detail.ScrapDialog
import com.terning.feature.intern.component.InternBottomBar
import com.terning.feature.intern.component.InternCompanyInfo
import com.terning.feature.intern.component.InternInfoRow
Expand All @@ -43,7 +45,7 @@ import java.text.DecimalFormat
@Composable
fun InternRoute(
announcementId: Long = 0,
modifier: Modifier = Modifier,
modifier: Modifier,
viewModel: InternViewModel = hiltViewModel(),
navController: NavHostController,
) {
Expand Down Expand Up @@ -74,7 +76,19 @@ fun InternRoute(
internUiState = internState,
modifier = modifier,
internInfo = (internState.loadState as UiState.Success).data,
navController = navController
navController = navController,
onDismissCancelDialog = {
viewModel.updateScrapDialogVisibility(false)
},
onDismissInternDialog = {
viewModel.updateScrapDialogVisibility(false)
},
onClickScrapButton = { detail ->
with(viewModel) {
updateInternshipModel(detail)
updateScrapDialogVisibility(true)
}
}
)
}
}
Expand All @@ -87,6 +101,9 @@ fun InternScreen(
viewModel: InternViewModel = hiltViewModel(),
internUiState: InternUiState,
internInfo: InternInfo,
onDismissCancelDialog: (Boolean) -> Unit,
onDismissInternDialog: () -> Unit,
onClickScrapButton: (InternInfo) -> Unit,
) {
val decimal = DecimalFormat("#,###")

Expand Down Expand Up @@ -231,16 +248,29 @@ fun InternScreen(
scrapCount = decimal.format(internInfo.scrapCount),
scrapId = internInfo.scrapId,
onScrapClick = {
viewModel.updateScrapDialogVisible(true)
viewModel.updateScrapDialogVisibility(true)
}
)

if (internUiState.isScrapDialogVisible) {
TerningBasicDialog(
onDismissRequest = {
viewModel.updateScrapDialogVisible(false)
},
content = {},
if (internUiState.isCancelDialogVisibility) {
internUiState.scrapId?.run {
ScrapCancelDialog(
scrapId = this,
onDismissRequest = onDismissCancelDialog
)
}
}

if (internUiState.isScrapDialogVisibility) {
ScrapDialog(
title = internInfo.title,
scrapColor = CalRed,
deadline = internInfo.deadline,
startDate = internInfo.startDate,
workingPeriod = internInfo.workingPeriod,
companyImage = internInfo.companyImage,
isScrapped = internUiState.isScrappedState,
onDismissRequest = onDismissInternDialog,
)
}
}
Expand Down
28 changes: 12 additions & 16 deletions feature/src/main/java/com/terning/feature/intern/InternViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.terning.feature.intern

import androidx.compose.ui.graphics.Color
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.terning.core.state.UiState
import com.terning.domain.entity.CalendarScrapRequest
import com.terning.domain.entity.intern.InternInfo
import com.terning.domain.repository.InternRepository
import com.terning.domain.repository.ScrapRepository
import com.terning.feature.R
Expand Down Expand Up @@ -60,7 +60,7 @@ class InternViewModel @Inject constructor(
it.copy(isScrap = UiState.Success(true))
}
getInternInfo(id)
updateScrapDialogVisible(false)
updateScrapDialogVisibility(false)
_sideEffect.emit(
InternViewSideEffect.Toast(R.string.intern_scrap_add_toast_message)
)
Expand All @@ -85,7 +85,7 @@ class InternViewModel @Inject constructor(
it.copy(isScrap = UiState.Success(false))
}
getInternInfo(announcementId)
updateScrapDialogVisible(false)
updateScrapDialogVisibility(false)
_sideEffect.emit(InternViewSideEffect.Toast(R.string.intern_scrap_delete_toast_message))
}.onFailure {
_sideEffect.emit(
Expand All @@ -96,27 +96,23 @@ class InternViewModel @Inject constructor(
}
}

fun updateSelectColor(newColor: Color) {
fun updateCancelDialogVisibility(visible: Boolean) {
_internUiState.update {
it.copy(selectedColor = newColor)
it.copy(isCancelDialogVisibility = visible)
}
}

fun updateScrapDialogVisible(visible: Boolean) {
fun updateScrapDialogVisibility(visible: Boolean) {
_internUiState.update {
it.copy(isScrapDialogVisible = visible)
it.copy(isScrapDialogVisibility = visible)
}
}

fun updatePaletteOpen(open: Boolean) {
_internUiState.update {
it.copy(isPaletteOpen = open)
}
}

fun updateColorChange(change: Boolean) {
_internUiState.update {
it.copy(isColorChange = change)
fun updateInternshipModel(scrapDetailModel: InternInfo?) {
_internUiState.update { currentState ->
currentState.copy(
internshipModel = scrapDetailModel
)
}
}

Expand Down
Loading

0 comments on commit 2dfd5b7

Please sign in to comment.