word-count-modal-content.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 bsStyle={null} className="btn-secondary" onClick={handleHide}>
  70. {t('done')}
  71. </Button>
  72. </Modal.Footer>
  73. </>
  74. )
  75. }
  76. WordCountModalContent.propTypes = {
  77. handleHide: PropTypes.func.isRequired,
  78. }