From fcafe0ce4342caf6fc5145802f7d89a8b6d8913c Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Fri, 13 Feb 2026 20:28:50 -0600 Subject: [PATCH] load and save config to localStorage --- src/services/config.service.ts | 81 +++++++++++----------------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/src/services/config.service.ts b/src/services/config.service.ts index 6059fb7..64ad759 100644 --- a/src/services/config.service.ts +++ b/src/services/config.service.ts @@ -24,67 +24,38 @@ export class ConfigService { } loadConfig() { - // TODO(jwetzell): load from local storage + const configString = localStorage.getItem('config'); + if (configString) { + try { + const config = JSON.parse(configString); + const valid = this.schemaService.validate(config); + if (valid) { + console.log('Loaded config from local storage', config); + this.updateCurrentlyShownConfig(config); + } else { + console.error('Config in local storage is invalid', config); + this.setEmptyConfig(); + } + } catch (e) { + console.error('Failed to parse config from local storage', e); + this.setEmptyConfig(); + } + } else { + this.setEmptyConfig(); + } + } + + setEmptyConfig() { + console.log('Setting empty config'); this.updateCurrentlyShownConfig({ - modules: [ - { - id: 'http', - type: 'http.server', - params: { - port: 8080, - }, - }, - { - id: 'http', - type: 'http.server', - params: { - port: 8080, - }, - }, - { - id: 'http', - type: 'http.server', - params: { - port: 8080, - }, - }, - { - id: 'http', - type: 'http.server', - params: { - port: 8080, - }, - }, - { - id: 'http', - type: 'http.server', - params: { - port: 8080, - }, - }, - { - id: 'http', - type: 'http.server', - params: { - port: 8080, - }, - }, - { - id: 'http', - type: 'http.server', - params: { - port: 8080, - }, - }, - ], + modules: [], routes: [], }); } saveConfig(config: Config) { - // TODO(jwetzell): save to local storage - console.log('saveConfig'); - console.log(config); + localStorage.setItem('config', JSON.stringify(config)); + console.log('Config saved to local storage', config); } updateCurrentlyShownConfig(config: Config) {