From a958047f04eff24dd5d3853b8a982f3173b210e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AA=85=ED=9B=88?= Date: Fri, 29 Nov 2024 23:53:48 +0900 Subject: [PATCH] :memo: :: Temporary Commit --- .../expo/view/ExpoCreateScreen.kt | 49 +++---- .../ExpoTrainingSettingBottomSheet.kt | 124 +++++++++--------- .../expo/viewmodel/ExpoViewModel.kt | 28 +--- 3 files changed, 80 insertions(+), 121 deletions(-) diff --git a/feature/expo/src/main/java/com/school_of_company/expo/view/ExpoCreateScreen.kt b/feature/expo/src/main/java/com/school_of_company/expo/view/ExpoCreateScreen.kt index 959e1ffa..d896bf83 100644 --- a/feature/expo/src/main/java/com/school_of_company/expo/view/ExpoCreateScreen.kt +++ b/feature/expo/src/main/java/com/school_of_company/expo/view/ExpoCreateScreen.kt @@ -91,9 +91,8 @@ internal fun ExpoCreateRoute( val coverImageState by viewModel.cover_image.collectAsStateWithLifecycle() val trainingProgramTextState by viewModel.trainingProgramTextState.collectAsStateWithLifecycle() val standardProgramTextState by viewModel.standardProgramTextState.collectAsStateWithLifecycle() - val startedTextState by viewModel.trainingStartedList.collectAsStateWithLifecycle() - val endedTextState by viewModel.trainingEndedList.collectAsStateWithLifecycle() - val categoryList by viewModel.trainingCategoryList.collectAsStateWithLifecycle() + val startedTextState by viewModel.started.collectAsStateWithLifecycle() + val endedTextState by viewModel.ended.collectAsStateWithLifecycle() var selectedImageUri by remember { mutableStateOf(null) } @@ -119,10 +118,6 @@ internal fun ExpoCreateRoute( } } - LaunchedEffect(Unit) { - viewModel.addTrainingProgram() - } - LaunchedEffect(imageUpLoadUiState) { when (imageUpLoadUiState) { is ImageUpLoadUiState.Loading -> Unit @@ -155,12 +150,12 @@ internal fun ExpoCreateRoute( is RegisterExpoInformationUiState.Success -> { viewModel.registerTrainingProgramList( expoId = (registerExpoInformationUiState as RegisterExpoInformationUiState.Success).data.expoId, - body = viewModel.trainingProgramTextState.value.mapIndexed { index, title -> + body = viewModel.trainingProgramTextState.value.map { title -> TrainingDtoModel( title = title, - startedAt = startedTextState[index], - endedAt = endedTextState[index], - category = categoryList[index].toString() + startedAt = viewModel.started.value, + endedAt = viewModel.ended.value, + category = viewModel.categoryState.value.toString() ) } ) @@ -218,15 +213,9 @@ internal fun ExpoCreateRoute( onRemoveStandardProgram = viewModel::removeStandardProgramText, startedTextState = startedTextState, endedTextState = endedTextState, - onStartedChange = { index, value -> - viewModel.updateTrainingStarted(index, value) - }, - onEndedChange = { index, value -> - viewModel.updateTrainingEnded(index, value) - }, - onTrainingCategoryChange = { index, value -> - viewModel.updateTrainingCategory(index, value) - } + onStartedChange = viewModel::onStartedChange, + onEndedChange = viewModel::onEndedChange, + onTrainingCategoryChange = viewModel::updateCategory ) } @@ -258,11 +247,11 @@ internal fun ExpoCreateScreen( onStandardProgramChange: (Int, String) -> Unit, onAddStandardProgram: () -> Unit, onRemoveStandardProgram: (Int) -> Unit, - startedTextState: List, - endedTextState: List, - onStartedChange: (Int, String) -> Unit, - onEndedChange: (Int, String) -> Unit, - onTrainingCategoryChange: (Int, TrainingCategory) -> Unit + startedTextState: String, + endedTextState: String, + onStartedChange: (String) -> Unit, + onEndedChange: (String) -> Unit, + onTrainingCategoryChange: (TrainingCategory) -> Unit ) { val (openTrainingSettingBottomSheet, isOpenTrainingSettingBottomSheet) = rememberSaveable { mutableStateOf(false) } @@ -580,10 +569,10 @@ private fun ExpoCreateScreenPreview() { onStandardProgramChange = { _, _ -> }, onAddStandardProgram = {}, onRemoveStandardProgram = {}, - startedTextState = listOf(), - endedTextState = listOf(), - onStartedChange = {_, _ ->}, - onEndedChange = {_, _ ->}, - onTrainingCategoryChange = {_, _ ->} + startedTextState = "", + endedTextState = "", + onStartedChange = {}, + onEndedChange = {}, + onTrainingCategoryChange = {} ) } \ No newline at end of file diff --git a/feature/expo/src/main/java/com/school_of_company/expo/view/component/ExpoTrainingSettingBottomSheet.kt b/feature/expo/src/main/java/com/school_of_company/expo/view/component/ExpoTrainingSettingBottomSheet.kt index 5b2ea4dd..81546235 100644 --- a/feature/expo/src/main/java/com/school_of_company/expo/view/component/ExpoTrainingSettingBottomSheet.kt +++ b/feature/expo/src/main/java/com/school_of_company/expo/view/component/ExpoTrainingSettingBottomSheet.kt @@ -52,13 +52,13 @@ import com.school_of_company.expo.enum.TrainingCategory fun ExpoTrainingSettingBottomSheet( modifier: Modifier = Modifier, onCancelClick: () -> Unit, - startedTextState: List, - endedTextState: List, - onStartedTextChange: (Int, String) -> Unit, - onEndedTextChange: (Int, String) -> Unit, + startedTextState: String, + endedTextState: String, + onStartedTextChange: (String) -> Unit, + onEndedTextChange: (String) -> Unit, onButtonClick: () -> Unit, categoryState: TrainingCategory = TrainingCategory.CHOICE, - onCategoryChange: (Int, TrainingCategory) -> Unit, + onCategoryChange: (TrainingCategory) -> Unit, focusManager: FocusManager = LocalFocusManager.current ) { val sheetState = rememberModalBottomSheetState() @@ -113,60 +113,56 @@ fun ExpoTrainingSettingBottomSheet( ) } - startedTextState.forEachIndexed { index, startedTextState -> - Row(verticalAlignment = Alignment.CenterVertically) { - Column( - verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.Top), - modifier = Modifier.weight(1f) - ) { - ExpoNoneLineTextField( - textState = startedTextState, - placeHolder = { - Text( - text = "yyyy-MM-dd HH:mm", - style = typography.titleBold2, - color = colors.gray300, - maxLines = 1 - ) - }, - onTextChange = { newText -> - onStartedTextChange(index, newText) - } - ) - - ExpoNoneLineTextField( - textState = endedTextState[index], - placeHolder = { - Text( - text = "yyyy-MM-dd HH:mm", - style = typography.titleBold2, - color = colors.gray300, - maxLines = 1 - ) - }, - onTextChange = { newText -> - onEndedTextChange(index, newText) - } - ) - } - - Row( - horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start), - verticalAlignment = Alignment.CenterVertically - ) { - Text( - text = "필수", - style = typography.bodyRegular2, - color = colors.gray500 - ) - - CustomCheckBox( - categoryState = categoryState, - onCategoryChange = { newCategory -> - onCategoryChange(index, newCategory) - } - ) - } + Row(verticalAlignment = Alignment.CenterVertically) { + Column( + verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.Top), + modifier = Modifier.weight(1f) + ) { + ExpoNoneLineTextField( + textState = startedTextState, + placeHolder = { + Text( + text = "yyyy-MM-dd HH:mm", + style = typography.titleBold2, + color = colors.gray300, + maxLines = 1 + ) + }, + onTextChange = { newText -> + onStartedTextChange(newText) + } + ) + + ExpoNoneLineTextField( + textState = endedTextState, + placeHolder = { + Text( + text = "yyyy-MM-dd HH:mm", + style = typography.titleBold2, + color = colors.gray300, + maxLines = 1 + ) + }, + onTextChange = { newText -> + onEndedTextChange(newText) + } + ) + } + + Row( + horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start), + verticalAlignment = Alignment.CenterVertically + ) { + Text( + text = "필수", + style = typography.bodyRegular2, + color = colors.gray500 + ) + + CustomCheckBox( + categoryState = categoryState, + onCategoryChange = onCategoryChange + ) } } @@ -232,13 +228,13 @@ fun CustomCheckBox( private fun ExpoTrainingSettingBottomSheetPreview() { ExpoTrainingSettingBottomSheet( onCancelClick = {}, - startedTextState = listOf(), - endedTextState = listOf(), - onStartedTextChange = {_, _ ->}, - onEndedTextChange = {_, _ ->}, + startedTextState = "", + endedTextState = "", + onStartedTextChange = {}, + onEndedTextChange = {}, onButtonClick = {}, categoryState = TrainingCategory.ESSENTIAL, - onCategoryChange = {_, _ ->} + onCategoryChange = {} ) } diff --git a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt index 20ea29c9..daa69833 100644 --- a/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt +++ b/feature/expo/src/main/java/com/school_of_company/expo/viewmodel/ExpoViewModel.kt @@ -75,6 +75,7 @@ class ExpoViewModel @Inject constructor( private val _categoryState = MutableStateFlow(TrainingCategory.CHOICE) val categoryState = _categoryState.asStateFlow() + private val _getExpoInformationUiState = MutableStateFlow(GetExpoInformationUiState.Loading) internal val getExpoInformationUiState = _getExpoInformationUiState.asStateFlow() @@ -120,33 +121,6 @@ class ExpoViewModel @Inject constructor( internal var ended = savedStateHandle.getStateFlow(key = ENDED, initialValue = "") - private val _trainingStartedList = MutableStateFlow>(emptyList()) - val trainingStartedList: StateFlow> = _trainingStartedList - - private val _trainingEndedList = MutableStateFlow>(emptyList()) - val trainingEndedList: StateFlow> = _trainingEndedList - - private val _trainingCategoryList = MutableStateFlow>(emptyList()) - val trainingCategoryList: StateFlow> = _trainingCategoryList - - fun updateTrainingStarted(index: Int, value: String) { - _trainingStartedList.value = _trainingStartedList.value.toMutableList().apply { this[index] = value } - } - - fun updateTrainingEnded(index: Int, value: String) { - _trainingEndedList.value = _trainingEndedList.value.toMutableList().apply { this[index] = value } - } - - fun updateTrainingCategory(index: Int, value: TrainingCategory) { - _trainingCategoryList.value = _trainingCategoryList.value.toMutableList().apply { this[index] = value } - } - - fun addTrainingProgram() { - _trainingStartedList.value += "" - _trainingEndedList.value += "" - _trainingCategoryList.value += TrainingCategory.CHOICE - } - internal fun getExpoInformation(expoId: String) = viewModelScope.launch { getExpoInformationUseCase(expoId = expoId) .asResult()