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.

115 lines
3.1 KiB

  1. // Package imports.
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import {
  6. FormattedMessage,
  7. defineMessages,
  8. } from 'react-intl';
  9. import spring from 'react-motion/lib/spring';
  10. import { Link } from 'react-router-dom';
  11. // Components.
  12. import AccountContainer from 'flavours/glitch/containers/account_container';
  13. import StatusContainer from 'flavours/glitch/containers/status_container';
  14. import Hashtag from 'flavours/glitch/components/hashtag';
  15. // Utils.
  16. import Motion from 'flavours/glitch/util/optional_motion';
  17. // Messages.
  18. const messages = defineMessages({
  19. total: {
  20. defaultMessage: '{count, number} {count, plural, one {result} other {results}}',
  21. id: 'search_results.total',
  22. },
  23. });
  24. // The component.
  25. export default function DrawerResults ({
  26. results,
  27. visible,
  28. }) {
  29. const accounts = results ? results.get('accounts') : null;
  30. const statuses = results ? results.get('statuses') : null;
  31. const hashtags = results ? results.get('hashtags') : null;
  32. // This gets the total number of items.
  33. const count = [accounts, statuses, hashtags].reduce(function (size, item) {
  34. if (item && item.size) {
  35. return size + item.size;
  36. }
  37. return size;
  38. }, 0);
  39. // The result.
  40. return (
  41. <Motion
  42. defaultStyle={{ x: -100 }}
  43. style={{
  44. x: spring(visible ? 0 : -100, {
  45. stiffness: 210,
  46. damping: 20,
  47. }),
  48. }}
  49. >
  50. {({ x }) => (
  51. <div
  52. className='drawer--results'
  53. style={{
  54. transform: `translateX(${x}%)`,
  55. visibility: x === -100 ? 'hidden' : 'visible',
  56. }}
  57. >
  58. <header>
  59. <FormattedMessage
  60. {...messages.total}
  61. values={{ count }}
  62. />
  63. </header>
  64. {accounts && accounts.size ? (
  65. <section>
  66. <h5><FormattedMessage id='search_results.accounts' defaultMessage='People' /></h5>
  67. {accounts.map(
  68. accountId => (
  69. <AccountContainer
  70. id={accountId}
  71. key={accountId}
  72. />
  73. )
  74. )}
  75. </section>
  76. ) : null}
  77. {statuses && statuses.size ? (
  78. <section>
  79. <h5><FormattedMessage id='search_results.statuses' defaultMessage='Toots' /></h5>
  80. {statuses.map(
  81. statusId => (
  82. <StatusContainer
  83. id={statusId}
  84. key={statusId}
  85. />
  86. )
  87. )}
  88. </section>
  89. ) : null}
  90. {hashtags && hashtags.size ? (
  91. <section>
  92. <h5><FormattedMessage id='search_results.hashtags' defaultMessage='Hashtags' /></h5>
  93. {hashtags.map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}
  94. </section>
  95. ) : null}
  96. </div>
  97. )}
  98. </Motion>
  99. );
  100. }
  101. // Props.
  102. DrawerResults.propTypes = {
  103. results: ImmutablePropTypes.map,
  104. visible: PropTypes.bool,
  105. };