From 4b8ae76132d2342f40cec703b3d5145ea075c451 Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 13 Dec 2023 17:58:51 -0500 Subject: log time coming ui and lib updates --- front-end/src/store/globalState.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 front-end/src/store/globalState.ts (limited to 'front-end/src/store/globalState.ts') 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 -- cgit