JengaPanel.jsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react'
  2. import uiStores from 'stores/ui'
  3. import JengaExtra from '../extra/JengaExtra'
  4. import JengaItem from './JengaItem'
  5. const minWidth = 858 // 最小宽度
  6. export default class JengaPanel extends React.Component {
  7. constructor(props) {
  8. super(props)
  9. this.jengaContent = React.createRef()
  10. this.onUiChange = this.onUiChange.bind(this)
  11. this.setWidth = this.setWidth.bind(this)
  12. }
  13. componentDidMount() {
  14. this.setWidth(uiStores.jengaViewWidthDelta)
  15. this.unsubscribe = uiStores.listen(this.onUiChange)
  16. }
  17. componentWillUnmount() {
  18. this.unsubscribe()
  19. }
  20. onUiChange(status) {
  21. if (status && status.types) {
  22. if (status.types.includes('changeJengaViewWidthDelta')) {
  23. this.setWidth(status.data.jengaViewWidthDelta)
  24. }
  25. }
  26. }
  27. setWidth(delta) {
  28. if (this.jengaContent && this.jengaContent.current) {
  29. this.jengaContent.current.style.width = minWidth + delta + 'px'
  30. }
  31. }
  32. render() {
  33. return (
  34. <div className="jenga-panel scroll-hide-bar">
  35. {this.props.curEventNodeList ? undefined : <JengaExtra />}
  36. <div className="jenga-content" ref={this.jengaContent}>
  37. {this.props.curEventNodeList ? (
  38. this.props.curEventNodeList.map((nodeId, index) => {
  39. let visibleBlockIds = this.props.filterBlockIdsMap
  40. ? this.props.filterBlockIdsMap[nodeId] || []
  41. : undefined
  42. return (
  43. <JengaItem
  44. key={index}
  45. eventNodeId={nodeId}
  46. visibleBlockIds={visibleBlockIds}
  47. />
  48. )
  49. })
  50. ) : (
  51. <JengaItem />
  52. )}
  53. </div>
  54. </div>
  55. )
  56. }
  57. }