ListItem.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import React, { Component } from 'react';
  2. import Container from '../Container/Container';
  3. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  4. import './ListItem.scss';
  5. class ListItem extends Component {
  6. state = {
  7. starred: false
  8. }
  9. UNSAFE_componentWillMount() {
  10. this.setState({ starred: this.props.starred === 1 });
  11. }
  12. UNSAFE_componentWillReceiveProps(nextProps) {
  13. this.setState({
  14. starred: nextProps.starred === 1
  15. });
  16. }
  17. printDate = date => {
  18. if (date) {
  19. let newDate = new Date(date);
  20. let day = newDate.getDate();
  21. let month = newDate.getMonth() + 1;
  22. let year = newDate.getFullYear();
  23. let months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  24. return <div className="date">{day} &nbsp; {months[month - 1]} &nbsp; {year}</div>;
  25. }
  26. }
  27. toggleItem = () => {
  28. this.props.checkItem();
  29. }
  30. starItem = () => {
  31. this.setState({ starred: !this.state.starred }, () => {
  32. this.props.toggleFav(this.state.starred);
  33. });
  34. }
  35. className = () => {
  36. const { starred } = this.state;
  37. const { checked, outdated, suspended, stopped, focused, sysInfo } = this.props;
  38. let className = 'list-item';
  39. if (checked) {
  40. className += ' toggled';
  41. }
  42. if (starred) {
  43. className += ' starred';
  44. }
  45. if (outdated) {
  46. className += ' outdated';
  47. }
  48. if (suspended) {
  49. className += ' suspended';
  50. }
  51. if (stopped) {
  52. className += ' stopped';
  53. }
  54. if (focused) {
  55. className += ' focused';
  56. }
  57. if (sysInfo) {
  58. className += ' sys-info';
  59. }
  60. return className;
  61. }
  62. render() {
  63. return (
  64. <div className={this.className()} id={this.props.id}>
  65. <Container className="l-col w-14">
  66. {this.printDate(this.props.date)}
  67. <div className="text-status">
  68. <div className="checkbox"><input type="checkbox" onChange={(e) => this.toggleItem(e)} checked={this.props.checked} /></div>
  69. {this.props.leftNameText}
  70. </div>
  71. <div className="star">
  72. <div className="checkbox"><input type="checkbox" onChange={(e) => this.toggleItem(e)} checked={this.props.checked} /></div>
  73. <div onClick={this.starItem}><FontAwesomeIcon icon="star" /></div>
  74. </div>
  75. {this.props.suspended && <div className='suspended'>{window.GLOBAL.App.i18n.suspended}</div>}
  76. </Container>
  77. {this.props.children}
  78. </div>
  79. );
  80. }
  81. }
  82. export default ListItem;