Skip to content

Commit

Permalink
Fixing notes persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
leandroBorgesFerreira committed Jul 4, 2023
1 parent 0bf3a36 commit cfed95c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ class NoteDetailsViewModel(
fun saveNote() {
viewModelScope.launch {
val stories = story.value.stories
val document = _documentState.value ?: return@launch
val document = _documentState.value ?: throw IllegalStateException(
"Trying to save a null document, did you forget to create a note?"
)

if (stories.noContent()) {
documentRepository.deleteDocument(document)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ class StoryTellerManager(
}

private fun cancelSelection() {
Log.d("Manager", "Cancelling selection")
_positionsOnEdit.value = emptySet()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fun <T> Iterable<T>.associateWithPosition(): Map<Int, T> {
}

fun Map<Int, StoryStep>.noContent(): Boolean =
this.values.any { storyStep ->
this.values.all { storyStep ->
storyStep.run {
url.isNullOrBlank() &&
path.isNullOrBlank() &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.leandroborgesferreira.storyteller.utils.extensions

import androidx.compose.runtime.toMutableStateMap
import com.github.leandroborgesferreira.storyteller.model.story.StoryStep
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertTrue
import org.junit.Test

Expand All @@ -16,4 +18,17 @@ class StoryExtensionsKtTest {

assertTrue(storyStepMap.noContent())
}

@Test
fun `it should be able to recognize a not empty document`() {
val storyStepMap = buildList {
repeat(5) { index ->
add(index to StoryStep(type = "message"))
}
}.toMutableStateMap()

storyStepMap[5] = StoryStep(type = "message", text = "some text")

assertFalse(storyStepMap.noContent())
}
}

0 comments on commit cfed95c

Please sign in to comment.