| class Store { | |
| constructor() { | |
| this.state = { | |
| user: null, | |
| projects: [], | |
| currentProject: null, | |
| buckets: [], | |
| currentBucket: null, | |
| files: [], | |
| apiKeys: [], | |
| notifications: [] | |
| }; | |
| } | |
| setUser(user) { | |
| this.state.user = user; | |
| this.save(); | |
| } | |
| addProject(project) { | |
| this.state.projects.push(project); | |
| this.save(); | |
| } | |
| setCurrentProject(projectId) { | |
| this.state.currentProject = this.state.projects.find(p => p.id === projectId); | |
| this.save(); | |
| } | |
| addBucket(bucket) { | |
| this.state.buckets.push(bucket); | |
| this.save(); | |
| } | |
| setCurrentBucket(bucketId) { | |
| this.state.currentBucket = this.state.buckets.find(b => b.id === bucketId); | |
| this.save(); | |
| } | |
| addFile(file) { | |
| this.state.files.push(file); | |
| this.save(); | |
| } | |
| removeFile(fileId) { | |
| this.state.files = this.state.files.filter(f => f.id !== fileId); | |
| this.save(); | |
| } | |
| addApiKey(apiKey) { | |
| this.state.apiKeys.push(apiKey); | |
| this.save(); | |
| } | |
| removeApiKey(keyId) { | |
| this.state.apiKeys = this.state.apiKeys.filter(k => k.id !== keyId); | |
| this.save(); | |
| } | |
| addNotification(notification) { | |
| this.state.notifications.push(notification); | |
| setTimeout(() => { | |
| this.removeNotification(notification.id); | |
| }, 3000); | |
| this.save(); | |
| } | |
| removeNotification(id) { | |
| this.state.notifications = this.state.notifications.filter(n => n.id !== id); | |
| this.save(); | |
| } | |
| save() { | |
| localStorage.setItem('bucketmaster-state', JSON.stringify(this.state)); | |
| } | |
| load() { | |
| const saved = localStorage.getItem('bucketmaster-state'); | |
| if (saved) { | |
| this.state = JSON.parse(saved); | |
| } | |
| } | |
| } | |
| const store = new Store(); | |
| store.load(); | |
| export default store; |