Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fun WriteDiaryTextField(
if (it.length <= maxLength) {
onTextChange(it)
val textWithoutSpaces = it.replace("\\s".toRegex(), "")
isTextValid = textWithoutSpaces.matches(Regex("^[a-zA-Z가-힣0-9ㄱ-ㅎㅏ-ㅣ가-힣]{2,50}$"))
isTextValid = textWithoutSpaces.matches(Regex("^[a-zA-Z가-힣0-9ㄱ-ㅎㅏ-ㅣ가-힣]{2,$maxLength}$"))
isTextTooLong = false
} else {
isTextTooLong = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fun WriteDiaryRoute(
val entryToDelete by viewModel::entryToDelete
val showDialog by viewModel::showDialog
val showExitDialog by viewModel::showExitDialog
val diaryMaxLength by viewModel.diaryMaxLength.collectAsState()

LaunchedEffectWhenStarted {
viewModel.fetchDraftDiary(year, month, date)
Expand Down Expand Up @@ -113,6 +114,7 @@ fun WriteDiaryRoute(
showFailureDialog = showFailureDialog,
failureMessage = failureMessage,
showExitDialog = showExitDialog,
diaryMaxLength = diaryMaxLength,
onClickBack = {
AmplitudeUtils.trackEvent(AmplitudeConstraints.WRITING_DIARY_BACK)
if (!viewModel.hasChangedFromInitial()) {
Expand Down Expand Up @@ -183,6 +185,7 @@ fun WriteDiaryScreen(
showEmptyFieldsMessage: Boolean,
showDeleteBottomSheet: Boolean,
showDialog: Boolean,
diaryMaxLength: Int,
onClickBack: () -> Unit,
onClickAdd: () -> Unit,
onClickRemove: (Int) -> Unit,
Expand Down Expand Up @@ -265,7 +268,7 @@ fun WriteDiaryScreen(
onTextChange = { newText -> onTextChange(index, newText) },
onRemove = { onClickRemove(index) },
isRemovable = entries.size > 1,
maxLength = 50,
maxLength = diaryMaxLength,
showWarning = showWarnings[index],
)
}
Expand Down Expand Up @@ -390,6 +393,7 @@ private fun WriteDiaryScreenPreview() {
showEmptyFieldsMessage = false,
showDeleteBottomSheet = false,
showDialog = false,
diaryMaxLength = 100,
onClickBack = {},
onClickAdd = {},
onClickRemove = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.sopt.clody.domain.repository.DiaryRepository
import com.sopt.clody.domain.repository.DraftRepository
import com.sopt.clody.domain.usecase.FetchDraftDiaryUseCase
import com.sopt.clody.domain.usecase.SaveDraftDiaryUseCase
import com.sopt.clody.presentation.utils.language.LanguageProvider
import com.sopt.clody.presentation.utils.network.ErrorMessages
import com.sopt.clody.presentation.utils.network.ErrorMessages.FAILURE_NETWORK_MESSAGE
import com.sopt.clody.presentation.utils.network.ErrorMessages.FAILURE_TEMPORARY_MESSAGE
Expand All @@ -30,6 +31,7 @@ class WriteDiaryViewModel @Inject constructor(
private val saveDraftDiaryUseCase: SaveDraftDiaryUseCase,
private val networkUtil: NetworkUtil,
private val draftRepository: DraftRepository,
private val languageProvider: LanguageProvider,
) : ViewModel() {

private val _writeDiaryState = MutableStateFlow<WriteDiaryState>(WriteDiaryState.Idle)
Expand Down Expand Up @@ -67,6 +69,9 @@ class WriteDiaryViewModel @Inject constructor(

private var initialEntries: List<String> = emptyList()

private val _diaryMaxLength = MutableStateFlow(languageProvider.getDiaryMaxLength())
val diaryMaxLength: StateFlow<Int> = _diaryMaxLength

fun writeDiary(year: Int, month: Int, day: Int, contents: List<String>) {
viewModelScope.launch {
if (!networkUtil.isNetworkAvailable()) {
Expand Down Expand Up @@ -154,7 +159,7 @@ class WriteDiaryViewModel @Inject constructor(

private fun isValidEntry(text: String): Boolean {
val textWithoutSpaces = text.replace("\\s".toRegex(), "")
return textWithoutSpaces.matches(Regex(ENTRY_REGEX))
return textWithoutSpaces.matches(Regex("^[a-zA-Z가-힣0-9ㄱ-ㅎㅏ-ㅣ가-힣\\W]{2,${_diaryMaxLength.value}$"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P5
어라 이 친구 object에서 뺀 이유가 있을까여?

Copy link
Copy Markdown
Contributor Author

@SYAAINN SYAAINN Jul 16, 2025

Choose a reason for hiding this comment

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

object에 들어가있어서 _diaryMaxLength.value 부분을 정규식에 집어넣지를 못해서 빼게 됐습니다!
일기 작성 최대 글자수 변경하는 작업하느냐고 뷰모델부터 Screen들을 대충 쭉 봤는데 정규식이 여기도 있고 스크린에도 있고 한 상태라 한번 뒤엎는 작업이 필요하지 않을까.. 싶습니다.

}

private fun checkLimitMessage() {
Expand Down Expand Up @@ -250,6 +255,5 @@ class WriteDiaryViewModel @Inject constructor(

companion object {
const val MAX_ENTRIES = 5
const val ENTRY_REGEX = "^[a-zA-Z가-힣0-9ㄱ-ㅎㅏ-ㅣ가-힣\\W]{2,50}$"
}
}