Skip to content

Commit

Permalink
Fixed category deletion (#4352)
Browse files Browse the repository at this point in the history
* Fixed category deletion and removed the unused import @mui/icons-material

* Added a function to count the current active categories.
  • Loading branch information
hassanzahidd authored Feb 25, 2025
1 parent 2d682a0 commit 9411206
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/frontend/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ class GlobalState extends PureComponent<Props> {
getCustomCategories = () =>
Array.from(new Set(Object.keys(this.state.customCategories))).sort()

getCurrentCustomCategories = () =>
Array.from(new Set(this.state.currentCustomCategories)).sort()

setCustomCategory = (newCategory: string) => {
const newCustomCategories = this.state.customCategories
newCustomCategories[newCategory] = []
Expand All @@ -367,8 +370,17 @@ class GlobalState extends PureComponent<Props> {

const newCustomCategories = this.state.customCategories
delete newCustomCategories[category]

this.setState({ customCategories: { ...newCustomCategories } })

const updatedCategories = this.getCurrentCustomCategories().filter(
(cat) => cat !== category
)
this.setCurrentCustomCategories(updatedCategories)
const numberOfCategories = updatedCategories.length

if (numberOfCategories < 1) {
this.setCurrentCustomCategories(['preset_uncategorized'])
}
configStore.set('games.customCategories', newCustomCategories)
}

Expand Down

0 comments on commit 9411206

Please sign in to comment.