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) {