clientjs/packages/dashboard-components/src/ui/DefinitionBlock.jsx
author ymh <ymh.work@gmail.com>
Mon, 04 Apr 2022 17:02:10 +0200
changeset 26 eb14941af2e7
parent 0 5f4fcbc80b37
permissions -rw-r--r--
Added tag 0.2.2 for changeset 7f7cdcd01dea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import React from 'react';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import PropTypes from 'prop-types';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import ReactMarkdown from 'react-markdown';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import AnnotationQuote from './AnnotationQuote';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
import './DefinitionBlock.scss';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
const DefinitionHeaderIcon = ({ annotation }) => {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
  const annotationText = annotation.text || '';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
  let faIconName;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
  if (annotationText) {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    faIconName = 'user';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
  } else if (/^https?:\/\/.+\.wikipedia\.org/.test(annotation.uri)) {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    faIconName = ['fab', 'wikipedia-w'];
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
  } else {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    faIconName = 'globe';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
  }
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
  return <FontAwesomeIcon icon={faIconName} className="annotation-card-definition-icon" />;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
};
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
DefinitionHeaderIcon.propTypes = {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
  annotation: PropTypes.object.isRequired,
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
};
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
const DefinitionUser = ({ annotation }) => {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
  const [userName] = annotation.user.replace('acct:', '').split('@');
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
  return (
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    <strong>
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
      { userName }
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
      {/* <span className="text-muted">@{ instanceName }</span> */}
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    </strong>
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
  );
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
};
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
DefinitionUser.propTypes = {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
  annotation: PropTypes.object.isRequired,
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
};
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
const DefinitionBody = ({ annotation, metacategories }) => {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
  if (annotation.text) {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    return <ReactMarkdown source={annotation.text} />;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
  }
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
  return <AnnotationQuote annotation={annotation} metacategories={metacategories} />;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
};
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
DefinitionBody.propTypes = {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
  annotation: PropTypes.object.isRequired,
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
  metacategories: PropTypes.arrayOf(PropTypes.object).isRequired,
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
};
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
const DefinitionBlock = ({ annotation, metacategories }) => {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
  const { document } = annotation;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
  return (
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
    <div className="card definition-card">
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
      <div className="card-header">
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
        <DefinitionHeaderIcon annotation={annotation} />
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
      </div>
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
      <div className="card-body small">
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
        <DefinitionBody annotation={annotation} metacategories={metacategories} />
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
      </div>
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
      <div className="card-footer">
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
        <a href={annotation.links.incontext} target="_blank" rel="noopener noreferrer">{ document.title }</a>
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        <div>
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
          <DefinitionUser annotation={annotation} />
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
        </div>
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
      </div>
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    </div>
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
  );
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
};
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
DefinitionBlock.propTypes = {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
  annotation: PropTypes.object.isRequired,
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
  metacategories: PropTypes.arrayOf(PropTypes.object).isRequired,
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
};
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
export default DefinitionBlock;