InAppNotificationDropdown.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import React from 'react';
  2. import { Dropdown, DropdownToggle, DropdownMenu } from 'reactstrap';
  3. // import DropdownMenu from './InAppNotificationDropdown/DropdownMenu';
  4. // import Icon from './Common/Icon'
  5. // import Crowi from 'client/util/Crowi'
  6. // import { Notification } from 'client/types/crowi'
  7. interface Props {
  8. // crowi: Crowi
  9. me: string
  10. }
  11. interface State {
  12. count: number
  13. loaded: boolean
  14. notifications: Notification[]
  15. open: boolean
  16. }
  17. export default class InAppNotificationDropdown extends React.Component<Props, State> {
  18. constructor(props: Props) {
  19. super(props);
  20. this.state = {
  21. count: 0,
  22. loaded: false,
  23. notifications: [],
  24. open: false,
  25. };
  26. }
  27. // componentDidMount() {
  28. // this.initializeSocket();
  29. // this.fetchList();
  30. // this.fetchStatus();
  31. // }
  32. // initializeSocket() {
  33. // this.props.crowi.getWebSocket().on('notification updated', (data: { user: string }) => {
  34. // if (this.props.me === data.user) {
  35. // this.fetchList();
  36. // this.fetchStatus();
  37. // }
  38. // });
  39. // }
  40. // async fetchStatus() {
  41. // try {
  42. // const { count = null } = await this.props.crowi.apiGet('/notification.status');
  43. // if (count !== null && count !== this.state.count) {
  44. // this.setState({ count });
  45. // }
  46. // }
  47. // catch (err) {
  48. // // TODO: error handling
  49. // }
  50. // }
  51. async updateStatus() {
  52. try {
  53. // await this.props.crowi.apiPost('/notification.read');
  54. this.setState({ count: 0 });
  55. }
  56. catch (err) {
  57. // TODO: error handling
  58. }
  59. }
  60. // async fetchList() {
  61. // const limit = 6;
  62. // try {
  63. // const { notifications } = await this.props.crowi.apiGet('/notification.list', { limit });
  64. // this.setState({ loaded: true, notifications });
  65. // }
  66. // catch (err) {
  67. // // TODO: error handling
  68. // }
  69. // }
  70. toggle() {
  71. const { open, count } = this.state;
  72. if (!open && count > 0) {
  73. this.updateStatus();
  74. }
  75. this.setState({ open: !open });
  76. }
  77. // async handleNotificationOnClick(notification: Notification) {
  78. // try {
  79. // await this.props.crowi.apiPost('/notification.open', { id: notification._id });
  80. // // jump to target page
  81. // window.location.href = notification.target.path;
  82. // }
  83. // catch (err) {
  84. // // TODO: error handling
  85. // }
  86. // }
  87. render() {
  88. const {
  89. count, open, loaded, notifications,
  90. } = this.state;
  91. const badge = count > 0 ? <span className="badge badge-pill badge-danger notification-badge">{count}</span> : '';
  92. return (
  93. <Dropdown className="notification-wrapper" isOpen={open} toggle={this.toggle}>
  94. <DropdownToggle tag="a" className="nav-link">
  95. <i className="icon-bell mr-2"></i>
  96. {/* {badge} */}
  97. </DropdownToggle>
  98. <DropdownMenu>hoge</DropdownMenu>
  99. </Dropdown>
  100. );
  101. }
  102. }