mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
23 lines
561 B
TypeScript
23 lines
561 B
TypeScript
type FieldSetting = {
|
|
path?: string
|
|
name?: string
|
|
hidden?: boolean
|
|
}
|
|
|
|
export class Settings {
|
|
fields: FieldSetting[]
|
|
|
|
constructor(private local_storage: string) {
|
|
const settings = JSON.parse(localStorage.getItem(local_storage) ?? '{}')
|
|
if (!Array.isArray(settings.fields)) settings.fields = []
|
|
this.fields = settings.fields
|
|
this.save()
|
|
}
|
|
|
|
save() {
|
|
const settings = JSON.stringify({ fields: this.fields })
|
|
localStorage.setItem(this.local_storage, settings)
|
|
this.fields = [...this.fields.filter(v => v?.path), {}]
|
|
}
|
|
}
|