-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyposts.js
119 lines (103 loc) · 3.99 KB
/
myposts.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var db = firebase.firestore();
var user = firebase.auth().currentUser;
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var displayName = user.displayName;
var email = user.email;
var emailVerified = user.emailVerified;
var photoURL = user.photoURL;
var isAnonymous = user.isAnonymous;
var uid = user.uid;
var providerData = user.providerData;
var user = firebase.auth().currentUser;
if(user != null){
var email_id = user.email;
}
} else {
//
}
});
function logout(){
firebase.auth().signOut().then(function() {
// Sign-out successful.
}).catch(function(error) {
// An error happened.
});
location.replace("index.html");
}
//var linkmyposts = document.getElementById("mindposts");
//linkmyposts.addEventListener('click',getmyposts);
console.log('works');
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var displayName = user.displayName;
var email = user.email;
var emailVerified = user.emailVerified;
var photoURL = user.photoURL;
var isAnonymous = user.isAnonymous;
var uid = user.uid;
var providerData = user.providerData;
// ...
db.collection("users").doc(email).collection("usermind").get().then(function(querySnapshot){
querySnapshot.forEach(function(doc) {
console.log(doc.id);
let hr = document.createElement("hr");
let lion = document.createElement('li');
let tiger = document.createTextNode(doc.data().onMind);
let fortiger = document.createElement("H3");
let tigress = document.createTextNode( doc.data().byEmail);
let fortigeress = document.createElement("H5");
let deletebtn = document.createTextNode("delete");
let fordeletebtn = document.createElement("button");
fordeletebtn.value = doc.id;
lion.setAttribute("class","forlion");
fordeletebtn.setAttribute("class","delbtn");
fortiger.append(tiger);
fortigeress.append(tigress);
fordeletebtn.append(deletebtn);
lion.appendChild(hr);
lion.appendChild(fortiger);
lion.appendChild(fortigeress);
lion.appendChild(fordeletebtn);
lion.appendChild(hr);
lion.appendChild(document.createElement('br'));
docID = doc.id;
lion.setAttribute("id",docID);
document.getElementById("mindposts").appendChild(lion);
fordeletebtn.addEventListener("click",deletepost,fordeletebtn);
});
});
}
else {
// User is signed out.
// ...
}
});
function deletepost(e){
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var displayName = user.displayName;
var email = user.email;
var emailVerified = user.emailVerified;
var photoURL = user.photoURL;
var isAnonymous = user.isAnonymous;
var uid = user.uid;
var providerData = user.providerData;
var user = firebase.auth().currentUser;
var docRef = db.collection("users").doc(email).collection("usermind");
var docID = e.path[0].value;
docRef.doc(docID).delete().then(() => {
console.log('Document deleted');
let elem = document.getElementById(docID);
elem.parentNode.removeChild(elem);
}).catch( error => {
console.error("Error removing: ", error);
});
} else {
//
}
});
}