0

The site implements adding and deleting banks created by the user. When added, the bank is added to the Firebase database. When a user adds a bank, it is immediately displayed on the screen. How to make it disappear from the screen when deleting a bank? Now I have implemented deletion from Firebase, but I don’t know how to remove it from the array so that it disappears on the screen.

// Function that controls the display of banks on the screen

function getBanks() {
  db.collection("banks").onSnapshot((snapshot) => {
    let banks = [];
    snapshot.docChanges().forEach((change) => {
      const bank = {
        id: change.doc.id,
        ...change.doc.data(),
      };
      if (change.type === "added") {
        banks.push(bank);
        generateBanks([bank]);
      } else if (change.type === "removed") {
       //how to remove a bank from an array of banks and redraw the screen
      }
    });
  });
}

//bank deletion

  bank_delete_el.addEventListener("click", () => {
      db.collection("banks").doc(bank.id).delete();
    });
userName
  • 903
  • 2
  • 20
  • 1
    This looks like the same problem you posted about yesterday. Please don't repost the same problem multiple times. At best they will get closed, but it may actually get you banned from the site. Instead edit your previous question (there's a link right under it) to make any clarification and interact with the people who already tried to help you there. – Frank van Puffelen Jul 14 '22 at 19:55

1 Answers1

1

Simple filter function on banks will do the job. banks = banks.filter(bank => bank.id !== change.doc.id)

czlowiek488
  • 187
  • 2
  • 17