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.entry.add.AddViewModel
|
||||||
import at.xaxa.ledger.ui.category.CategoryViewModel
|
import at.xaxa.ledger.ui.category.CategoryViewModel
|
||||||
import at.xaxa.ledger.ui.category.edit.EditCategoryViewModel
|
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
|
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.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
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.CategoryViewModel
|
||||||
import at.xaxa.ledger.ui.category.iconNames
|
import at.xaxa.ledger.ui.category.iconNames
|
||||||
import at.xaxa.ledger.ui.category.icons
|
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
|
var expanded by remember { mutableStateOf(false) } // Controls dropdown visibility
|
||||||
val category = editCategoryViewModel.categoryUi.category
|
val category = editCategoryViewModel.categoryUi.category
|
||||||
var selectedIconIndex = category.icon // Store index of selected icon
|
var selectedIconIndex by remember { mutableIntStateOf(category.icon) } // Store index of selected icon
|
||||||
|
|
||||||
Log.d(
|
|
||||||
"kkjkjkjkj",
|
|
||||||
category.categoryName)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
val categories by categoryViewModel.categoryUiState.categories.collectAsState(initial = emptyList())
|
val categories by categoryViewModel.categoryUiState.categories.collectAsState(initial = emptyList())
|
||||||
val category = categoryViewModel.categoryUi.category
|
val category = categoryViewModel.categoryUi.category
|
||||||
@ -106,8 +100,7 @@ fun EditCategory(
|
|||||||
onClick = {
|
onClick = {
|
||||||
selectedIconIndex = index // Update selected index
|
selectedIconIndex = index // Update selected index
|
||||||
|
|
||||||
category.copy(_id = index)
|
editCategoryViewModel.updateCategory(category.copy(icon = index))
|
||||||
editCategoryViewModel.updateCategory(category)
|
|
||||||
expanded = false
|
expanded = false
|
||||||
},
|
},
|
||||||
leadingIcon = {
|
leadingIcon = {
|
||||||
@ -130,6 +123,7 @@ fun EditCategory(
|
|||||||
modifier = Modifier,
|
modifier = Modifier,
|
||||||
"Edit Category",
|
"Edit Category",
|
||||||
onClick = {
|
onClick = {
|
||||||
|
|
||||||
editCategoryViewModel.saveCategory()
|
editCategoryViewModel.saveCategory()
|
||||||
onButtonClick()
|
onButtonClick()
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,13 @@ class EditCategoryViewModel(private val savedStateHandle: SavedStateHandle,
|
|||||||
fun updateCategory(category: CategoryEntity) {
|
fun updateCategory(category: CategoryEntity) {
|
||||||
categoryUi = categoryUi.copy(category = category)
|
categoryUi = categoryUi.copy(category = category)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDeleteEntry(category: CategoryEntity) {
|
fun onDeleteEntry(category: CategoryEntity) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
entryRepository.deleteCategory(category)
|
entryRepository.deleteCategory(category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveCategory() {
|
fun saveCategory() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
entryRepository.updateCategory(categoryUi.category)
|
entryRepository.updateCategory(categoryUi.category)
|
||||||
|
Loading…
Reference in New Issue
Block a user