Skip to content

Commit

Permalink
Fix Loading showing even when it's not loading, add ShowSuccess to En…
Browse files Browse the repository at this point in the history
…tryViewModels create edit and delete
  • Loading branch information
PasclDev committed Jun 24, 2022
1 parent 3daae54 commit aa9ba12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,30 @@ class EntryViewModel(
private fun create(entry: Entry.In) = scope.launch {
entryUseCases.createNewEntryUseCase(entry).collect {
it.handleDataResponse<Entry>(
routerFlow = routerFlow, onSuccess = { routerFlow.navigateTo(Screen.Dashboard) })
routerFlow = routerFlow, onSuccess = {
routerFlow.navigateTo(Screen.Dashboard)
eventFlow.emit(UiEvent.ShowSuccess("Entry successfully created"))
})
}
}

private fun update(entry: Entry.Patch, id: Int) = scope.launch {
entryUseCases.changeEntryByIdUseCase(entry, id).collect {
it.handleDataResponse<Entry>(
routerFlow = routerFlow, onSuccess = { routerFlow.navigateTo(Screen.Dashboard) })
routerFlow = routerFlow, onSuccess = {
routerFlow.navigateTo(Screen.Dashboard)
eventFlow.emit(UiEvent.ShowSuccess("Entry successfully updated"))
})
}
}

private fun delete(id: Int) = scope.launch {
entryUseCases.deleteEntryByIdUseCase(id).collect {
it.handleDataResponse<Entry>(
routerFlow = routerFlow, onSuccess = { routerFlow.navigateTo(Screen.Dashboard) })
routerFlow = routerFlow, onSuccess = {
routerFlow.navigateTo(Screen.Dashboard)
eventFlow.emit(UiEvent.ShowSuccess("Entry successfully deleted"))
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion budget-binder-multiplatform-app/src/jsMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ val di = kodein(ktorEngine = Js.create())
@Composable
fun App() = withDI(di) {
val uiEventFlow: UiEventSharedFlow by di.instance()
val loadingState = remember { mutableStateOf(false) }
val loadingState = remember { mutableStateOf(true) }
val snackBarText = remember { mutableStateOf("") }
val snackBarHidden = remember { mutableStateOf(true) }
LaunchedEffect(key1 = true) {
Expand Down

0 comments on commit aa9ba12

Please sign in to comment.