feat: implement hierarchical category management with parent-child relationships and enhance category creation dialog
This commit is contained in:
40
lib/store.ts
40
lib/store.ts
@@ -5,11 +5,49 @@ import { defaultCategories, defaultRootFolder } from "./defaults"
|
||||
|
||||
const STORAGE_KEY = "banking-app-data"
|
||||
|
||||
// Convertir les CategoryDefinition en Category pour le localStorage
|
||||
function buildCategoriesFromDefaults(): Category[] {
|
||||
const slugToId = new Map<string, string>()
|
||||
const categories: Category[] = []
|
||||
|
||||
// D'abord les parents
|
||||
const parents = defaultCategories.filter((c) => c.parentSlug === null)
|
||||
parents.forEach((cat, index) => {
|
||||
const id = `cat-${index + 1}`
|
||||
slugToId.set(cat.slug, id)
|
||||
categories.push({
|
||||
id,
|
||||
name: cat.name,
|
||||
color: cat.color,
|
||||
icon: cat.icon,
|
||||
keywords: cat.keywords,
|
||||
parentId: null,
|
||||
})
|
||||
})
|
||||
|
||||
// Puis les enfants
|
||||
const children = defaultCategories.filter((c) => c.parentSlug !== null)
|
||||
children.forEach((cat, index) => {
|
||||
const id = `cat-${parents.length + index + 1}`
|
||||
slugToId.set(cat.slug, id)
|
||||
categories.push({
|
||||
id,
|
||||
name: cat.name,
|
||||
color: cat.color,
|
||||
icon: cat.icon,
|
||||
keywords: cat.keywords,
|
||||
parentId: cat.parentSlug ? slugToId.get(cat.parentSlug) || null : null,
|
||||
})
|
||||
})
|
||||
|
||||
return categories
|
||||
}
|
||||
|
||||
const defaultData: BankingData = {
|
||||
accounts: [],
|
||||
transactions: [],
|
||||
folders: [defaultRootFolder],
|
||||
categories: defaultCategories.map((cat, index) => ({ ...cat, id: `cat-${index + 1}` })),
|
||||
categories: buildCategoriesFromDefaults(),
|
||||
categoryRules: [],
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user