-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathfirebase.js
51 lines (40 loc) · 1.31 KB
/
firebase.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
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/11.0.1/firebase-app.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
import {
getFirestore,
collection,
getDocs,
onSnapshot,
addDoc,
deleteDoc,
doc,
getDoc,
updateDoc,
} from "https://www.gstatic.com/firebasejs/11.0.1/firebase-firestore.js";
// Your web app's Firebase configuration
const firebaseConfig = {
// your credentials here
};
// Initialize Firebase
export const app = initializeApp(firebaseConfig);
export const db = getFirestore();
/**
* Save a New Task in Firestore
* @param {string} title the title of the Task
* @param {string} description the description of the Task
*/
export const saveTask = (title, description) =>
addDoc(collection(db, "tasks"), { title, description });
export const onGetTasks = (callback) =>
onSnapshot(collection(db, "tasks"), callback);
/**
*
* @param {string} id Task ID
*/
export const deleteTask = (id) => deleteDoc(doc(db, "tasks", id));
export const getTask = (id) => getDoc(doc(db, "tasks", id));
export const updateTask = (id, newFields) =>
updateDoc(doc(db, "tasks", id), newFields);
export const getTasks = () => getDocs(collection(db, "tasks"));