index.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from 'react'
  2. import newEventStores from 'stores/newEvent'
  3. import uiStores from 'stores/ui'
  4. import cls from 'classnames'
  5. import EventCodeJenga from './coms/EventJenga'
  6. export default class NewEventView extends React.Component {
  7. constructor(props) {
  8. super(props)
  9. this.state = {
  10. visible: false,
  11. eventPanelMode: null,
  12. sidebarExpand: true,
  13. curEventNodeList: newEventStores.curEventNodeList,
  14. filterBlockIdsMap: newEventStores.filterBlockIdsMap
  15. }
  16. this.onEventChange = this.onEventChange.bind(this)
  17. this.onUIChange = this.onUIChange.bind(this)
  18. }
  19. componentDidMount() {
  20. this.unsubscribeEvent = newEventStores.listen(this.onEventChange)
  21. this.unUISubscribe = uiStores.listen(this.onUIChange)
  22. }
  23. componentWillUnmount() {
  24. this.unsubscribeEvent()
  25. this.unUISubscribe()
  26. }
  27. onEventChange(status) {
  28. let obj = {}
  29. if (status.data && status.data.showEventView !== undefined) {
  30. if (this.state.visible !== status.data.showEventView) {
  31. obj.visible = status.data.showEventView
  32. }
  33. if (this.state.eventPanelMode !== status.data.eventPanelMode) {
  34. obj.eventPanelMode = status.data.eventPanelMode
  35. }
  36. if (this.state.curEventNodeList !== status.data.curEventNodeList) {
  37. obj.curEventNodeList = status.data.curEventNodeList
  38. }
  39. if (this.state.filterBlockIdsMap !== status.data.filterBlockIdsMap) {
  40. obj.filterBlockIdsMap = status.data.filterBlockIdsMap
  41. }
  42. }
  43. if (Object.keys(obj).length > 0) {
  44. this.setState(obj)
  45. }
  46. }
  47. onUIChange(status) {
  48. let obj = {}
  49. if (status.types) {
  50. if (status.types.includes('sidebarToggle')) {
  51. if (this.state.sidebarExpand !== status.data.sidebarExpand) {
  52. obj.sidebarExpand = status.data.sidebarExpand
  53. }
  54. }
  55. }
  56. if (Object.keys(obj).length > 0) {
  57. this.setState(obj)
  58. }
  59. }
  60. render() {
  61. let {
  62. visible,
  63. eventPanelMode,
  64. sidebarExpand,
  65. curEventNodeList,
  66. filterBlockIdsMap
  67. } = this.state
  68. return visible && eventPanelMode ? (
  69. <div
  70. className={cls('event-view jenga-mode', {
  71. 'sidebar-collapse': !sidebarExpand
  72. })}
  73. >
  74. {eventPanelMode === 'citedJengas' ? (
  75. <EventCodeJenga
  76. curEventNodeList={curEventNodeList}
  77. filterBlockIdsMap={filterBlockIdsMap}
  78. />
  79. ) : eventPanelMode === 'jenga' ? (
  80. <EventCodeJenga />
  81. ) : null}
  82. </div>
  83. ) : null
  84. }
  85. }