From bb83b87cb35302150a059a8826fd21b5bdb65948 Mon Sep 17 00:00:00 2001 From: balzack Date: Wed, 31 Jul 2024 16:34:19 +0200 Subject: [PATCH] preparing landing page --- app/client/web/src/SessionStore.ts | 24 ++++++++++++++++ .../web/src/context/useAppContext.hook.ts | 28 ++----------------- 2 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 app/client/web/src/SessionStore.ts diff --git a/app/client/web/src/SessionStore.ts b/app/client/web/src/SessionStore.ts new file mode 100644 index 00000000..fe2a5c79 --- /dev/null +++ b/app/client/web/src/SessionStore.ts @@ -0,0 +1,24 @@ +import { WebStore } from 'databag-client-sdk' + +export class SessionStore implements WebStore { + public async getValue (key: string): Promise { + console.log('web store get: ', key) + const value = localStorage.getItem(key) + if (!value) { + return null + } + return JSON.parse(value) + } + + public async setValue (key: string, value: any): Promise { + localStorage.setItem(key, JSON.stringify(value)) + } + + public async clearValue (key: string): Promise { + localStorage.removeItem(key) + } + + public async clearAll (): Promise { + localStorage.clear() + } +} diff --git a/app/client/web/src/context/useAppContext.hook.ts b/app/client/web/src/context/useAppContext.hook.ts index 47501533..918278a7 100644 --- a/app/client/web/src/context/useAppContext.hook.ts +++ b/app/client/web/src/context/useAppContext.hook.ts @@ -1,28 +1,6 @@ import { useState, useEffect } from 'react' -import { DatabagSDK, WebStore, Session } from 'databag-client-sdk' - -class Store implements WebStore { - public async getValue (key: string): Promise { - console.log('web store get: ', key) - const value = localStorage.getItem(key) - if (!value) { - return null - } - return JSON.parse(value) - } - - public async setValue (key: string, value: any): Promise { - localStorage.setItem(key, JSON.stringify(value)) - } - - public async clearValue (key: string): Promise { - localStorage.removeItem(key) - } - - public async clearAll (): Promise { - localStorage.clear() - } -}; +import { DatabagSDK, Session } from 'databag-client-sdk' +import { SessionStore } from '../SessionStore' export function useAppContext () { const [state, setState] = useState({}) @@ -38,7 +16,7 @@ export function useAppContext () { const init = async () => { const sdk = new DatabagSDK(null) - const store = new Store() + const store = new SessionStore() const session: Session | null = await sdk.initOnlineStore(store) console.log(session) if (session) {