diff --git a/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt b/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt index 2e95a0549..dc0089100 100644 --- a/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt +++ b/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt @@ -54,7 +54,7 @@ fun CalendarTopAppBar( Icon( painter = painterResource(id = R.drawable.ic_calendar_previous), contentDescription = stringResource(id = R.string.calendar_button_description_previous), - tint = Grey300, + tint = TerningMain, modifier = Modifier.noRippleClickable { onMonthNavigationButtonClicked(-1) } ) } @@ -68,7 +68,7 @@ fun CalendarTopAppBar( Icon( painter = painterResource(id = R.drawable.ic_calendar_next), contentDescription = stringResource(id = R.string.calendar_button_description_next), - tint = Grey300, + tint = TerningMain, modifier = Modifier.noRippleClickable { onMonthNavigationButtonClicked(1) } ) } diff --git a/data/src/main/java/com/terning/data/repositoryimpl/ScrapRepositoryImpl.kt b/data/src/main/java/com/terning/data/repositoryimpl/ScrapRepositoryImpl.kt index 57364e770..ccca0dc92 100644 --- a/data/src/main/java/com/terning/data/repositoryimpl/ScrapRepositoryImpl.kt +++ b/data/src/main/java/com/terning/data/repositoryimpl/ScrapRepositoryImpl.kt @@ -17,4 +17,9 @@ class ScrapRepositoryImpl @Inject constructor( : Result = runCatching { scrapDataSource.deleteScrap(scrapRequestModel) } + + override suspend fun patchScrap(scrapRequestModel: ScrapRequestModel) + : Result = runCatching { + scrapDataSource.patchScrap(scrapRequestModel) + } } \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/repository/ScrapRepository.kt b/domain/src/main/java/com/terning/domain/repository/ScrapRepository.kt index 69647c6d4..ed66f6393 100644 --- a/domain/src/main/java/com/terning/domain/repository/ScrapRepository.kt +++ b/domain/src/main/java/com/terning/domain/repository/ScrapRepository.kt @@ -5,4 +5,5 @@ import com.terning.domain.entity.request.ScrapRequestModel interface ScrapRepository { suspend fun postScrap(scrapRequestModel: ScrapRequestModel): Result suspend fun deleteScrap(scrapRequestModel: ScrapRequestModel): Result + suspend fun patchScrap(scrapRequestModel: ScrapRequestModel): Result } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt index e00b6f54a..a353dfb3e 100644 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt @@ -108,7 +108,7 @@ private fun CalendarScreen( CalendarTopAppBar( date = currentDate, isListExpanded = calendarUiState.isListEnabled, - isWeekExpanded = calendarUiState.isListEnabled, + isWeekExpanded = calendarUiState.isWeekEnabled, onListButtonClicked = { viewModel.changeListVisibility() if (calendarUiState.isWeekEnabled) { @@ -163,8 +163,9 @@ private fun CalendarScreen( }, contentTwo = { CalendarWeekScreen( - uiState = calendarUiState, + calendarUiState = calendarUiState, viewModel = viewModel, + navController = navController, modifier = Modifier .fillMaxSize(), ) @@ -177,7 +178,7 @@ private fun CalendarScreen( listState = listState, pages = state.getPageCount(), viewModel = viewModel, - uiState = calendarUiState, + navController = navController, modifier = Modifier .fillMaxSize() .padding(top = paddingValues.calculateTopPadding()) diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt index addc7f1e1..9a3126149 100644 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt @@ -1,14 +1,29 @@ package com.terning.feature.calendar.calendar +import android.util.Log +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.state.UiState +import com.terning.domain.entity.request.ScrapRequestModel import com.terning.domain.entity.response.CalendarScrapDetailModel import com.terning.domain.repository.CalendarRepository +import com.terning.domain.repository.ScrapRepository import com.terning.feature.R import com.terning.feature.calendar.month.CalendarMonthState import com.terning.feature.calendar.scrap.CalendarListState import com.terning.feature.calendar.week.CalendarWeekState +import com.terning.feature.intern.model.InternScrapState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableSharedFlow @@ -18,13 +33,13 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import timber.log.Timber import java.time.LocalDate import javax.inject.Inject @HiltViewModel class CalendarViewModel @Inject constructor( - private val calendarRepository: CalendarRepository + private val calendarRepository: CalendarRepository, + private val scrapRepository: ScrapRepository ) : ViewModel() { private var _uiState: MutableStateFlow = MutableStateFlow( @@ -91,10 +106,17 @@ class CalendarViewModel @Inject constructor( } } - fun updateInternDialogVisible(scrapDetailModel: CalendarScrapDetailModel?) { + fun updateInternDialogVisible(visibility: Boolean = false) { + _uiState.update { currentState -> + currentState.copy( + isInternshipClicked = visibility + ) + } + } + + fun updateInternshipModel(scrapDetailModel: CalendarScrapDetailModel?) { _uiState.update { currentState -> currentState.copy( - isInternshipClicked = !currentState.isInternshipClicked, internshipModel = scrapDetailModel ) } @@ -153,7 +175,6 @@ class CalendarViewModel @Inject constructor( _calendarWeekState.update { currentState -> currentState.copy( loadState = if (it.isNotEmpty()) UiState.Success(it) else UiState.Empty - //loadState = UiState.Success(it) ) } }, @@ -168,4 +189,66 @@ class CalendarViewModel @Inject constructor( } ) } + + fun deleteScrap(isFromWeekScreen: Boolean = false) = viewModelScope.launch { + _calendarWeekState.value.loadState + .takeIf { it is UiState.Success } + ?.let { ScrapRequestModel(_uiState.value.scrapId, null) }?.let { scrapRequestModel -> + scrapRepository.deleteScrap( + scrapRequestModel + ).onSuccess { + runCatching { + if (isFromWeekScreen) { + getScrapWeekList() + } else { + getScrapMonthList( + _uiState.value.selectedDate.year, + _uiState.value.selectedDate.monthValue + ) + } + }.onSuccess { + updateScrapCancelDialogVisible() + } + }.onFailure { + _calendarSideEffect.emit( + CalendarSideEffect.ShowToast(R.string.server_failure) + ) + } + } + } + + fun patchScrap(color: Color, isFromWeekScreen: Boolean = false) = viewModelScope.launch { + val scrapId = _uiState.value.internshipModel?.scrapId ?: 0 + val colorIndex = getColorIndex(color) + + scrapRepository.patchScrap(ScrapRequestModel(scrapId, colorIndex)) + .onSuccess { + runCatching { + if (isFromWeekScreen) { + getScrapWeekList() + } else { + getScrapMonthList( + _uiState.value.selectedDate.year, + _uiState.value.selectedDate.monthValue + ) + } + } + }.onFailure { + _calendarSideEffect.emit(CalendarSideEffect.ShowToast(R.string.server_failure)) + } + } + + private fun getColorIndex(color: Color): Int = listOf( + CalRed, + CalOrange1, + CalOrange2, + CalYellow, + CalGreen1, + CalGreen2, + CalBlue1, + CalBlue2, + CalPurple, + CalPink + ).indexOf(color) + } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDetailDialog.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDetailDialog.kt index a3118e705..9c9ab4102 100644 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDetailDialog.kt +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDetailDialog.kt @@ -8,11 +8,14 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon @@ -24,14 +27,18 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.window.DialogProperties +import coil.compose.AsyncImage +import coil.request.ImageRequest import com.terning.core.R import com.terning.core.designsystem.component.button.RoundButton import com.terning.core.designsystem.component.dialog.TerningBasicDialog @@ -40,6 +47,7 @@ import com.terning.core.designsystem.theme.CalBlue2 import com.terning.core.designsystem.theme.CalGreen2 import com.terning.core.designsystem.theme.CalRed import com.terning.core.designsystem.theme.Grey200 +import com.terning.core.designsystem.theme.Grey300 import com.terning.core.designsystem.theme.Grey350 import com.terning.core.designsystem.theme.Grey500 import com.terning.core.designsystem.theme.TerningMain @@ -50,12 +58,14 @@ import com.terning.core.extension.noRippleClickable import com.terning.domain.entity.response.CalendarScrapDetailModel import com.terning.feature.intern.component.InternInfoRow import com.terning.feature.intern.model.InternViewState +import java.time.LocalDate @Composable fun CalendarDetailDialog( + scrapDetailModel: CalendarScrapDetailModel?, onDismissRequest: () -> Unit, - onClickColor: (Color) -> Unit, - onClickNavigate: () -> Unit, + onClickChangeColorButton: (Color) -> Unit, + onClickNavigateButton: (Long) -> Unit, ) { TerningBasicDialog( onDismissRequest = onDismissRequest, @@ -67,22 +77,9 @@ fun CalendarDetailDialog( ) ) { InternDialogContent( - scrapDetailModel = CalendarScrapDetailModel( - scrapId = 1, - internshipAnnouncementId = 1, - title = "안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕안녕", - dDay = "D-8", - workingPeriod = "9개월", - color = "0xf3d1e3", - companyImage = "", - startYear = 2024, - startMonth = 8, - deadLine = "2024-07-13", - isScrapped = true - ), - state = InternViewState(), - onClickColor = onClickColor, - onClickNavigate = onClickNavigate + scrapDetailModel = scrapDetailModel, + onClickChangeColorButton = onClickChangeColorButton, + onClickNavigateButton = onClickNavigateButton ) } } @@ -90,13 +87,12 @@ fun CalendarDetailDialog( @Composable private fun InternDialogContent( - scrapDetailModel: CalendarScrapDetailModel, - state: InternViewState, - onClickColor: (Color) -> Unit, - onClickNavigate: () -> Unit + scrapDetailModel: CalendarScrapDetailModel?, + onClickChangeColorButton: (Color) -> Unit, + onClickNavigateButton: (Long) -> Unit ) { var isPaletteOpen by remember { mutableStateOf(false) } - var selectedColor by remember {mutableStateOf(Color.Red)} + var selectedColor by remember {mutableStateOf(Color(android.graphics.Color.parseColor(scrapDetailModel?.color)))} Box( modifier = Modifier @@ -110,28 +106,25 @@ private fun InternDialogContent( .padding(horizontal = 11.dp), horizontalAlignment = Alignment.CenterHorizontally ) { - Image( - painter = painterResource( - id = R.drawable.ic_character1 - ), + AsyncImage( + model = ImageRequest.Builder(LocalContext.current) + .data(scrapDetailModel?.companyImage) + .build(), + contentDescription = scrapDetailModel?.title, + contentScale = ContentScale.Fit, modifier = Modifier - .size(80.dp) - .background( - Grey200, - shape = RoundedCornerShape(size = 15.dp) - ) + .width(80.dp) + .aspectRatio(1f) + .clip(RoundedCornerShape(5.dp)) + .background(color = Grey300) .border( width = 1.dp, color = TerningMain, - shape = RoundedCornerShape(size = 15.dp) - ), - contentDescription = null, - contentScale = ContentScale.Fit, - alignment = Alignment.Center + shape = RoundedCornerShape(size = 5.dp) + ) ) - Text( - text = scrapDetailModel.title, + text = scrapDetailModel?.title.orEmpty(), textAlign = TextAlign.Center, style = TerningTheme.typography.title4, color = Grey500, @@ -156,7 +149,7 @@ private fun InternDialogContent( Row( modifier = Modifier .background( - color = if (state.selectedColor != CalRed) CalBlue2 else CalGreen2, + color = selectedColor, shape = RoundedCornerShape(14.dp) ) .noRippleClickable { @@ -214,7 +207,7 @@ private fun InternDialogContent( } } else { Text( - text = scrapDetailModel.dDay, + text = scrapDetailModel?.dDay.orEmpty(), style = TerningTheme.typography.body5, color = TerningMain, modifier = Modifier.padding(bottom = 9.dp) @@ -229,15 +222,16 @@ private fun InternDialogContent( ) { InternInfoRow( title = stringResource(id = com.terning.feature.R.string.intern_info_d_day), - value = scrapDetailModel.title + value = scrapDetailModel?.title.orEmpty() ) InternInfoRow( title = stringResource(id = com.terning.feature.R.string.intern_info_working), - value = scrapDetailModel.workingPeriod + value = scrapDetailModel?.workingPeriod.orEmpty() ) InternInfoRow( title = stringResource(id = com.terning.feature.R.string.intern_info_start_date), - value = "${scrapDetailModel.startYear}년 ${scrapDetailModel.startMonth}월" + value = "${scrapDetailModel?.startYear?:LocalDate.now().year}년 " + + "${scrapDetailModel?.startMonth?:LocalDate.now().monthValue}월" ) } } @@ -254,10 +248,10 @@ private fun InternDialogContent( else R.string.dialog_scrap_move_to_intern, onButtonClick = { if (isPaletteOpen) { - onClickColor(selectedColor) + onClickChangeColorButton(selectedColor) isPaletteOpen = false } else { - onClickNavigate() + onClickNavigateButton(scrapDetailModel?.internshipAnnouncementId?:0) } }, modifier = Modifier.padding(bottom = 8.dp) @@ -273,8 +267,21 @@ fun InternDialogContentPreview() { TerningPointTheme { CalendarDetailDialog( onDismissRequest = {}, - onClickNavigate = {}, - onClickColor = {} + onClickChangeColorButton = {}, + onClickNavigateButton = {}, + scrapDetailModel = CalendarScrapDetailModel( + scrapId = 123, + internshipAnnouncementId = 123, + title = "테스트", + dDay = "asdas", + workingPeriod = "asdas", + startYear = 2023, + startMonth = 1, + isScrapped = true, + color = "0xFF4c3552", + companyImage = "", + deadLine = "sads" + ) ) } } diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDialog.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDialog.kt new file mode 100644 index 000000000..ec902815a --- /dev/null +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDialog.kt @@ -0,0 +1,44 @@ +package com.terning.feature.calendar.calendar.component + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.LocalLifecycleOwner +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.navigation.NavController +import androidx.navigation.compose.rememberNavController +import com.terning.feature.calendar.calendar.CalendarViewModel +import com.terning.feature.intern.navigation.navigateIntern + +@Composable +fun CalendarDialog( + isWeekScreen: Boolean, + navController: NavController = rememberNavController(), + viewModel: CalendarViewModel = hiltViewModel() +) { + val lifecycleOwner = LocalLifecycleOwner.current + val uiState by viewModel.uiState.collectAsStateWithLifecycle(lifecycleOwner) + + if (uiState.isScrapButtonClicked) { + CalendarCancelDialog( + onDismissRequest = { viewModel.updateScrapCancelDialogVisible() }, + onClickScrapCancel = { + viewModel.deleteScrap(isWeekScreen) + } + ) + } + + if (uiState.isInternshipClicked) { + CalendarDetailDialog( + scrapDetailModel = uiState.internshipModel, + onDismissRequest = {viewModel.updateInternDialogVisible(false)}, + onClickChangeColorButton = { newColor -> + viewModel.patchScrap(newColor, isWeekScreen) + }, + onClickNavigateButton = {announcementId -> + viewModel.updateInternDialogVisible(false) + navController.navigateIntern(announcementId = announcementId) + } + ) + } +} \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/calendar/scrap/CalendarListScreen.kt b/feature/src/main/java/com/terning/feature/calendar/scrap/CalendarListScreen.kt index 100446cb5..878c6b3ea 100644 --- a/feature/src/main/java/com/terning/feature/calendar/scrap/CalendarListScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/scrap/CalendarListScreen.kt @@ -22,6 +22,8 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.navigation.NavController +import androidx.navigation.compose.rememberNavController import com.terning.core.designsystem.theme.Back import com.terning.core.designsystem.theme.Grey400 import com.terning.core.designsystem.theme.TerningTheme @@ -34,9 +36,11 @@ import com.terning.feature.calendar.calendar.CalendarUiState import com.terning.feature.calendar.calendar.CalendarViewModel import com.terning.feature.calendar.calendar.component.CalendarDetailDialog import com.terning.feature.calendar.calendar.component.CalendarCancelDialog +import com.terning.feature.calendar.calendar.component.CalendarDialog import com.terning.feature.calendar.calendar.model.CalendarDefaults.flingBehavior import com.terning.feature.calendar.calendar.model.CalendarState.Companion.getDateByPage import com.terning.feature.calendar.scrap.component.CalendarScrapList +import com.terning.feature.intern.navigation.navigateIntern import kotlinx.coroutines.flow.distinctUntilChanged import timber.log.Timber import java.time.LocalDate @@ -45,8 +49,8 @@ import java.time.LocalDate fun CalendarListScreen( pages: Int, listState: LazyListState, - uiState: CalendarUiState, modifier: Modifier = Modifier, + navController: NavController = rememberNavController(), viewModel: CalendarViewModel = hiltViewModel() ) { val lifecycleOwner = LocalLifecycleOwner.current @@ -117,10 +121,9 @@ fun CalendarListScreen( onScrapButtonClicked = { scrapId -> viewModel.updateScrapCancelDialogVisible(scrapId) }, - onInternshipClicked = { internshipAnnouncementId -> - viewModel.updateInternDialogVisible( - internshipAnnouncementId - ) + onInternshipClicked = { scrapDetailModel -> + viewModel.updateInternshipModel(scrapDetailModel) + viewModel.updateInternDialogVisible(true) }, isFromList = true, noScrapScreen = {}) @@ -131,26 +134,12 @@ fun CalendarListScreen( } } } - if (uiState.isScrapButtonClicked) { - CalendarCancelDialog( - onDismissRequest = { viewModel.updateScrapCancelDialogVisible() }, - onClickScrapCancel = { - viewModel.updateScrapCancelDialogVisible() - } - ) - } - if (uiState.isInternshipClicked) { - CalendarDetailDialog( - onDismissRequest = {viewModel.updateInternDialogVisible(null)}, - onClickColor = { newColor -> - Timber.tag("CalendarScreen") - .d(": $newColor") - }, - onClickNavigate = { - viewModel.updateInternDialogVisible(null) - } - ) - } + + CalendarDialog( + isWeekScreen = false, + viewModel = viewModel, + navController = navController + ) } } diff --git a/feature/src/main/java/com/terning/feature/calendar/scrap/component/CalendarScrap.kt b/feature/src/main/java/com/terning/feature/calendar/scrap/component/CalendarScrap.kt index 7a93ba262..8d3e7fa72 100644 --- a/feature/src/main/java/com/terning/feature/calendar/scrap/component/CalendarScrap.kt +++ b/feature/src/main/java/com/terning/feature/calendar/scrap/component/CalendarScrap.kt @@ -26,6 +26,7 @@ fun CalendarScrap( elevation = 1.dp, ) { InternItem( + scrapId = scrap.scrapId, imageUrl = scrap.companyImage.orEmpty(), title = scrap.title, dateDeadline = scrap.dDay, diff --git a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt index aaee1767d..e2bf3d076 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt @@ -1,7 +1,6 @@ package com.terning.feature.calendar.week import androidx.compose.foundation.background -import androidx.compose.foundation.border import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -22,8 +21,9 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.navigation.NavController +import androidx.navigation.compose.rememberNavController import com.terning.core.designsystem.theme.Back -import com.terning.core.designsystem.theme.Grey200 import com.terning.core.designsystem.theme.Grey400 import com.terning.core.designsystem.theme.TerningTheme import com.terning.core.designsystem.theme.White @@ -32,22 +32,21 @@ import com.terning.domain.entity.response.CalendarScrapDetailModel import com.terning.feature.R import com.terning.feature.calendar.calendar.CalendarUiState import com.terning.feature.calendar.calendar.CalendarViewModel -import com.terning.feature.calendar.calendar.component.CalendarDetailDialog -import com.terning.feature.calendar.calendar.component.CalendarCancelDialog +import com.terning.feature.calendar.calendar.component.CalendarDialog import com.terning.feature.calendar.scrap.component.CalendarScrapList -import timber.log.Timber import java.time.LocalDate @Composable fun CalendarWeekScreen( modifier: Modifier = Modifier, - uiState: CalendarUiState, + calendarUiState: CalendarUiState, + navController: NavController = rememberNavController(), viewModel: CalendarViewModel = hiltViewModel() ) { val lifecycleOwner = LocalLifecycleOwner.current val calendarWeekState by viewModel.calendarWeekState.collectAsStateWithLifecycle(lifecycleOwner) - LaunchedEffect(uiState.selectedDate) { + LaunchedEffect(calendarUiState.selectedDate) { viewModel.getScrapWeekList() } @@ -69,7 +68,7 @@ fun CalendarWeekScreen( modifier = Modifier .fillMaxWidth() .background(White), - selectedDate = uiState, + calendarUiState = calendarUiState, onDateSelected = { viewModel.updateSelectedDate(it) } @@ -87,37 +86,23 @@ fun CalendarWeekScreen( val scrapList = (calendarWeekState.loadState as UiState.Success).data CalendarWeekSuccess( scrapList = scrapList, - selectedDate = uiState.selectedDate, + selectedDate = calendarUiState.selectedDate, onScrapButtonClicked = { scrapId -> viewModel.updateScrapCancelDialogVisible(scrapId) }, onInternshipClicked = { scrapDetailModel -> - viewModel.updateInternDialogVisible(scrapDetailModel) + viewModel.updateInternshipModel(scrapDetailModel) + viewModel.updateInternDialogVisible(true) }) } } } - if (uiState.isScrapButtonClicked) { - CalendarCancelDialog( - onDismissRequest = { viewModel.updateScrapCancelDialogVisible() }, - onClickScrapCancel = { - viewModel.updateScrapCancelDialogVisible() - } - ) - } - if (uiState.isInternshipClicked) { - CalendarDetailDialog( - onDismissRequest = {viewModel.updateInternDialogVisible(null)}, - onClickColor = { newColor -> - Timber.tag("CalendarScreen") - .d(": $newColor") - }, - onClickNavigate = { - viewModel.updateInternDialogVisible(null) - } - ) - } + CalendarDialog( + isWeekScreen = true, + viewModel = viewModel, + navController = navController + ) } } diff --git a/feature/src/main/java/com/terning/feature/calendar/week/HorizontalCalendarWeek.kt b/feature/src/main/java/com/terning/feature/calendar/week/HorizontalCalendarWeek.kt index 9b16f9a9d..54c3c084a 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/HorizontalCalendarWeek.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/HorizontalCalendarWeek.kt @@ -20,11 +20,11 @@ import java.time.YearMonth @Composable fun HorizontalCalendarWeek( - selectedDate: CalendarUiState, + calendarUiState: CalendarUiState, modifier: Modifier = Modifier, onDateSelected: (LocalDate) -> Unit = {} ) { - val date = selectedDate.selectedDate + val date = calendarUiState.selectedDate val monthData = MonthData(YearMonth.of(date.year, date.monthValue)) val currentWeek = date.getWeekIndexContainingSelectedDate(monthData.inDays) @@ -46,7 +46,7 @@ fun HorizontalCalendarWeek( items(items = monthData.calendarMonth.weekDays[page]) { day -> CalendarDay( dayData = day, - isSelected = selectedDate.selectedDate == day.date && selectedDate.isWeekEnabled, + isSelected = calendarUiState.selectedDate == day.date && calendarUiState.isWeekEnabled, isToday = day.date.isToday(), onDateSelected = onDateSelected )