initial commit
This commit is contained in:
29
frontend/src/components/settingsManager.ts
Normal file
29
frontend/src/components/settingsManager.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import Alpine from 'alpinejs';
|
||||
import { getSettings, saveSettings } from '../client';
|
||||
import { Settings } from '../types';
|
||||
|
||||
Alpine.data('settingsManager', () => ({
|
||||
settings: {} as Settings,
|
||||
loading: false,
|
||||
saved: false,
|
||||
error: '',
|
||||
|
||||
async init() {
|
||||
this.settings = await getSettings();
|
||||
},
|
||||
|
||||
async saveSettings() {
|
||||
this.loading = true;
|
||||
this.saved = false;
|
||||
this.error = '';
|
||||
|
||||
try {
|
||||
await saveSettings(this.settings);
|
||||
this.saved = true;
|
||||
} catch (err) {
|
||||
this.error = String(err);
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user