yohei0125 3 лет назад
Родитель
Сommit
8bb5fa9a7a

+ 34 - 3
packages/app/src/components/PageAlert/PageStaleAlert.tsx

@@ -1,9 +1,40 @@
 
 
 import { useIsEnabledStaleNotification } from '../../stores/context'
 import { useIsEnabledStaleNotification } from '../../stores/context'
+import { useSWRxCurrentPage, useSWRxPageInfo } from '../../stores/page'
+import { useTranslation } from 'react-i18next';
+
+
+export const PageStaleAlert = ():JSX.Element => {
+  const { t } = useTranslation()
+  const { data: isEnabledStaleNotification } = useIsEnabledStaleNotification();
+  const { data: pageData } = useSWRxCurrentPage();
+  const { data: pageInfo } = useSWRxPageInfo(pageData?._id);
+  const contentAge = pageInfo?.contentAge;
+
+  if (!isEnabledStaleNotification) {
+    return <></>
+  }
+
+  if( pageInfo == null || contentAge == null || contentAge === 0) {
+    return <></>
+  }
+
+  let alertClass;
+  switch (pageInfo.contentAge) {
+    case 1:
+      alertClass = "alert-info";
+      break;
+    case 2:
+      alertClass = "alert-warning";
+      break;
+    default:
+      alertClass = "alert-danger";
+  }
 
 
-export const PageStaleAlert = (props):JSX.Element => {
-const { data: isEnabledStaleNotification } = useIsEnabledStaleNotification()
   return (
   return (
-    <>PageStaleAlert</>
+    <div className={`alert ${alertClass}`}>
+      <i className="icon-fw icon-hourglass"></i>
+      <strong>{ t('page_page.notice.stale', { count: pageInfo.contentAge }) }</strong>
+    </div>
   )
   )
 }
 }

+ 1 - 0
packages/app/src/interfaces/page.ts

@@ -53,6 +53,7 @@ export type IPageInfo = {
   isDeletable: boolean,
   isDeletable: boolean,
   isAbleToDeleteCompletely: boolean,
   isAbleToDeleteCompletely: boolean,
   isRevertible: boolean,
   isRevertible: boolean,
+  contentAge?: number,
 }
 }
 
 
 export type IPageInfoForEntity = IPageInfo & {
 export type IPageInfoForEntity = IPageInfo & {

+ 2 - 1
packages/app/src/server/service/page.ts

@@ -2176,7 +2176,7 @@ class PageService {
     });
     });
   }
   }
 
 
-  constructBasicPageInfo(page: IPage, isGuestUser?: boolean): IPageInfo | IPageInfoForEntity {
+  constructBasicPageInfo(page: PageDocument, isGuestUser?: boolean): IPageInfo | IPageInfoForEntity {
     const isMovable = isGuestUser ? false : isMovablePage(page.path);
     const isMovable = isGuestUser ? false : isMovablePage(page.path);
 
 
     if (page.isEmpty) {
     if (page.isEmpty) {
@@ -2204,6 +2204,7 @@ class PageService {
       isDeletable: isMovable,
       isDeletable: isMovable,
       isAbleToDeleteCompletely: false,
       isAbleToDeleteCompletely: false,
       isRevertible: isTrashPage(page.path),
       isRevertible: isTrashPage(page.path),
+      contentAge: page.getContentAge(),
     };
     };
 
 
   }
   }