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.

127 lines
3.5 KiB

  1. // Package imports.
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { defineMessages } from 'react-intl';
  6. import { Link } from 'react-router-dom';
  7. // Components.
  8. import Icon from 'flavours/glitch/components/icon';
  9. // Utils.
  10. import { conditionalRender } from 'flavours/glitch/util/react_helpers';
  11. import { signOutLink } from 'flavours/glitch/util/backend_links';
  12. // Messages.
  13. const messages = defineMessages({
  14. community: {
  15. defaultMessage: 'Local timeline',
  16. id: 'navigation_bar.community_timeline',
  17. },
  18. home_timeline: {
  19. defaultMessage: 'Home',
  20. id: 'tabs_bar.home',
  21. },
  22. logout: {
  23. defaultMessage: 'Logout',
  24. id: 'navigation_bar.logout',
  25. },
  26. notifications: {
  27. defaultMessage: 'Notifications',
  28. id: 'tabs_bar.notifications',
  29. },
  30. public: {
  31. defaultMessage: 'Federated timeline',
  32. id: 'navigation_bar.public_timeline',
  33. },
  34. settings: {
  35. defaultMessage: 'App settings',
  36. id: 'navigation_bar.app_settings',
  37. },
  38. start: {
  39. defaultMessage: 'Getting started',
  40. id: 'getting_started.heading',
  41. },
  42. });
  43. // The component.
  44. export default function DrawerHeader ({
  45. columns,
  46. unreadNotifications,
  47. showNotificationsBadge,
  48. intl,
  49. onSettingsClick,
  50. }) {
  51. // Only renders the component if the column isn't being shown.
  52. const renderForColumn = conditionalRender.bind(null,
  53. columnId => !columns || !columns.some(
  54. column => column.get('id') === columnId
  55. )
  56. );
  57. // The result.
  58. return (
  59. <nav className='drawer--header'>
  60. <Link
  61. aria-label={intl.formatMessage(messages.start)}
  62. title={intl.formatMessage(messages.start)}
  63. to='/getting-started'
  64. ><Icon icon='asterisk' /></Link>
  65. {renderForColumn('HOME', (
  66. <Link
  67. aria-label={intl.formatMessage(messages.home_timeline)}
  68. title={intl.formatMessage(messages.home_timeline)}
  69. to='/timelines/home'
  70. ><Icon icon='home' /></Link>
  71. ))}
  72. {renderForColumn('NOTIFICATIONS', (
  73. <Link
  74. aria-label={intl.formatMessage(messages.notifications)}
  75. title={intl.formatMessage(messages.notifications)}
  76. to='/notifications'
  77. >
  78. <span className='icon-badge-wrapper'>
  79. <Icon icon='bell' />
  80. { showNotificationsBadge && unreadNotifications > 0 && <div className='icon-badge' />}
  81. </span>
  82. </Link>
  83. ))}
  84. {renderForColumn('COMMUNITY', (
  85. <Link
  86. aria-label={intl.formatMessage(messages.community)}
  87. title={intl.formatMessage(messages.community)}
  88. to='/timelines/public/local'
  89. ><Icon icon='users' /></Link>
  90. ))}
  91. {renderForColumn('PUBLIC', (
  92. <Link
  93. aria-label={intl.formatMessage(messages.public)}
  94. title={intl.formatMessage(messages.public)}
  95. to='/timelines/public'
  96. ><Icon icon='globe' /></Link>
  97. ))}
  98. <a
  99. aria-label={intl.formatMessage(messages.settings)}
  100. onClick={onSettingsClick}
  101. href='#'
  102. title={intl.formatMessage(messages.settings)}
  103. ><Icon icon='cogs' /></a>
  104. <a
  105. aria-label={intl.formatMessage(messages.logout)}
  106. data-method='delete'
  107. href={ signOutLink }
  108. title={intl.formatMessage(messages.logout)}
  109. ><Icon icon='sign-out' /></a>
  110. </nav>
  111. );
  112. }
  113. // Props.
  114. DrawerHeader.propTypes = {
  115. columns: ImmutablePropTypes.list,
  116. unreadNotifications: PropTypes.number,
  117. showNotificationsBadge: PropTypes.bool,
  118. intl: PropTypes.object,
  119. onSettingsClick: PropTypes.func,
  120. };