mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 07:37:10 +00:00
Add field settings
This commit is contained in:
22
src/app/Settings.ts
Normal file
22
src/app/Settings.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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), {}]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user