import React, { Component } from 'react'; import { Link } from 'react-router-dom'; import Interactive from 'react-interactive'; import sidebarCSS from '../styles/adminSidebar.jsx' class SidebarComponent extends Component { constructor(props){ super(props) // Constructor with states holding the search query and the element of reponse. this.state = { filterValue: '', filterQuery: '', requestItemsToBeDisplayed: [], listItemSelected: '', height: '0', } this.updateWindowDimensions = this.updateWindowDimensions.bind(this); } // Where we wait for api response to be delivered from parent through props componentWillReceiveProps(props) { this.state.listItemSelected = props.listItemSelected; this.displayRequestedElementsInfo(props.requested_objects); } componentDidMount() { this.updateWindowDimensions(); window.addEventListener('resize', this.updateWindowDimensions); } componentWillUnmount() { window.removeEventListener('resize', this.updateWindowDimensions); } updateWindowDimensions() { this.setState({ height: window.innerHeight }); } // Inputs a date and returns a text string that matches how long it was since convertDateToDaysSince(date) { var oneDay = 24*60*60*1000; var firstDate = new Date(date); var secondDate = new Date(); var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime()) / oneDay)); switch (diffDays) { case 0: return 'Today'; case 1: return '1 day ago' default: return diffDays + ' days ago' } } // Called from our dropdown, receives a filter string and checks it with status field // of our request objects. filterItems(filterValue) { let filteredRequestElements = this.props.requested_objects.map((item, index) => { if (item.status === filterValue || filterValue === 'all') return this.generateListElements(index, item); }) this.setState({ requestItemsToBeDisplayed: filteredRequestElements, filterValue: filterValue, }) } // Updates the internal state of the query filter and updates the list to only // display names matching the query. This is real-time filtering. updateFilterQuery(event) { const query = event.target.value; let filteredByQuery = this.props.requested_objects.map((item, index) => { if (item.title.toLowerCase().indexOf(query.toLowerCase()) != -1) return this.generateListElements(index, item); }) this.setState({ requestItemsToBeDisplayed: filteredByQuery, filterQuery: query, }); } generateFilterSearch() { return (
Requested: