|
1
|
import app from 'firebase/app'; |
|
2
|
import 'firebase/database'; |
|
3
|
|
|
4
|
class Firebase { |
|
5
|
|
|
6
|
db!: app.database.Database; |
|
7
|
language!: string; |
|
8
|
|
|
9
|
public onLanguageChangedCallback: (() => void) | null = null |
|
10
|
private static instance: Firebase |
|
11
|
|
|
12
|
constructor(language: string, db: app.database.Database) { |
|
13
|
|
|
14
|
if (Firebase.instance) |
|
15
|
return Firebase.instance |
|
16
|
|
|
17
|
this.db = db; |
|
18
|
this.language = language; |
|
19
|
Firebase.instance = this; |
|
20
|
} |
|
21
|
|
|
22
|
setLanguage(language: string) { |
|
23
|
this.language = language |
|
24
|
|
|
25
|
if (this.onLanguageChangedCallback) |
|
26
|
this.onLanguageChangedCallback() |
|
27
|
} |
|
28
|
|
|
29
|
rootRef(): app.database.Reference { |
|
30
|
return this.db.ref('setoelkahfi-web-id').child(this.language); |
|
31
|
} |
|
32
|
|
|
33
|
whoAmIRef(): app.database.Reference { |
|
34
|
return this.rootRef().child('i am'); |
|
35
|
} |
|
36
|
|
|
37
|
aboutRef = () => this.rootRef().child('about'); |
|
38
|
cvRef = () => this.rootRef().child('cv'); |
|
39
|
contactRef = () => this.rootRef().child('contact'); |
|
40
|
} |
|
41
|
|
|
42
|
export default Firebase; |