clientjs/packages/dashboard-components/src/ui/Annotation.jsx
changeset 0 5f4fcbc80b37
equal deleted inserted replaced
-1:000000000000 0:5f4fcbc80b37
       
     1 import React, { Component } from 'react';
       
     2 import PropTypes from 'prop-types';
       
     3 import { FormattedRelative } from 'react-intl';
       
     4 import ReactMarkdown from 'react-markdown';
       
     5 
       
     6 import Tag from './Tag';
       
     7 import AnnotationQuote from './AnnotationQuote';
       
     8 
       
     9 export default class Annotation extends Component {
       
    10   user() {
       
    11     const { annotation } = this.props;
       
    12 
       
    13     const [userName, instanceName] = annotation.user.replace('acct:', '').split('@');
       
    14 
       
    15     return (
       
    16       <strong>
       
    17         { userName }
       
    18         <span className="text-muted">{`@${instanceName}`}</span>
       
    19       </strong>
       
    20     );
       
    21   }
       
    22 
       
    23   tags() {
       
    24     const { annotation, metacategories, categories } = this.props;
       
    25 
       
    26     const tagMetacategories = [];
       
    27     const others = [];
       
    28 
       
    29     annotation.tags.forEach((tagStr) => {
       
    30       if (tagStr.startsWith('cat:')) {
       
    31         tagMetacategories.push(tagStr);
       
    32       } else {
       
    33         others.push(tagStr);
       
    34       }
       
    35     });
       
    36 
       
    37     /* eslint-disable max-len */
       
    38     return (
       
    39       <div className="tags">
       
    40         { tagMetacategories.map(tag => <Tag tag={tag} metacategories={metacategories} categories={categories} />) }
       
    41         { others.map(tag => <Tag tag={tag} metacategories={metacategories} categories={categories} />) }
       
    42       </div>
       
    43     );
       
    44     /* eslint-enable max-len */
       
    45   }
       
    46 
       
    47   render() {
       
    48     const { annotation, metacategories } = this.props;
       
    49 
       
    50     const dateUpdated = (
       
    51       <FormattedRelative
       
    52         value={annotation.updated}
       
    53       />
       
    54     );
       
    55 
       
    56     let body = '';
       
    57 
       
    58     if (annotation.text || annotation.text !== '') {
       
    59       body = (
       
    60         <div className="comment-body text-muted font-italic">
       
    61           <ReactMarkdown source={(annotation.text)} />
       
    62         </div>
       
    63       );
       
    64     }
       
    65 
       
    66     return (
       
    67       <div className="card">
       
    68         <div className="card-header">
       
    69           <a href={annotation.uri}>{ annotation.document.title }</a>
       
    70         </div>
       
    71         <ul className="list-group list-group-flush small">
       
    72           <li className="highlight list-group-item d-block">
       
    73             <AnnotationQuote annotation={annotation} metacategories={metacategories} />
       
    74             <div className="comment-info">
       
    75               { `${this.user()} - ${dateUpdated} `}
       
    76               <a href={annotation.links.incontext}>#</a>
       
    77             </div>
       
    78             { body }
       
    79             { this.tags() }
       
    80           </li>
       
    81         </ul>
       
    82       </div>
       
    83     );
       
    84   }
       
    85 }
       
    86 
       
    87 Annotation.propTypes = {
       
    88   annotation: PropTypes.isRequired,
       
    89   metacategories: PropTypes.isRequired,
       
    90   categories: PropTypes.isRequired,
       
    91 };