word-count-modal-content.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 modifier="fw" /> &nbsp; {t('loading')}…
  23. </div>
  24. )}
  25. {error && (
  26. <Alert bsStyle="danger">{t('generic_something_went_wrong')}</Alert>
  27. )}
  28. {data && (
  29. <Grid fluid>
  30. {data.messages && (
  31. <Row>
  32. <Col xs={12}>
  33. <Alert bsStyle="danger">
  34. <p style={{ whiteSpace: 'pre-wrap' }}>{data.messages}</p>
  35. </Alert>
  36. </Col>
  37. </Row>
  38. )}
  39. <Row>
  40. <Col xs={4}>
  41. <div className="pull-right">{t('total_words')}:</div>
  42. </Col>
  43. <Col xs={6}>{data.textWords}</Col>
  44. </Row>
  45. <Row>
  46. <Col xs={4}>
  47. <div className="pull-right">{t('headers')}:</div>
  48. </Col>
  49. <Col xs={6}>{data.headers}</Col>
  50. </Row>
  51. <Row>
  52. <Col xs={4}>
  53. <div className="pull-right">{t('math_inline')}:</div>
  54. </Col>
  55. <Col xs={6}>{data.mathInline}</Col>
  56. </Row>
  57. <Row>
  58. <Col xs={4}>
  59. <div className="pull-right">{t('math_display')}:</div>
  60. </Col>
  61. <Col xs={6}>{data.mathDisplay}</Col>
  62. </Row>
  63. </Grid>
  64. )}
  65. </Modal.Body>
  66. <Modal.Footer>
  67. <Button onClick={handleHide}>{t('done')}</Button>
  68. </Modal.Footer>
  69. </>
  70. )
  71. }
  72. WordCountModalContent.propTypes = {
  73. handleHide: PropTypes.func.isRequired,
  74. }