mirror of
https://github.com/balzack/databag.git
synced 2025-04-23 01:55:17 +00:00
preparing landing page
This commit is contained in:
parent
5f3ad8ed25
commit
bb83b87cb3
24
app/client/web/src/SessionStore.ts
Normal file
24
app/client/web/src/SessionStore.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { WebStore } from 'databag-client-sdk'
|
||||
|
||||
export class SessionStore implements WebStore {
|
||||
public async getValue (key: string): Promise<any> {
|
||||
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<void> {
|
||||
localStorage.setItem(key, JSON.stringify(value))
|
||||
}
|
||||
|
||||
public async clearValue (key: string): Promise<void> {
|
||||
localStorage.removeItem(key)
|
||||
}
|
||||
|
||||
public async clearAll (): Promise<void> {
|
||||
localStorage.clear()
|
||||
}
|
||||
}
|
@ -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<any> {
|
||||
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<void> {
|
||||
localStorage.setItem(key, JSON.stringify(value))
|
||||
}
|
||||
|
||||
public async clearValue (key: string): Promise<void> {
|
||||
localStorage.removeItem(key)
|
||||
}
|
||||
|
||||
public async clearAll (): Promise<void> {
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user