yohei0125 4 лет назад
Родитель
Сommit
389916e493

+ 27 - 5
packages/app/src/components/IdenticalPathPage.tsx

@@ -1,16 +1,38 @@
-import React, { FC } from 'react';
+import React, {
+  FC,
+} from 'react';
+
+import { withUnstatedContainers } from './UnstatedUtils';
+import AppContainer from '~/client/services/AppContainer';
+import PageListItem from './Page/PageListItem';
 
 type IdenticalPathPageProps= {
   // add props and types here
 }
+const jsonNull = 'null';
+
 const IdenticalPathPage:FC<IdenticalPathPageProps> = (props:IdenticalPathPageProps) => {
+  const identicalPageDocument = document.getElementById('identical-path-page-list');
+  const pageDataList = JSON.parse(identicalPageDocument?.getAttribute('data-identical-page-data-list') || jsonNull);
+  const shortbodyMap = JSON.parse(identicalPageDocument?.getAttribute('data-shortody-map') || jsonNull);
+
   return (
-    <div>
+    <div className="list-group">
       {/* Todo: show alert */}
-      {/* Todo: show identical path page list */}
-      IdenticalPathPageList
+      {pageDataList.map((data) => {
+        return (
+          <PageListItem
+            key={data.pageData._id}
+            page={data} // need this to have valid userpicture
+            isSelected={false}
+            isChecked={false}
+            isEnableActions={false}
+            shortBody={shortbodyMap[data.pageData._id]}
+          />
+        );
+      })}
     </div>
   );
 };
 
-export default IdenticalPathPage;
+export default withUnstatedContainers(IdenticalPathPage, [AppContainer]);

+ 14 - 1
packages/app/src/server/routes/page.js

@@ -142,6 +142,7 @@ module.exports = function(crowi, app) {
 
   const Page = crowi.model('Page');
   const User = crowi.model('User');
+  const Bookmark = crowi.model('Bookmark');
   const PageTagRelation = crowi.model('PageTagRelation');
   const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
   const ShareLink = crowi.model('ShareLink');
@@ -613,8 +614,20 @@ module.exports = function(crowi, app) {
     const { redirectFrom } = req.query;
 
     if (pages.length >= 2) {
+
+      const pageIds = pages.map(p => p._id);
+      const shortBodyMap = await crowi.pageService.shortBodiesMapByPageIds(pageIds);
+      const identicalPageDataList = await Promise.all(pages.map(async(page) => {
+        const bookmarkCount = await Bookmark.countByPageId(page._id);
+        return {
+          pageData: page,
+          pageMeta: {
+            bookmarkCount,
+          },
+        };
+      }));
       return res.render('layout-growi/identical-path-page-list', {
-        pages, redirectFrom,
+        identicalPageDataList, shortBodyMap, redirectFrom,
       });
     }
 

+ 6 - 1
packages/app/src/server/views/layout-growi/identical-path-page-list.html

@@ -2,5 +2,10 @@
 
 {% block content_main %}
 <div id="grw-fav-sticky-trigger" class="sticky-top"></div>
-<div id="identical-path-page-list"></div>
+<div
+  id="identical-path-page-list"
+  data-identical-page-data-list="{{ identicalPageDataList|json }}"
+  data-shortody-map="{{ shortBodyMap|json }}"
+>
+</div>
 {% endblock %}