Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
Expand All @@ -44,6 +45,7 @@ import com.mifos.core.designsystem.theme.MifosTypography
import com.mifos.core.ui.components.MifosAlertDialog
import com.mifos.core.ui.components.MifosErrorComponent
import com.mifos.core.ui.util.EventsEffect
import kotlinx.coroutines.delay
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel

Expand Down Expand Up @@ -112,7 +114,12 @@ fun AddEditNoteScreenDialog(
)
}

AddEditNoteState.DialogState.Success -> {
onAction(AddEditNoteAction.NavigateBackWithUpdateList)
Comment thread
Arinyadav1 marked this conversation as resolved.
Outdated
}

null -> Unit

}
}

Expand All @@ -131,10 +138,14 @@ internal fun AddEditNoteScreenScaffold(
.fillMaxSize()
.padding(paddingValues),
) {
AddEditNote(
state = state,
onAction = onAction,
)

if(state.dialogState !is AddEditNoteState.DialogState.Loading){
AddEditNote(
state = state,
onAction = onAction,
)
}

}
}
}
Expand Down Expand Up @@ -221,9 +232,6 @@ private fun AddEditNote(
} else {
onAction(AddEditNoteAction.AddNote(state.textFieldNotesPayload))
}
if (state.isError) {
onAction(AddEditNoteAction.NavigateBack)
}
},
colors = ButtonDefaults.outlinedButtonColors(
contentColor = MaterialTheme.colorScheme.onPrimary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,20 @@ class AddEditNoteViewModel(
mutableStateFlow.update {
it.copy(
dialogState = AddEditNoteState.DialogState.Error(Res.string.feature_note_Unexpected_error),
isError = false,
)
}
}

DataState.Loading -> {
// no need to show loading for this
mutableStateFlow.update {
it.copy(dialogState = AddEditNoteState.DialogState.Loading)
}
}

is DataState.Success -> {
mutableStateFlow.update {
it.copy(
isError = true,
dialogState = null,
dialogState = AddEditNoteState.DialogState.Success,
successMessage = Res.string.feature_note_add_success,
notesPayloadInitialData = state.textFieldNotesPayload.note,
)
Expand All @@ -159,18 +159,18 @@ class AddEditNoteViewModel(
mutableStateFlow.update {
it.copy(
dialogState = AddEditNoteState.DialogState.Error(Res.string.feature_note_Unexpected_error),
isError = false,
)
}
}
DataState.Loading -> {
// no need to show loading for this
mutableStateFlow.update {
it.copy(dialogState = AddEditNoteState.DialogState.Loading)
}
}
is DataState.Success -> {
mutableStateFlow.update {
it.copy(
isError = true,
dialogState = null,
dialogState = AddEditNoteState.DialogState.Success,
successMessage = Res.string.feature_note_edit_success,
notesPayloadInitialData = state.textFieldNotesPayload.note,
)
Expand All @@ -185,6 +185,10 @@ class AddEditNoteViewModel(
override fun handleAction(action: AddEditNoteAction) {
when (action) {
AddEditNoteAction.NavigateBack -> {
sendEvent(AddEditNoteEvent.NavigateBack)
}

AddEditNoteAction.NavigateBackWithUpdateList -> {
sendEvent(AddEditNoteEvent.NavigateBackWithUpdateList)
}

Expand Down Expand Up @@ -242,6 +246,8 @@ class AddEditNoteViewModel(
sendEvent(AddEditNoteEvent.NavigateBack)
}
}


}
}
}
Expand All @@ -257,14 +263,14 @@ data class AddEditNoteState(
val textFieldNotesPayload: NotesPayload = NotesPayload(null),
val notesPayloadInitialData: String? = null,
val showDialog: Boolean = false,
val isError: Boolean = true,
val dialogState: DialogState? = null,
val networkConnection: Boolean = false,
) {
sealed interface DialogState {
data class Error(val message: StringResource) : DialogState
data object Loading : DialogState
data object MisTouchBack : DialogState
data object Success : DialogState
}
}

Expand All @@ -275,6 +281,7 @@ sealed interface AddEditNoteEvent {

sealed interface AddEditNoteAction {
data object NavigateBack : AddEditNoteAction
data object NavigateBackWithUpdateList : AddEditNoteAction
data object OnRetry : AddEditNoteAction
data class AddNote(val notesPayload: NotesPayload) : AddEditNoteAction
data class EditNote(val notesPayload: NotesPayload) : AddEditNoteAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,25 @@ internal fun NoteScreenScaffold(
EventsEffect(viewModel.eventFlow) { event ->
when (event) {
NoteEvent.NavigateBack -> onNavigateBack()
NoteEvent.NavigateAddNote -> onNavigateAddEditNote(state.resourceId, state.resourceType, null)
NoteEvent.NavigateEditNote -> onNavigateAddEditNote(state.resourceId, state.resourceType, state.expandedNoteId)
NoteEvent.NavigateAddNote -> onNavigateAddEditNote(
state.resourceId,
state.resourceType,
null,
)

NoteEvent.NavigateEditNote -> onNavigateAddEditNote(
state.resourceId,
state.resourceType,
state.expandedNoteId,
)
}
}

if (!state.isError && state.notes.isNotEmpty()) {
NoteScreenScaffold(
state = state,
onAction = remember(viewModel) { { viewModel.trySendAction(it) } },
)
}

NoteScreenScaffold(
state = state,
onAction = remember(viewModel) { { viewModel.trySendAction(it) } },
)

NoteScreenDialog(
state = state,
Expand Down Expand Up @@ -152,10 +160,12 @@ internal fun NoteScreenScaffold(
isRefreshing = state.isRefreshing,
onRefresh = { onAction(NoteAction.OnRefresh) },
) {
NoteContent(
state = state,
onAction = onAction,
)
if (state.dialogState != NoteState.DialogState.Loading && !state.isError) {
NoteContent(
state = state,
onAction = onAction,
)
}
Comment thread
Arinyadav1 marked this conversation as resolved.
Outdated
Comment thread
Arinyadav1 marked this conversation as resolved.
Outdated
}
}
}
Expand Down Expand Up @@ -271,7 +281,9 @@ private fun NoteItem(
width = 1.dp,
color = MaterialTheme.colorScheme.secondaryContainer,
shape = shape,
),
).clickable {
id?.let { onAction(NoteAction.OnToggleExpanded(id)) }
},
shape = shape,
elevation = DesignToken.spacing.none,
) {
Expand All @@ -292,9 +304,7 @@ private fun NoteItem(
Icon(
imageVector = MifosIcons.MoreHoriz,
contentDescription = null,
modifier = Modifier.clickable {
id?.let { onAction(NoteAction.OnToggleExpanded(id)) }
}.size(DesignToken.sizes.iconAverage),
modifier = Modifier.size(DesignToken.sizes.iconAverage),
)
}

Expand Down Expand Up @@ -368,9 +378,10 @@ private fun ContextualActions(
verticalArrangement = Arrangement.spacedBy(DesignToken.spacing.medium),
) {
Row(
modifier = Modifier.clickable {
onAction(NoteAction.OnClickEditScreen)
},
modifier = Modifier.fillMaxWidth()
.clickable {
onAction(NoteAction.OnClickEditScreen)
},
horizontalArrangement = Arrangement.spacedBy(
DesignToken.spacing.medium,
),
Expand All @@ -389,9 +400,10 @@ private fun ContextualActions(
}

Row(
modifier = Modifier.clickable {
onAction(NoteAction.ShowDialog)
},
modifier = Modifier.fillMaxWidth()
.clickable {
onAction(NoteAction.ShowDialog)
},
horizontalArrangement = Arrangement.spacedBy(
DesignToken.spacing.medium,
),
Expand Down
Loading