🐛 (database) fix init local database

This commit is contained in:
Julien Calixte
2019-12-29 00:53:58 +01:00
parent b6deea2109
commit 85cb069e9b

View File

@@ -23,7 +23,7 @@ const LOCALE_DB: string = 'VAQUANT_LOCALE_DB'
const REMOTE: string = 'https://juliencalixte.ddns.net/database'
class CouchService {
public db: PouchDB.Database | null = new PouchDb(LOCALE_DB)
public db: PouchDB.Database | null = null
private innerRemote: PouchDB.Database | null = null
private user: IUser | null = null
private sync: PouchDB.Replication.Sync<{}> | null = null
@@ -38,6 +38,7 @@ class CouchService {
}
constructor() {
this.initDb()
if (!this.eventListened) {
this.eventListened = true
window.addEventListener('online', () => {
@@ -50,7 +51,6 @@ class CouchService {
})
}
}
public async initLive(): Promise<boolean> {
if (!this.db) {
return false
@@ -230,6 +230,14 @@ class CouchService {
this.userSync = null
}
}
private initDb(): void {
if (this.user) {
this.db = new PouchDb(`vaquant-${this.user.userId}`)
} else {
this.db = new PouchDb(LOCALE_DB)
}
}
}
export default new CouchService()