mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 03:27:05 -04:00
Add word count in document info modal (#738)
Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
4b3990d0db
commit
57f46f489b
15 changed files with 242 additions and 9 deletions
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { ShowIf } from '../../../common/show-if/show-if'
|
||||
import { DocumentInfoLine } from './document-info-line'
|
||||
import { UnitalicBoldText } from './unitalic-bold-text'
|
||||
import { useIFrameEditorToRendererCommunicator } from '../../render-context/iframe-editor-to-renderer-communicator-context-provider'
|
||||
|
||||
/**
|
||||
* Creates a new info line for the document information dialog that holds the
|
||||
* word count of the note, based on counting in the rendered output.
|
||||
*/
|
||||
export const DocumentInfoLineWordCount: React.FC = () => {
|
||||
useTranslation()
|
||||
const iframeEditorToRendererCommunicator = useIFrameEditorToRendererCommunicator()
|
||||
const [wordCount, setWordCount] = useState<number | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
iframeEditorToRendererCommunicator?.onWordCountCalculated((words) => {
|
||||
setWordCount(words)
|
||||
})
|
||||
iframeEditorToRendererCommunicator?.sendGetWordCount()
|
||||
return () => {
|
||||
iframeEditorToRendererCommunicator?.onWordCountCalculated(undefined)
|
||||
}
|
||||
}, [iframeEditorToRendererCommunicator, setWordCount])
|
||||
|
||||
return (
|
||||
<DocumentInfoLine icon={'align-left'} size={'2x'}>
|
||||
<ShowIf condition={wordCount === null}>
|
||||
<Trans i18nKey={'common.loading'} />
|
||||
</ShowIf>
|
||||
<ShowIf condition={wordCount !== null}>
|
||||
<Trans i18nKey={'editor.modal.documentInfo.words'}>
|
||||
<UnitalicBoldText text={wordCount ?? ''} dataCy={'document-info-word-count'} />
|
||||
</Trans>
|
||||
</ShowIf>
|
||||
</DocumentInfoLine>
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue