Skip to content

Commit

Permalink
Merge pull request #1994 from sanao1006/feature/#1992/Avoid_note_with…
Browse files Browse the repository at this point in the history
…_blank_annotations_in_CW

feat: CWで注釈を空欄のままノートできないようにする

ありがとうございました🙇
  • Loading branch information
pantasystem authored Nov 30, 2023
2 parents 65977c9 + 4acbf29 commit be98175
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ data class NoteEditorUiState(
val totalFilesCount: Int
get() = this.files.size

fun checkValidate(textMaxLength: Int = 3000, maxFileCount: Int = 4): Boolean {
fun checkValidate(textMaxLength: Int = 3000, maxFileCount: Int = 4, isCwAllowBlank: Boolean = true): Boolean {
if (this.files.size > maxFileCount) {
return false
}

if (!isCwAllowBlank && formState.hasCw && formState.cw.isNullOrEmpty()) {
return false
}

if ((this.formState.text?.codePointCount(0, this.formState.text.length)
?: 0) > textMaxLength
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ class NoteEditorViewModel @Inject constructor(
logger.error("observe meta error", it)
}.stateIn(viewModelScope + Dispatchers.IO, started = SharingStarted.Lazily, initialValue = 1500)

val isPostAvailable = uiState.map {
it.checkValidate(textMaxLength = maxTextLength.value, maxFileCount = maxFileCount.value)
val isPostAvailable = combine(instanceInfoType, uiState) { instanceInfo, uiState ->
val isCwAllowBlank = instanceInfo?.isCwAllowBlank ?: true
uiState.checkValidate(textMaxLength = maxTextLength.value, maxFileCount = maxFileCount.value, isCwAllowBlank = isCwAllowBlank)
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5_000),
Expand Down

0 comments on commit be98175

Please sign in to comment.