admin/plugins: search online columns will now persist reload

Massimo Melina committed Jun 5, 2022 at 10:10 UTC 63c57594a03e1653823a79d4070bbe95597b8819
1 file changed +11 -2
admin/src/state.ts
+11 -2
@@ -3,7 +3,10 @@
3 import { proxy, useSnapshot } from 'valtio'
4 import { Dict } from './misc'
5 import { VfsNode } from './VfsPage'
6 +import _ from 'lodash'
7 +import { subscribeKey } from 'valtio/utils'
8
9 +const STORAGE_KEY = 'admin_state'
10 export const state = proxy<{
11 title: string
12 config: Dict
@@ -13,7 +16,7 @@ export const state = proxy<{
16 loginRequired: boolean
17 username: string
18 onlinePluginsColumns: Dict<boolean>
16 -}>({
19 +}>(Object.assign({
20 title: '',
21 config: {},
22 changes: {},
@@ -26,7 +29,13 @@ export const state = proxy<{
29 pushed_at: false,
30 license: false,
31 }
29 -})
32 +}, JSON.parse(localStorage[STORAGE_KEY]||null)))
33 +
34 +const SETTINGS_TO_STORE: (keyof typeof state)[] = ['onlinePluginsColumns']
35 +const storeSettings = _.debounce(() =>
36 + localStorage[STORAGE_KEY] = JSON.stringify(_.pick(state, SETTINGS_TO_STORE)), 500, { maxWait: 1000 })
37 +for (const k of SETTINGS_TO_STORE)
38 + subscribeKey(state, k, storeSettings)
39
40 export function useSnapState() {
41 return useSnapshot(state)