diff --git a/src/components/Child.js b/src/components/Child.js index 4baf672..0a8db97 100644 --- a/src/components/Child.js +++ b/src/components/Child.js @@ -2,8 +2,7 @@ import React, { Component } from 'react'; import { Button, FormGroup, Checkbox, ControlLabel, FormControl } from 'react-bootstrap'; import uuid from 'node-uuid'; import localforage from 'localforage'; -//import { BrowserRouter as Router, Route, Link } from 'react-router-dom'; -//import { } from 'react-bootstrap'; +import createHistory from 'history/createBrowserHistory' import '../App.css'; import h5bp_interview from '../utilities/h5bp_interview.json'; import { CATEGORIES } from '../utilities/constants'; @@ -36,7 +35,7 @@ class Child extends Component { // this.removeArrayItem = this.removeArrayItem.bind(this); this.handleViewMenu = this.handleViewMenu.bind(this); this.isChecked = this.isChecked.bind(this); - + this.handleRemoveList = this.handleRemoveList.bind(this); // var maxQuestionsObj = this.getMaxCountObj(); // maxQuestionsObj.display = 'all'; // this.state = maxQuestionsObj; @@ -90,7 +89,7 @@ class Child extends Component {

{this.state.name} List

- {this.state.viewState === 'read' ?
Edit | Delete
:
Read | Delete
} + {this.state.viewState === 'read' ?
Edit | Delete
:
Read | Delete
} {this.state.viewState === 'edit' ? : null} {this.state.viewState === 'read' ? questionsList : this.renderEditQuestions()} {this.state.viewState === 'edit' ? : null} @@ -114,6 +113,8 @@ class Child extends Component { }) break; case 'delete-link': + console.log('clicked delete menu'); + this.handleRemoveList(); break; case 'read-link': this.setState({ @@ -186,6 +187,40 @@ class Child extends Component { } + /** + * @param {} + * @return {} + * + * + */ + handleRemoveList() { + const keyRemove = this.listId; + let that = this; + + localforage.removeItem(keyRemove).then(function() { + var savedLists = []; + var renderSavedLists = []; + + localforage.iterate(function(value, key, iterationNumber) { + savedLists.push([key, value]); + }).then(function() { + console.log('list deleted'); + const history = createHistory(); + history.push('/favorites'); + // need reload latest lists content + window.location.reload(); + }).catch(function(err) { + // This code runs if there were any errors + console.log(err); + }); + + }).catch(function(err) { + // This code runs if there were any errors + console.log(err); + }); + + } + /** * @param {} * @return {} diff --git a/src/components/Favorites.js b/src/components/Favorites.js index 6eb54ce..a8a13cc 100644 --- a/src/components/Favorites.js +++ b/src/components/Favorites.js @@ -83,21 +83,14 @@ class Favorites extends Component { * */ handleRemoveList(e) { - console.log('clicked remove icon'); - console.log('e.target.id: ' + e.target.id); const keyRemove = e.target.id; let that = this; localforage.removeItem(keyRemove).then(function() { - // Run this code once the key has been removed. - console.log('Key is cleared!'); - var savedLists = []; var renderSavedLists = []; - // The same code, but using ES6 Promises. localforage.iterate(function(value, key, iterationNumber) { - savedLists.push([key, value]); }).then(function() { renderSavedLists = savedLists.map((list) => {