fix: remove promise from isAvailable
This commit is contained in:
parent
71e92db24c
commit
186cdbeadd
@ -40,7 +40,7 @@ export function mapEventToProfile(ev: TaggedRawEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UsersDb {
|
export interface UsersDb {
|
||||||
isAvailable(): Promise<boolean>
|
isAvailable(): boolean
|
||||||
query(str: string): Promise<MetadataCache[]>
|
query(str: string): Promise<MetadataCache[]>
|
||||||
find(key: HexKey): Promise<MetadataCache | undefined>
|
find(key: HexKey): Promise<MetadataCache | undefined>
|
||||||
add(user: MetadataCache): Promise<any>
|
add(user: MetadataCache): Promise<any>
|
||||||
|
@ -5,7 +5,7 @@ import { UsersDb, MetadataCache, setUsers } from "State/Users";
|
|||||||
import store from "State/Store";
|
import store from "State/Store";
|
||||||
|
|
||||||
class IndexedDb implements UsersDb {
|
class IndexedDb implements UsersDb {
|
||||||
async isAvailable() {
|
isAvailable() {
|
||||||
try {
|
try {
|
||||||
const req = "indexedDb" in window && window.indexedDB.open('test', 1)
|
const req = "indexedDb" in window && window.indexedDB.open('test', 1)
|
||||||
return Boolean(req)
|
return Boolean(req)
|
||||||
@ -58,7 +58,7 @@ function groupByPubkey(acc: Record<HexKey, MetadataCache>, user: MetadataCache)
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ReduxUsersDb implements UsersDb {
|
class ReduxUsersDb implements UsersDb {
|
||||||
async isAvailable() { return true }
|
isAvailable() { return true }
|
||||||
|
|
||||||
async query(q: string) {
|
async query(q: string) {
|
||||||
const state = store.getState()
|
const state = store.getState()
|
||||||
@ -128,10 +128,13 @@ class ReduxUsersDb implements UsersDb {
|
|||||||
export const indexedDb = new IndexedDb()
|
export const indexedDb = new IndexedDb()
|
||||||
export const inMemoryDb = new ReduxUsersDb()
|
export const inMemoryDb = new ReduxUsersDb()
|
||||||
|
|
||||||
let db: UsersDb = inMemoryDb
|
const isIndexedDbAvailable = indexedDb.isAvailable()
|
||||||
indexedDb.isAvailable().then(() => {
|
const db: UsersDb = isIndexedDbAvailable ? indexedDb : inMemoryDb;
|
||||||
console.debug('IndexedDB available')
|
|
||||||
db = indexedDb
|
if (isIndexedDbAvailable) {
|
||||||
})
|
console.debug('Using Indexed DB')
|
||||||
|
} else {
|
||||||
|
console.debug('Using in-memory DB')
|
||||||
|
}
|
||||||
|
|
||||||
export default db
|
export default db
|
||||||
|
Loading…
Reference in New Issue
Block a user