You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.4 KiB

  1. // Package imports.
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import classNames from 'classnames';
  6. // Actions.
  7. import { openModal } from 'flavours/glitch/actions/modal';
  8. import {
  9. changeSearch,
  10. clearSearch,
  11. showSearch,
  12. submitSearch,
  13. } from 'flavours/glitch/actions/search';
  14. import { cycleElefriendCompose } from 'flavours/glitch/actions/compose';
  15. // Components.
  16. import Composer from 'flavours/glitch/features/composer';
  17. import DrawerAccount from './account';
  18. import DrawerHeader from './header';
  19. import DrawerResults from './results';
  20. import DrawerSearch from './search';
  21. // Utils.
  22. import { me } from 'flavours/glitch/util/initial_state';
  23. import { wrap } from 'flavours/glitch/util/redux_helpers';
  24. // State mapping.
  25. const mapStateToProps = state => ({
  26. account: state.getIn(['accounts', me]),
  27. columns: state.getIn(['settings', 'columns']),
  28. elefriend: state.getIn(['compose', 'elefriend']),
  29. results: state.getIn(['search', 'results']),
  30. searchHidden: state.getIn(['search', 'hidden']),
  31. searchValue: state.getIn(['search', 'value']),
  32. submitted: state.getIn(['search', 'submitted']),
  33. });
  34. // Dispatch mapping.
  35. const mapDispatchToProps = {
  36. onChange: changeSearch,
  37. onClear: clearSearch,
  38. onClickElefriend: cycleElefriendCompose,
  39. onShow: showSearch,
  40. onSubmit: submitSearch,
  41. onOpenSettings: openModal.bind(null, 'SETTINGS', {}),
  42. };
  43. // The component.
  44. class Drawer extends React.Component {
  45. // Constructor.
  46. constructor (props) {
  47. super(props);
  48. }
  49. // Rendering.
  50. render () {
  51. const {
  52. account,
  53. columns,
  54. elefriend,
  55. intl,
  56. multiColumn,
  57. onChange,
  58. onClear,
  59. onClickElefriend,
  60. onOpenSettings,
  61. onShow,
  62. onSubmit,
  63. results,
  64. searchHidden,
  65. searchValue,
  66. submitted,
  67. } = this.props;
  68. const computedClass = classNames('drawer', `mbstobon-${elefriend}`);
  69. // The result.
  70. return (
  71. <div className={computedClass}>
  72. {multiColumn ? (
  73. <DrawerHeader
  74. columns={columns}
  75. intl={intl}
  76. onSettingsClick={onOpenSettings}
  77. />
  78. ) : null}
  79. <DrawerSearch
  80. intl={intl}
  81. onChange={onChange}
  82. onClear={onClear}
  83. onShow={onShow}
  84. onSubmit={onSubmit}
  85. submitted={submitted}
  86. value={searchValue}
  87. />
  88. <div className='contents'>
  89. <DrawerAccount account={account} />
  90. <Composer />
  91. {multiColumn && <button className='mastodon' onClick={onClickElefriend} />}
  92. <DrawerResults
  93. results={results}
  94. visible={submitted && !searchHidden}
  95. />
  96. </div>
  97. </div>
  98. );
  99. }
  100. }
  101. // Props.
  102. Drawer.propTypes = {
  103. intl: PropTypes.object.isRequired,
  104. multiColumn: PropTypes.bool,
  105. // State props.
  106. account: ImmutablePropTypes.map,
  107. columns: ImmutablePropTypes.list,
  108. results: ImmutablePropTypes.map,
  109. elefriend: PropTypes.number,
  110. searchHidden: PropTypes.bool,
  111. searchValue: PropTypes.string,
  112. submitted: PropTypes.bool,
  113. // Dispatch props.
  114. onChange: PropTypes.func,
  115. onClear: PropTypes.func,
  116. onClickElefriend: PropTypes.func,
  117. onShow: PropTypes.func,
  118. onSubmit: PropTypes.func,
  119. onOpenSettings: PropTypes.func,
  120. };
  121. // Connecting and export.
  122. export { Drawer as WrappedComponent };
  123. export default wrap(Drawer, mapStateToProps, mapDispatchToProps, true);