Support filtering to own/all servers if user is an admin
This commit is contained in:
parent
67c6be9f6f
commit
f45c03a449
4 changed files with 86 additions and 19 deletions
23
resources/scripts/plugins/usePersistedState.ts
Normal file
23
resources/scripts/plugins/usePersistedState.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
||||
|
||||
export function usePersistedState<S = undefined> (key: string, defaultValue: S): [S | undefined, Dispatch<SetStateAction<S | undefined>>] {
|
||||
const [state, setState] = useState(
|
||||
() => {
|
||||
try {
|
||||
const item = localStorage.getItem(key);
|
||||
|
||||
return JSON.parse(item || (String(defaultValue)));
|
||||
} catch (e) {
|
||||
console.warn('Failed to retrieve persisted value from store.', e);
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(key, JSON.stringify(state))
|
||||
}, [key, state]);
|
||||
|
||||
return [ state, setState ];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue