AllInAppNotifications.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { FC, useState, useEffect } from 'react';
  2. import AppContainer from '../../client/services/AppContainer';
  3. import loggerFactory from '~/utils/logger';
  4. import InAppNotificationList from './InAppNotificationList';
  5. import { withUnstatedContainers } from '../UnstatedUtils';
  6. import { useSWRxInAppNotifications } from '../../stores/in-app-notification';
  7. const logger = loggerFactory('growi:ALlInAppnotification');
  8. type Props = {
  9. appContainer: AppContainer,
  10. };
  11. const AllInAppNotifications: FC<Props> = (props: Props) => {
  12. const { appContainer } = props;
  13. // const [notifications, setNotifications] = useState([]);
  14. const limit = 6;
  15. const { data: inAppNotificationdata, error, mutate } = useSWRxInAppNotifications(limit);
  16. console.log('useSWRxInAppNotification_notifications', inAppNotificationdata);
  17. const [isLoaded, setIsLoaded] = useState(false);
  18. useEffect(() => {
  19. fetchNotificationList();
  20. }, []);
  21. const fetchNotificationList = async() => {
  22. // const limit = 6;
  23. try {
  24. // const paginationResult = await appContainer.apiv3Get('/in-app-notification/list', { limit });
  25. // setNotifications(paginationResult.data.docs);
  26. setIsLoaded(true);
  27. }
  28. catch (err) {
  29. logger.error(err);
  30. }
  31. };
  32. if (inAppNotificationdata == null) {
  33. return (
  34. <div className="wiki">
  35. <div className="text-muted text-center">
  36. <i className="fa fa-2x fa-spinner fa-pulse mr-1"></i>
  37. </div>
  38. </div>
  39. );
  40. }
  41. const notifications = inAppNotificationdata.data.docs;
  42. console.log('notifications!!', notifications);
  43. return (
  44. <InAppNotificationList notifications={notifications} isLoaded={isLoaded} />
  45. );
  46. };
  47. /**
  48. * Wrapper component for using unstated
  49. */
  50. const AllInAppNotificationsWrapper = withUnstatedContainers(AllInAppNotifications, [AppContainer]);
  51. export default AllInAppNotificationsWrapper;