Skip to content

Commit

Permalink
fix: #57; add handleRemoveList() click handler for delete from child
Browse files Browse the repository at this point in the history
  • Loading branch information
cch5ng committed Mar 30, 2017
1 parent 125312c commit edff5ac
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/components/Child.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +89,7 @@ class Child extends Component {
<div>
<h3>{this.state.name} List</h3>
<div>
{this.state.viewState === 'read' ? <div className="right" onClick={this.handleViewMenu}><span id="edit-link">Edit</span> | <span id="delete-link">Delete</span></div> : <div className="right" onClick={this.handleViewMenu}><span id="read-link">Read</span> | <span id="delete-link">Delete</span></div>}
{this.state.viewState === 'read' ? <div className="right" onClick={this.handleViewMenu}><span id="edit-link">Edit</span> | <span id="delete-link" onClick={this.handleViewMenu}>Delete</span></div> : <div className="right" onClick={this.handleViewMenu}><span id="read-link">Read</span> | <span id="delete-link" onClick={this.handleViewMenu}>Delete</span></div>}
{this.state.viewState === 'edit' ? <Button className="button" onClick={this.handleSaveButton}>Save List</Button> : null}
{this.state.viewState === 'read' ? questionsList : this.renderEditQuestions()}
{this.state.viewState === 'edit' ? <Button className="button" onClick={this.handleSaveButton}>Save List</Button> : null}
Expand All @@ -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({
Expand Down Expand Up @@ -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 {}
Expand Down

0 comments on commit edff5ac

Please sign in to comment.