diff --git a/app/components/app-menu/settings.gjs b/app/components/app-menu/settings.gjs
index 50654b9..67e32c7 100644
--- a/app/components/app-menu/settings.gjs
+++ b/app/components/app-menu/settings.gjs
@@ -1,25 +1,41 @@
+import Component from '@glimmer/component';
import { on } from '@ember/modifier';
+import { action } from '@ember/object';
+import { service } from '@ember/service';
import Icon from '#components/icon';
import AppMenuSettingsMapUi from './settings/map-ui';
import AppMenuSettingsApis from './settings/apis';
import AppMenuSettingsNostr from './settings/nostr';
-
-
+export default class AppMenuSettings extends Component {
+ @service settings;
-
-
+ @action
+ updateSetting(key, event) {
+ let value = event.target.value;
+ if (value === 'true') value = true;
+ if (value === 'false') value = false;
+
+ this.settings.update(key, value);
+ }
+
+
+
+
+
+
+}
diff --git a/app/components/app-menu/settings/apis.gjs b/app/components/app-menu/settings/apis.gjs
index 44a1cb5..8231b34 100644
--- a/app/components/app-menu/settings/apis.gjs
+++ b/app/components/app-menu/settings/apis.gjs
@@ -1,23 +1,13 @@
import Component from '@glimmer/component';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
-import { action } from '@ember/object';
+import { fn } from '@ember/helper';
import Icon from '#components/icon';
import eq from 'ember-truth-helpers/helpers/eq';
export default class AppMenuSettingsApis extends Component {
@service settings;
- @action
- updateApi(event) {
- this.settings.updateOverpassApi(event.target.value);
- }
-
- @action
- updatePhotonApi(event) {
- this.settings.updatePhotonApi(event.target.value);
- }
-
{{! template-lint-disable no-nested-interactive }}
@@ -31,7 +21,7 @@ export default class AppMenuSettingsApis extends Component {
{{#each this.settings.overpassApis as |api|}}
{{#each this.settings.photonApis as |api|}}
{{! template-lint-disable no-nested-interactive }}
@@ -30,7 +20,7 @@ export default class AppMenuSettingsMapUi extends Component {
{{! template-lint-disable no-nested-interactive }}
@@ -28,7 +21,7 @@ export default class AppMenuSettingsNostr extends Component {
api.url === savedApi);
- if (isValid) {
- this.overpassApi = savedApi;
- } else {
- // If not valid, revert to default
- this.overpassApi = 'https://overpass-api.de/api/interpreter';
- localStorage.setItem('marco:overpass-api', this.overpassApi);
+ let settings = {};
+ const savedSettings = localStorage.getItem('marco:settings');
+
+ if (savedSettings) {
+ try {
+ settings = JSON.parse(savedSettings);
+ } catch (e) {
+ console.error('Failed to parse settings from localStorage', e);
}
+ } else {
+ // Migration from old individual keys
+ const savedApi = localStorage.getItem('marco:overpass-api');
+ if (savedApi) settings.overpassApi = savedApi;
+
+ const savedKinetic = localStorage.getItem('marco:map-kinetic');
+ if (savedKinetic !== null) settings.mapKinetic = savedKinetic === 'true';
+
+ const savedShowQuickSearch = localStorage.getItem(
+ 'marco:show-quick-search'
+ );
+ if (savedShowQuickSearch !== null) {
+ settings.showQuickSearchButtons = savedShowQuickSearch === 'true';
+ }
+
+ const savedNostrPhotoFallbackUploads = localStorage.getItem(
+ 'marco:nostr-photo-fallback-uploads'
+ );
+ if (savedNostrPhotoFallbackUploads !== null) {
+ settings.nostrPhotoFallbackUploads =
+ savedNostrPhotoFallbackUploads === 'true';
+ }
+
+ const savedPhotonApi = localStorage.getItem('marco:photon-api');
+ if (savedPhotonApi) settings.photonApi = savedPhotonApi;
}
- const savedKinetic = localStorage.getItem('marco:map-kinetic');
- if (savedKinetic !== null) {
- this.mapKinetic = savedKinetic === 'true';
- }
- // Default is true (initialized in class field)
+ // Merge with defaults
+ const finalSettings = { ...DEFAULT_SETTINGS, ...settings };
- const savedShowQuickSearch = localStorage.getItem(
- 'marco:show-quick-search'
+ // Validate overpass API
+ const isValid = this.overpassApis.some(
+ (api) => api.url === finalSettings.overpassApi
);
- if (savedShowQuickSearch !== null) {
- this.showQuickSearchButtons = savedShowQuickSearch === 'true';
+ if (!isValid) {
+ finalSettings.overpassApi = DEFAULT_SETTINGS.overpassApi;
}
- const savedNostrPhotoFallbackUploads = localStorage.getItem(
- 'marco:nostr-photo-fallback-uploads'
- );
- if (savedNostrPhotoFallbackUploads !== null) {
- this.nostrPhotoFallbackUploads =
- savedNostrPhotoFallbackUploads === 'true';
+ // Apply to tracked properties
+ this.overpassApi = finalSettings.overpassApi;
+ this.mapKinetic = finalSettings.mapKinetic;
+ this.photonApi = finalSettings.photonApi;
+ this.showQuickSearchButtons = finalSettings.showQuickSearchButtons;
+ this.nostrPhotoFallbackUploads = finalSettings.nostrPhotoFallbackUploads;
+
+ // Save to ensure migrated settings are stored in the new format
+ this.saveSettings();
+ }
+
+ saveSettings() {
+ const settings = {
+ overpassApi: this.overpassApi,
+ mapKinetic: this.mapKinetic,
+ photonApi: this.photonApi,
+ showQuickSearchButtons: this.showQuickSearchButtons,
+ nostrPhotoFallbackUploads: this.nostrPhotoFallbackUploads,
+ };
+ localStorage.setItem('marco:settings', JSON.stringify(settings));
+ }
+
+ update(key, value) {
+ if (key in DEFAULT_SETTINGS) {
+ this[key] = value;
+ this.saveSettings();
}
}
-
- updateOverpassApi(url) {
- this.overpassApi = url;
- localStorage.setItem('marco:overpass-api', url);
- }
-
- updateMapKinetic(enabled) {
- this.mapKinetic = enabled;
- localStorage.setItem('marco:map-kinetic', String(enabled));
- }
-
- updateShowQuickSearchButtons(enabled) {
- this.showQuickSearchButtons = enabled;
- localStorage.setItem('marco:show-quick-search', String(enabled));
- }
-
- updatePhotonApi(url) {
- this.photonApi = url;
- }
-
- updateNostrPhotoFallbackUploads(enabled) {
- this.nostrPhotoFallbackUploads = enabled;
- localStorage.setItem('marco:nostr-photo-fallback-uploads', String(enabled));
- }
}