- Refactoring: Error Boundaries, apiFetch Wrapper, Socket Status-Tracking - Refactoring: UI Kontrast (theme-aware colors), unused imports bereinigt - Symbol-Verwaltung: Neues Split-Panel (Meine Symbole + Bibliothek) - Symbol-Verwaltung: Umbenennen (TLF rot/blau), Duplikate erlaubt - Symbol-Verwaltung: Karten-Sidebar zeigt eigene Symbole bevorzugt - Schlauch-Labels: Groessere Schrift (13px/10px), verschiebbar (Drag) - Schema: TenantSymbol customName, sortOrder, unique constraint entfernt - Open Source Referenz entfernt (kostenloses Projekt)
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { create } from 'zustand'
|
|
import type { Project, Feature, JournalEntry } from '@/types'
|
|
|
|
interface ProjectStore {
|
|
// Projekt-Daten
|
|
project: Project | null
|
|
features: Feature[] // Karten-Elemente (Symbole, Linien, Polygone)
|
|
journalEntries: JournalEntry[]
|
|
|
|
// Actions
|
|
setProject: (project: Project | null) => void
|
|
setFeatures: (features: Feature[]) => void
|
|
addFeature: (feature: Feature) => void
|
|
updateFeature: (id: string, updates: Partial<Feature>) => void
|
|
removeFeature: (id: string) => void
|
|
|
|
setJournalEntries: (entries: JournalEntry[]) => void
|
|
addJournalEntry: (entry: JournalEntry) => void
|
|
|
|
// Realtime-Sync Actions (werden von Socket.io getriggert)
|
|
syncFeatures: (features: Feature[]) => void
|
|
syncJournalEntry: (entry: JournalEntry) => void
|
|
}
|
|
|
|
export const useProjectStore = create<ProjectStore>((set) => ({
|
|
project: null,
|
|
features: [],
|
|
journalEntries: [],
|
|
|
|
setProject: (project) => set({ project }),
|
|
|
|
setFeatures: (features) => set({ features }),
|
|
|
|
addFeature: (feature) => set((state) => ({
|
|
features: [...state.features, feature]
|
|
})),
|
|
|
|
updateFeature: (id, updates) => set((state) => ({
|
|
features: state.features.map(f =>
|
|
f.id === id || f.properties?.id === id
|
|
? { ...f, properties: { ...f.properties, ...updates } }
|
|
: f
|
|
)
|
|
})),
|
|
|
|
removeFeature: (id) => set((state) => ({
|
|
features: state.features.filter(f => f.id !== id && f.properties?.id !== id)
|
|
})),
|
|
|
|
setJournalEntries: (entries) => set({ journalEntries: entries }),
|
|
|
|
addJournalEntry: (entry) => set((state) => ({
|
|
journalEntries: [...state.journalEntries, entry]
|
|
})),
|
|
|
|
syncFeatures: (features) => set({ features }),
|
|
|
|
syncJournalEntry: (entry) => set((state) => {
|
|
// Avoid duplicates
|
|
if (state.journalEntries.some(e => e.id === entry.id)) {
|
|
return {
|
|
journalEntries: state.journalEntries.map(e => e.id === entry.id ? entry : e)
|
|
}
|
|
}
|
|
return {
|
|
journalEntries: [...state.journalEntries, entry]
|
|
}
|
|
}),
|
|
}))
|