InAppNotificationList.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React, { FC } from 'react';
  2. import { IInAppNotification } from '../../interfaces/in-app-notification';
  3. import { InAppNotification } from './InAppNotification';
  4. type Props = {
  5. notifications: Array<IInAppNotification>;
  6. isLoaded: boolean;
  7. };
  8. const InAppNotificationList: FC<Props> = (props: Props) => {
  9. const { notifications } = props;
  10. const notificationClickHandler = async(notification: Notification) => {
  11. try {
  12. // await this.props.crowi.apiPost('/notification.open', { id: notification._id });
  13. // jump to target page
  14. // window.location.href = notification.target.path;
  15. }
  16. catch (err) {
  17. // logger.error(err);
  18. }
  19. };
  20. // TODO: improve view of loading icon by #80669
  21. const RenderUnLoadedInAppNotification = (): JSX.Element => {
  22. return (
  23. <i className="fa fa-spinner"></i>
  24. );
  25. };
  26. const RenderEmptyInAppNotification = (): JSX.Element => {
  27. return (
  28. // TODO: apply i18n by #78569
  29. <>You had no notifications, yet.</>
  30. );
  31. };
  32. const RenderInAppNotificationList = () => {
  33. if (notifications.length === 0) {
  34. return <RenderEmptyInAppNotification />;
  35. }
  36. const notificationList = notifications.map((notification: IInAppNotification) => {
  37. return (
  38. <div className="d-flex flex-row" key={notification._id}>
  39. <InAppNotification notification={notification} onClick={notificationClickHandler} />
  40. </div>
  41. );
  42. });
  43. return <>{notificationList}</>;
  44. };
  45. if (!props.isLoaded) {
  46. return <RenderUnLoadedInAppNotification />;
  47. }
  48. return <RenderInAppNotificationList />;
  49. };
  50. export default InAppNotificationList;