word-count-modal-content.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import PropTypes from 'prop-types'
  2. import { useTranslation } from 'react-i18next'
  3. import { Alert, Button, Modal, Row, Col, Grid } from 'react-bootstrap'
  4. import { useIdeContext } from '../../../shared/context/ide-context'
  5. import { useProjectContext } from '../../../shared/context/project-context'
  6. import { useWordCount } from '../hooks/use-word-count'
  7. import Icon from '../../../shared/components/icon'
  8. // NOTE: this component is only mounted when the modal is open
  9. export default function WordCountModalContent({ handleHide }) {
  10. const { _id: projectId } = useProjectContext()
  11. const { clsiServerId } = useIdeContext()
  12. const { t } = useTranslation()
  13. const { data, error, loading } = useWordCount(projectId, clsiServerId)
  14. return (
  15. <>
  16. <Modal.Header closeButton>
  17. <Modal.Title>{t('word_count')}</Modal.Title>
  18. </Modal.Header>
  19. <Modal.Body>
  20. {loading && !error && (
  21. <div className="loading">
  22. <Icon type="refresh" spin fw />
  23. &nbsp;
  24. {t('loading')}…
  25. </div>
  26. )}
  27. {error && (
  28. <Alert bsStyle="danger">{t('generic_something_went_wrong')}</Alert>
  29. )}
  30. {data && (
  31. <Grid fluid>
  32. {data.messages && (
  33. <Row>
  34. <Col xs={12}>
  35. <Alert bsStyle="danger">
  36. <p style={{ whiteSpace: 'pre-wrap' }}>{data.messages}</p>
  37. </Alert>
  38. </Col>
  39. </Row>
  40. )}
  41. <Row>
  42. <Col xs={4}>
  43. <div className="pull-right">{t('total_words')}:</div>
  44. </Col>
  45. <Col xs={6}>{data.textWords}</Col>
  46. </Row>
  47. <Row>
  48. <Col xs={4}>
  49. <div className="pull-right">{t('headers')}:</div>
  50. </Col>
  51. <Col xs={6}>{data.headers}</Col>
  52. </Row>
  53. <Row>
  54. <Col xs={4}>
  55. <div className="pull-right">{t('math_inline')}:</div>
  56. </Col>
  57. <Col xs={6}>{data.mathInline}</Col>
  58. </Row>
  59. <Row>
  60. <Col xs={4}>
  61. <div className="pull-right">{t('math_display')}:</div>
  62. </Col>
  63. <Col xs={6}>{data.mathDisplay}</Col>
  64. </Row>
  65. </Grid>
  66. )}
  67. </Modal.Body>
  68. <Modal.Footer>
  69. <Button onClick={handleHide}>{t('done')}</Button>
  70. </Modal.Footer>
  71. </>
  72. )
  73. }
  74. WordCountModalContent.propTypes = {
  75. handleHide: PropTypes.func.isRequired,
  76. }