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.

116 lines
2.9 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. // Utils.
  15. import Motion from 'flavours/glitch/util/optional_motion';
  16. // Messages.
  17. const messages = defineMessages({
  18. total: {
  19. defaultMessage: '{count, number} {count, plural, one {result} other {results}}',
  20. id: 'search_results.total',
  21. },
  22. });
  23. // The component.
  24. export default function DrawerResults ({
  25. results,
  26. visible,
  27. }) {
  28. const accounts = results ? results.get('accounts') : null;
  29. const statuses = results ? results.get('statuses') : null;
  30. const hashtags = results ? results.get('hashtags') : null;
  31. // This gets the total number of items.
  32. const count = [accounts, statuses, hashtags].reduce(function (size, item) {
  33. if (item && item.size) {
  34. return size + item.size;
  35. }
  36. return size;
  37. }, 0);
  38. // The result.
  39. return (
  40. <Motion
  41. defaultStyle={{ x: -100 }}
  42. style={{
  43. x: spring(visible ? 0 : -100, {
  44. stiffness: 210,
  45. damping: 20,
  46. }),
  47. }}
  48. >
  49. {({ x }) => (
  50. <div
  51. className='drawer--results'
  52. style={{
  53. transform: `translateX(${x}%)`,
  54. visibility: x === -100 ? 'hidden' : 'visible',
  55. }}
  56. >
  57. <header>
  58. <FormattedMessage
  59. {...messages.total}
  60. values={{ count }}
  61. />
  62. </header>
  63. {accounts && accounts.size ? (
  64. <section>
  65. {accounts.map(
  66. accountId => (
  67. <AccountContainer
  68. id={accountId}
  69. key={accountId}
  70. />
  71. )
  72. )}
  73. </section>
  74. ) : null}
  75. {statuses && statuses.size ? (
  76. <section>
  77. {statuses.map(
  78. statusId => (
  79. <StatusContainer
  80. id={statusId}
  81. key={statusId}
  82. />
  83. )
  84. )}
  85. </section>
  86. ) : null}
  87. {hashtags && hashtags.size ? (
  88. <section>
  89. {hashtags.map(
  90. hashtag => (
  91. <Link
  92. className='hashtag'
  93. key={hashtag}
  94. to={`/timelines/tag/${hashtag}`}
  95. >#{hashtag}</Link>
  96. )
  97. )}
  98. </section>
  99. ) : null}
  100. </div>
  101. )}
  102. </Motion>
  103. );
  104. }
  105. // Props.
  106. DrawerResults.propTypes = {
  107. results: ImmutablePropTypes.map,
  108. visible: PropTypes.bool,
  109. };