fixed redir
This commit is contained in:
parent
2bb80953c8
commit
8262569134
@ -121,7 +121,7 @@ fun AddCategory(
|
||||
modifier = Modifier,
|
||||
"Add Category",
|
||||
onClick = {
|
||||
if (name.isNotBlank()) {
|
||||
if (name.isNotBlank() && selectedIconIndex != -1) {
|
||||
val newCategory = CategoryEntity(
|
||||
_id = 0,
|
||||
categoryName = name,
|
||||
|
@ -19,6 +19,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -45,8 +46,8 @@ fun EditCategory(
|
||||
) {
|
||||
val category = editCategoryViewModel.categoryUi.category
|
||||
var showError by remember { mutableStateOf(editCategoryViewModel.deletePossible) }
|
||||
var redirect by remember { mutableStateOf(editCategoryViewModel.redirect) }
|
||||
var deleteStarted by remember { mutableStateOf(false) }
|
||||
val redirect by editCategoryViewModel.redirect.collectAsState()
|
||||
var deleteStarted by remember { mutableStateOf(editCategoryViewModel.deleteStarted) }
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
var selectedIconIndex by remember { mutableIntStateOf(category.icon) }
|
||||
|
||||
@ -58,8 +59,11 @@ fun EditCategory(
|
||||
if (deleteStarted) {
|
||||
editCategoryViewModel.findEntryByCategoryId()
|
||||
showError = editCategoryViewModel.deletePossible
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(redirect) {
|
||||
Log.w("lolo", "EditCategory: "+ redirect.toString(), )
|
||||
if (redirect) {
|
||||
onButtonClick()
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import androidx.lifecycle.viewModelScope
|
||||
import at.xaxa.ledger.data.EntryRepository
|
||||
import at.xaxa.ledger.data.db.Category.CategoryEntity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@ -23,7 +25,10 @@ class EditCategoryViewModel(private val savedStateHandle: SavedStateHandle, priv
|
||||
var categoryUi by mutableStateOf(CategoryUIState())
|
||||
private set
|
||||
var deletePossible by mutableStateOf(false)
|
||||
var redirect by mutableStateOf(false)
|
||||
var deleteStarted by mutableStateOf(false)
|
||||
|
||||
private var _redirect = MutableStateFlow(false)
|
||||
val redirect: StateFlow<Boolean> get() = _redirect
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
@ -32,7 +37,7 @@ class EditCategoryViewModel(private val savedStateHandle: SavedStateHandle, priv
|
||||
}
|
||||
categoryUi = CategoryUIState(category)
|
||||
|
||||
redirect = false;
|
||||
_redirect.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +45,7 @@ class EditCategoryViewModel(private val savedStateHandle: SavedStateHandle, priv
|
||||
categoryUi = categoryUi.copy(category = category)
|
||||
}
|
||||
|
||||
fun deleteCategory() {
|
||||
fun deleteCategory(){
|
||||
viewModelScope.launch {
|
||||
entryRepository.deleteCategory(categoryUi.category)
|
||||
}
|
||||
@ -61,10 +66,10 @@ class EditCategoryViewModel(private val savedStateHandle: SavedStateHandle, priv
|
||||
if(fetchedEntries>0){
|
||||
deletePossible = true
|
||||
}else{
|
||||
Log.w("lolo", "findEntryByCategoryId: "+fetchedEntries, )
|
||||
deleteCategory()
|
||||
redirect= true;
|
||||
_redirect.value= true;
|
||||
}
|
||||
}
|
||||
//print("ASASDADS$categoryId")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user