Skip to content

Commit debdbef

Browse files
added remove feature
1 parent 1beabb0 commit debdbef

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

assets/js/connections.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ function displayUserCard(data, containerID) {
2121
level.className = 'absolute top-2 right-3 mt-2 mr-2 text-sm text-gray-400';
2222
level.textContent = `Level: ${data.level}`;
2323

24+
const del = document.createElement('button');
25+
del.className = 'bg-red-600 text-sm absolute bottom-4 right-20 mt-2 mr-2 px-4 py-2 rounded-md hover:bg-red-700 duration-300';
26+
del.textContent = 'Remove';
27+
del.onclick = function () {
28+
const userRef = db.collection("Users").doc(auth.currentUser.uid);
29+
userRef.update({
30+
connections: firebase.firestore.FieldValue.arrayRemove(data.senderId)
31+
}).then(() => {
32+
console.log("User removed from connections successfully!");
33+
card.remove();
34+
}
35+
).catch((error) => {
36+
console.error("Error removing user from connections: ", error);
37+
}
38+
);
39+
}
40+
2441
const button = document.createElement('button');
2542
button.className = 'bg-blue-600 text-sm absolute bottom-4 right-3 mt-2 mr-2 px-4 py-2 rounded-md hover:bg-blue-700 duration-300';
2643
button.textContent = 'Chat';
@@ -51,6 +68,7 @@ function displayUserCard(data, containerID) {
5168
div.appendChild(p);
5269

5370
card.appendChild(level);
71+
card.appendChild(del);
5472
card.appendChild(button);
5573
card.appendChild(img);
5674
card.appendChild(div);

0 commit comments

Comments
 (0)