JengaNavMemo.jsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from 'react'
  2. import cls from 'classnames'
  3. import i18n from 'i18next'
  4. import newEventActions from 'actions/newEvent'
  5. import newEventStores from 'stores/newEvent'
  6. export default class JengaNavMemo extends React.Component {
  7. constructor(props) {
  8. super(props)
  9. this.state = {
  10. expanded: newEventStores.showMemo
  11. }
  12. this.onEventChange = this.onEventChange.bind(this)
  13. this.onToggleMemo = this.onToggleMemo.bind(this)
  14. }
  15. componentDidMount() {
  16. this.unsubscribe = newEventStores.listen(this.onEventChange)
  17. }
  18. componentWillUnmount() {
  19. this.unsubscribe()
  20. }
  21. onEventChange(status) {
  22. let obj = {}
  23. if (status && status.types) {
  24. if (status.types.includes('showMemo')) {
  25. if (this.state.expanded !== status.data.showMemo) {
  26. obj.expanded = status.data.showMemo
  27. }
  28. }
  29. }
  30. if (Object.keys(obj).length > 0) {
  31. this.setState(obj)
  32. }
  33. }
  34. onToggleMemo() {
  35. newEventActions.toggleMemo({})
  36. }
  37. render() {
  38. return (
  39. <div className={cls('jenga-nav-memo', { expanded: this.state.expanded })}>
  40. <button
  41. className="btn-clear btn-toggle-memo f--hcc"
  42. onClick={this.onToggleMemo}
  43. >
  44. <div className="icon" />
  45. <div className="title">{i18n.t('EventView.jenga_nav.memo')}</div>
  46. </button>
  47. </div>
  48. )
  49. }
  50. }