var React = require('react'); var _ = require('lodash'); var cx = require('classnames'); var Moment = require('moment'); var Nav = require('naturalcrit/nav/nav.jsx'); const VIEW_KEY = 'homebrewery-recently-viewed'; const EDIT_KEY = 'homebrewery-recently-edited'; var BaseItem = React.createClass({ getDefaultProps: function() { return { storageKey : '', text : '', currentBrew:{ title : '', id : '', url : '' } }; }, getInitialState: function() { return { showDropdown: false, brews : [] }; }, componentDidMount: function() { var brews = JSON.parse(localStorage.getItem(this.props.storageKey) || '[]'); brews = _.filter(brews, (brew)=>{ return brew.id !== this.props.currentBrew.id; }); if(this.props.currentBrew.id){ brews.unshift({ id : this.props.currentBrew.id, url : this.props.currentBrew.url, title : this.props.currentBrew.title, ts : Date.now() }); } brews = _.slice(brews, 0, 8); localStorage.setItem(this.props.storageKey, JSON.stringify(brews)); this.setState({ brews : brews }); }, handleDropdown : function(show){ this.setState({ showDropdown : show }) }, renderDropdown : function(){ if(!this.state.showDropdown) return null; var items = _.map(this.state.brews, (brew)=>{ return {brew.title} {Moment(brew.ts).fromNow()} }); return