Giter Club home page Giter Club logo

bag-it-up's People

Stargazers

 avatar

Watchers

 avatar

Forkers

ginabenavidez

bag-it-up's Issues

you're not calling this function properly

Calls for two parameters
ShoppingLists.js

toggleItems(key, marketClicked){ //line 26
    const properties = [];
    this.itemsListedRef.on("value", function(snapshot) {
      var marketObj = snapshot.val();
      var keysInMarketObj = Object.keys(marketObj);
      for(var i in keysInMarketObj){
        for(var j in marketObj[keysInMarketObj[i]]){
          if (marketObj[keysInMarketObj[i]].name ===  marketClicked ){
            properties.push(marketObj[keysInMarketObj[i]][j].itemName);
            // this.setState({listedItems: properties} );
          }
        }
      }
    }, function (errorObject) {
      console.log("The read failed: " + errorObject.code);
    });
    this.setState({listedItems: properties} );
  }

Being called in ShoppingList on line 14 with no params:

  onClick(key, marketName){
    this.setState({childVisible: !this.state.childVisible});
    this.props.toggleItems();
    // this.setState({itemsToggled: !this.state.itemsToggled});
  }

Please add them so your application will know which market/shopping list you are referring to

Lets add a conditional in ShoppingList.js to improve UI.

class ShoppingList extends Component {
  constructor(props){
    super(props);
    this.state = {
      childVisible: false
    }
  }
/* Add conditional for listed items that also belong to the correct store to prevent unwanted items appearing under the wrong merchant */

  onClick(key, marketName){
    this.setState({childVisible: !this.state.childVisible});
    this.props.toggleItems();
  }

  render () {
    const { name, user, handleDelete, appendTo } = this.props;
    return ( 
      <article>
        <h3>{ name }</h3>
        <button onClick={ handleDelete }> Delete </button>
        <button onClick={()=> this.onClick()}> Select </button>
        {
          this.state.childVisible ?
            <ShowItems  user={this.props.user} 
                        appendTo={appendTo}
                        content={this.props.content}
            />
          : <span></span>
        }
      </article>
    );
  }
}

Don't add undefined to properties array.

toggleItems(key, marketClicked){
    const properties = [];
    this.itemsListedRef.on("value", function(snapshot) {
      var marketObj = snapshot.val();
      var keysInMarketObj = Object.keys(marketObj);
      for (var i in keysInMarketObj){
        for (var j in marketObj[keysInMarketObj[i]]){
          if (marketObj[keysInMarketObj[i]].name ===  marketClicked){
            // add a conditional or something. 
            properties.push(marketObj[keysInMarketObj[i]][j].itemName);
            // this.setState({listedItems: properties} );
          }          
        }
      }
    }, function (errorObject) {
      console.log("The read failed: " + errorObject.code);
    });
    this.setState({listedItems: properties} );
  }

Why are you pushing an undefined element into properties?

Let's figure out this bug in application.js

   render () {
    const { shoppingListsRef, user } = this.props;
    return (
      <section>
          { map(shoppingListsRef, (shoppingList, key) => (
            <ShoppingList key={key} name={shoppingList.name} user={user} {...shoppingList}      
              handleDelete={ () => this.handleDelete(key)}
            />
          )) }
      </section>
    );
  }

Why is name undefined?

React red warning -- need to research

line 46 in ShoppingList.js

      <section>
        {map(shoppingLists, (shoppingList, key) => (        
          <ShoppingList key={key} 
                        appendTo={key} 
                        user={user}
                        content={this.state.listedItems}
                        toggleItems={ () => this.toggleItems(key,shoppingList.name)}
                        handleDelete={ () => this.handleDelete(key)}
                        {...shoppingList}
          />
        ))}
      </section>

You can't open multiple lists at the same time.

Each time we press the button that triggers clicked() as seen in ShoppingList.js on line 26:

  render () {
    const { name, user, handleDelete, appendTo } = this.props;
    return ( 
      <article>
        <h3>{ name }</h3>
        <button onClick={ handleDelete }> Delete </button>
        <button onClick={()=> this.clicked(appendTo, name)}> Select </button>
        {
          this.state.childVisible ?
            <ShowItems  user={this.props.user} 
                        appendTo={appendTo}
                        content={this.props.content}
            />
          : <span></span>
        }
      </article>
    );
  }

The function toggles the show/hide state of the element.
And I'm not 100% sure of the toggleItems method.... let's look deeper into this...

  clicked(key, marketName){
    this.setState({childVisible: !this.state.childVisible}); /* We need to only toggle for the specific element with the same id as the item being clicked. */
    this.props.toggleItems(key, marketName);
    // this.setState({itemsToggled: !this.state.itemsToggled});
  }

The end functionality is a bug in the UI that manipulates the previous lists that are opened if multiple lists are selected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.