-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.js
59 lines (53 loc) · 1.51 KB
/
service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let store = {};
let keys = [];
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional...
var firebaseConfig = {
apiKey: "AIzaSyDeBSykwrmtb7MYUjdgv3l1amrXkeMnaw4",
authDomain: "diwali2020-10ba6.firebaseapp.com",
databaseURL: "https://diwali2020-10ba6.firebaseio.com",
projectId: "diwali2020-10ba6",
storageBucket: "diwali2020-10ba6.appspot.com",
messagingSenderId: "1045739233580",
appId: "1:1045739233580:web:1af027dedd2799b60f4c89",
measurementId: "G-ZKLGLSCG4K"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
let database = firebase.database();
function storeUser(name, lat, long, time) {
let stored = firebase.database().ref('users').push({
name,
lat,
long,
time
});
current_user.key = stored.key;
current_user.added = false;
$('#add-to-map').html(' ↓ Added to the map ↓ ');
}
function updateUser(key, name, lat, long, time){
firebase.database().ref(`/users/${key}`).update({
name,
lat,
long,
time
});
}
firebase.database().ref('users').once('value')
.then((snapshot) => {
store = snapshot.val();
_.map(store, (user) =>{
user.added = false;
});
console.log(store);
});
firebase.database().ref('users').on("child_added", (snapshot, prevChildKey) => {
var newLocation = snapshot.val();
console.log('new post added...')
console.log(snapshot.key);
console.log(newLocation);
newLocation.added = false;
store[snapshot.key] = newLocation;
});