PageStaleAlert.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { useIsEnabledStaleNotification } from '../../stores/context'
  2. import { useSWRxCurrentPage, useSWRxPageInfo } from '../../stores/page'
  3. import { useTranslation } from 'react-i18next';
  4. export const PageStaleAlert = ():JSX.Element => {
  5. const { t } = useTranslation()
  6. const { data: isEnabledStaleNotification } = useIsEnabledStaleNotification();
  7. const { data: pageData } = useSWRxCurrentPage();
  8. const { data: pageInfo } = useSWRxPageInfo(pageData?._id);
  9. const contentAge = pageInfo?.contentAge;
  10. if (!isEnabledStaleNotification) {
  11. return <></>
  12. }
  13. if( pageInfo == null || contentAge == null || contentAge === 0) {
  14. return <></>
  15. }
  16. let alertClass;
  17. switch (contentAge) {
  18. case 1:
  19. alertClass = "alert-info";
  20. break;
  21. case 2:
  22. alertClass = "alert-warning";
  23. break;
  24. default:
  25. alertClass = "alert-danger";
  26. }
  27. return (
  28. <div className={`alert ${alertClass}`}>
  29. <i className="icon-fw icon-hourglass"></i>
  30. <strong>{ t('page_page.notice.stale', { count: pageInfo.contentAge }) }</strong>
  31. </div>
  32. )
  33. }