edit category list is updating but not display the right val on load
This commit is contained in:
parent
7ec6dc64ae
commit
ac7e35d54f
@ -8,7 +8,7 @@ import at.xaxa.ledger.LedgerApplication
|
||||
import at.xaxa.ledger.ui.entry.add.AddViewModel
|
||||
import at.xaxa.ledger.ui.category.CategoryViewModel
|
||||
import at.xaxa.ledger.ui.category.edit.EditCategoryViewModel
|
||||
import at.xaxa.ledger.ui.edit.EditViewModel
|
||||
import at.xaxa.ledger.ui.entry.edit.EditViewModel
|
||||
import at.xaxa.ledger.ui.home.HomeViewModel
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
@ -33,7 +34,6 @@ import at.xaxa.ledger.ui.DatePickerDocked
|
||||
import at.xaxa.ledger.ui.category.CategoryViewModel
|
||||
import at.xaxa.ledger.ui.category.iconNames
|
||||
import at.xaxa.ledger.ui.category.icons
|
||||
import at.xaxa.ledger.ui.edit.EditViewModel
|
||||
|
||||
|
||||
|
||||
@ -47,13 +47,7 @@ fun EditCategory(
|
||||
|
||||
var expanded by remember { mutableStateOf(false) } // Controls dropdown visibility
|
||||
val category = editCategoryViewModel.categoryUi.category
|
||||
var selectedIconIndex = category.icon // Store index of selected icon
|
||||
|
||||
Log.d(
|
||||
"kkjkjkjkj",
|
||||
category.categoryName)
|
||||
|
||||
|
||||
var selectedIconIndex by remember { mutableIntStateOf(category.icon) } // Store index of selected icon
|
||||
/*
|
||||
val categories by categoryViewModel.categoryUiState.categories.collectAsState(initial = emptyList())
|
||||
val category = categoryViewModel.categoryUi.category
|
||||
@ -106,8 +100,7 @@ fun EditCategory(
|
||||
onClick = {
|
||||
selectedIconIndex = index // Update selected index
|
||||
|
||||
category.copy(_id = index)
|
||||
editCategoryViewModel.updateCategory(category)
|
||||
editCategoryViewModel.updateCategory(category.copy(icon = index))
|
||||
expanded = false
|
||||
},
|
||||
leadingIcon = {
|
||||
@ -130,6 +123,7 @@ fun EditCategory(
|
||||
modifier = Modifier,
|
||||
"Edit Category",
|
||||
onClick = {
|
||||
|
||||
editCategoryViewModel.saveCategory()
|
||||
onButtonClick()
|
||||
}
|
||||
|
@ -44,11 +44,13 @@ class EditCategoryViewModel(private val savedStateHandle: SavedStateHandle,
|
||||
fun updateCategory(category: CategoryEntity) {
|
||||
categoryUi = categoryUi.copy(category = category)
|
||||
}
|
||||
|
||||
fun onDeleteEntry(category: CategoryEntity) {
|
||||
viewModelScope.launch {
|
||||
entryRepository.deleteCategory(category)
|
||||
}
|
||||
}
|
||||
|
||||
fun saveCategory() {
|
||||
viewModelScope.launch {
|
||||
entryRepository.updateCategory(categoryUi.category)
|
||||
|
Loading…
Reference in New Issue
Block a user