diff options
author | vnugent <public@vaughnnugent.com> | 2023-12-13 17:58:51 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-12-13 17:58:51 -0500 |
commit | 4b8ae76132d2342f40cec703b3d5145ea075c451 (patch) | |
tree | 62b942b6181261566cd3245ee35cd15a138aabf2 /front-end/src/store/globalState.ts | |
parent | b564708f29cf8a709c3e3d981477b2ec8440673e (diff) |
log time coming ui and lib updates
Diffstat (limited to 'front-end/src/store/globalState.ts')
-rw-r--r-- | front-end/src/store/globalState.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/front-end/src/store/globalState.ts b/front-end/src/store/globalState.ts new file mode 100644 index 0000000..9e700eb --- /dev/null +++ b/front-end/src/store/globalState.ts @@ -0,0 +1,30 @@ +import 'pinia' +import { shallowRef } from 'vue'; +import { useAutoHeartbeat } from '@vnuge/vnlib.browser'; +import { toRefs, useLocalStorage } from '@vueuse/core'; +import { PiniaPluginContext, PiniaPlugin } from 'pinia' +import { defaults } from 'lodash-es'; + +declare module 'pinia' { + export interface PiniaCustomProperties { + autoHeartbeat: boolean; + } +} + +export const globalStatePlugin: PiniaPlugin = ({ store }: PiniaPluginContext) =>{ + + //Get shared global state storage + const mainState = useLocalStorage("vn-state", { ahEnabled: false }); + + //Set defaults to avoid undefined errors from toRefs + defaults(mainState.value, { ahEnabled: false }) + + const { ahEnabled } = toRefs(mainState) + + //Setup heartbeat for 5 minutes + useAutoHeartbeat(shallowRef(5 * 60 * 1000), ahEnabled) + + return{ + autoHeartbeat: ahEnabled, + } +}
\ No newline at end of file |