Skip to content

Commit

Permalink
refactor: initialize shelf states in LibraryViewModel for improved it…
Browse files Browse the repository at this point in the history
…em loading

- Added initShelfStates method to initialize shelfStates for all ShelfType cases, enhancing state management.
- Updated selectedCategory property to call initShelfStates and loadAllShelfItems when changed, ensuring consistent shelf item loading and state updates.
  • Loading branch information
lcandy2 committed Jan 21, 2025
1 parent 45d3953 commit 2fea1f3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions NeoDB/NeoDB/Views/Library/LibraryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class LibraryViewModel: ObservableObject {
@Published var selectedCategory: ItemCategory.shelfAvailable = .allItems {
didSet {
if oldValue != selectedCategory {
initShelfStates()
loadAllShelfItems()
}
}
Expand Down Expand Up @@ -61,6 +62,12 @@ final class LibraryViewModel: ObservableObject {
var currentShelfState: ShelfItemsState {
shelfStates[selectedShelfType] ?? ShelfItemsState()
}

func initShelfStates() {
for type in ShelfType.allCases {
shelfStates[type] = ShelfItemsState()
}
}

// MARK: - Public Methods
func loadShelfItems(type: ShelfType, refresh: Bool = false) async {
Expand Down

0 comments on commit 2fea1f3

Please sign in to comment.