Просмотр исходного кода

edit method for getting tag list

yusuketk 7 лет назад
Родитель
Сommit
397e1e3567
2 измененных файлов с 17 добавлено и 12 удалено
  1. 5 5
      src/client/js/components/TagsList.jsx
  2. 12 7
      src/server/routes/tag.js

+ 5 - 5
src/client/js/components/TagsList.jsx

@@ -7,14 +7,14 @@ export default class TagsList extends React.Component {
     super(props);
     super(props);
 
 
     this.state = {
     this.state = {
-      tags: [],
+      tagData: [],
     };
     };
   }
   }
 
 
   async componentWillMount() {
   async componentWillMount() {
     const res = await this.props.crowi.apiGet('/tags.list');
     const res = await this.props.crowi.apiGet('/tags.list');
     this.setState({
     this.setState({
-      tags: res.tags,
+      tagData: res.result,
     });
     });
   }
   }
 
 
@@ -22,10 +22,10 @@ export default class TagsList extends React.Component {
     return (
     return (
       <div>
       <div>
         <ul className="list-group mx-4">
         <ul className="list-group mx-4">
-          {this.state.tags.map((tag) => {
+          {this.state.tagData.map((data) => {
             return (
             return (
-              <a href={`/_search?q=tag:${tag}`} className="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
-                <p className="float-left my-0">{tag}</p>
+              <a key={data.tagName} href={`/_search?q=tag:${data.tagName}`} className="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
+                <p className="float-left my-0">{data.tagNeme}</p>
               </a>
               </a>
             );
             );
           })}
           })}

+ 12 - 7
src/server/routes/tag.js

@@ -35,15 +35,20 @@ module.exports = function(crowi, app) {
     const tags = await Tag.find();
     const tags = await Tag.find();
     const result = [];
     const result = [];
 
 
-    /* eslint-disable no-await-in-loop */
-    for (const tag of tags) {
-      const data = {};
-      data.tagName = tag.name;
-      data.countPage = await PageTagRelation.count({ relatedTag: tag.id });
-      result.push(data);
+    try {
+      /* eslint-disable no-await-in-loop */
+      for (const tag of tags) {
+        const data = {};
+        data.tagName = tag.name;
+        data.countPage = await PageTagRelation.count({ relatedTag: tag.id });
+        result.push(data);
+      }
+    }
+    catch (err) {
+      return res.json(ApiResponse.error(err));
     }
     }
 
 
-    return res.json(ApiResponse.success(result));
+    return res.json(ApiResponse.success({ result }));
   };
   };