Skip to content

Commit

Permalink
Move default settings to assets
Browse files Browse the repository at this point in the history
  • Loading branch information
wkramer committed Jul 25, 2023
1 parent 27f2648 commit 0112a65
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 25 deletions.
101 changes: 101 additions & 0 deletions src/assets/DefaultUserSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
[
{
"id": "units.displayUnits",
"type": "oneOfMultiple",
"label": "Display Units",
"value": "display",
"items": [
{
"value": "stored",
"icon": "mdi-database"
},
{
"value": "display",
"icon": "mdi-monitor"
},
{
"value": "custom",
"icon": "mdi-monitor-edit",
"disabled": true
}
],
"group": "Units"
},
{
"id": "units.parameterGroup.Discharge",
"type": "oneOfMultiple",
"label": "Discharge",
"value": "ML/d",
"disabled": true,
"items": [
{
"value": "m³/s"
},
{
"value": "ML/d"
}
],
"group": "Units"
},
{
"id": "units.parameterGroup.Volume",
"type": "oneOfMultiple",
"label": "Volume",
"value": "ML",
"disabled": true,
"items": [
{
"value": ""
},
{
"value": "ML"
}
],
"group": "Units"
},
{
"id": "datum.verticalDatum",
"type": "boolean",
"label": "Absolute vertical datum",
"value": true,
"group": "Datum"
},
{
"id": "ui.theme",
"type": "oneOfMultiple",
"label": "Theme",
"value": "auto",
"items": [
{
"value": "auto",
"icon": "mdi-theme-light-dark"
},
{
"value": "light",
"icon": "mdi-weather-sunny"
},
{
"value": "dark",
"icon": "mdi-weather-night"
}
],
"group": "UI"
},
{
"id": "locale.language",
"type": "oneOfMultiple",
"label": "Language",
"value": "en-au",
"items": [
{
"icon": "fi-au",
"value": "en-au"
},
{
"icon": "fi-nl",
"value": "nl-nl"
}
],
"group": "Locale"
}
]
27 changes: 2 additions & 25 deletions src/store/modules/user-settings/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RootState } from '../../types'
import { UserSettingsItem, UserSettingsState } from './types'
import { state as emptyState } from './index'
import DefaultUserSettings from '@/assets/DefaultUserSettings.json'

export function serializeState(state: UserSettingsState): Partial<UserSettingsItem>[] {
const serializedSettings: Partial<UserSettingsItem>[] = []
Expand All @@ -17,31 +18,7 @@ export function serializeState(state: UserSettingsState): Partial<UserSettingsIt
}

export function deserializeState(json: string): Partial<RootState> {
const defaultSettings: UserSettingsItem[] = [
{ id: 'units.displayUnits', type: 'oneOfMultiple', label: 'Display Units', value: 'display', items: [
{ value: 'stored', icon: 'mdi-database'},
{ value: 'display', icon: 'mdi-monitor'},
{ value: 'custom' , icon: 'mdi-monitor-edit', disabled: true}
], group: 'Units'},
{ id: 'units.parameterGroup.Discharge', type: 'oneOfMultiple', label: 'Discharge', value: 'ML/d', disabled: true, items: [
{ value: 'm³/s' },
{ value: 'ML/d'}
], group: 'Units'},
{ id: 'units.parameterGroup.Volume', type: 'oneOfMultiple', label: 'Volume', value: 'ML', disabled: true, items: [
{ value: 'm³' },
{ value: 'ML' }
], group: 'Units'},
{ id: 'datum.verticalDatum', type: 'boolean', label: 'Absolute vertical datum', value: true, group: 'Datum'},
{ id: 'ui.theme', type: 'oneOfMultiple', label: 'Theme', value: 'auto', items: [
{ value: 'auto', icon: 'mdi-theme-light-dark'},
{ value: 'light', icon: 'mdi-weather-sunny'},
{ value: 'dark' , icon: 'mdi-weather-night'}
], group: 'UI'},
{ id: 'locale.language', type: 'oneOfMultiple', label: 'Language', value: 'en-au', items: [
{ icon: 'fi-au', value: 'en-au' },
{ icon: 'fi-nl', value: 'nl-nl' }
], group: 'Locale'},
]
const defaultSettings = DefaultUserSettings as UserSettingsItem[]
const defaultState = emptyState
defaultState.allIds = defaultSettings.map( item => item.id)
const byId: Record<string,UserSettingsItem>= {}
Expand Down

0 comments on commit 0112a65

Please sign in to comment.