nss-evening-cohort-10 / nutshell-nautilus-explorer

0 stars 0 forks source link

Environment Delete #26

Closed evangdesigns closed 4 years ago

evangdesigns commented 4 years ago

USER STORY As a user, I should be able to delete an environmental reading.

AC WHEN I am on the environments page I should see a delete link on the far right for each row of each environment. AND when I click DELETE THEN it will delete that environment from the database.

DEV

evangdesigns commented 4 years ago

Add button to domString inside printEnvironments <button type="link" class="btn btn-link delete-environment" id="delete-${environment.id}">DELETE</button>

Add Event listener to the end of the printEnvironments() function $('#environments').on('click', '.delete-environment', deleteEnvironment;

**Delete Function for environments.js

const deleteEnvironment= (e) => {
  e.stopImmediatePropagation();
  const enviId = e.target.id.split('delete-')[1];
 environments.deleteBoard(enviId)
    .then(() => {
      enviData.getEnvis(enviId)
        });
      firebase.auth().onAuthStateChanged((user) => {
        // eslint-disable-next-line no-use-before-define
        printEnvironments();
      });
    })
    .catch((error) => console.error(error));
};

Axios call to add to environmentsData.js

const deleteEnvironment = (Id) => axios.delete(`${baseUrl}/environments/${id}.json`);
evangdesigns commented 4 years ago

Logs_Destinations_Environments