@@ -87,6 +87,13 @@ const DocContextMenu = ({
87
87
? usersMap . get ( currentDoc . userId )
88
88
: undefined
89
89
90
+ const contentCounters = useMemo ( ( ) => {
91
+ return {
92
+ wordCount : currentDoc ?. head ?. content . match ( / \S + / g) ?. length || 0 ,
93
+ characterCount : currentDoc ?. head ?. content . replace ( / \s + / g, '' ) . length || 0 ,
94
+ }
95
+ } , [ currentDoc ?. head ?. content ] )
96
+
90
97
if ( currentDoc == null ) {
91
98
return (
92
99
< MetadataContainer
@@ -213,26 +220,22 @@ const DocContextMenu = ({
213
220
} }
214
221
/>
215
222
) }
216
- { currentDoc . head && [
217
- < MetadataContainerRow
218
- key = 'word-count'
219
- row = { {
220
- label : translate ( lngKeys . WordCount ) ,
221
- type : 'content' ,
222
- icon : mdiFormatLetterCase ,
223
- content : currentDoc . head . content . match ( / \S + / g) ?. length || 0 ,
224
- } }
225
- /> ,
226
- < MetadataContainerRow
227
- key = 'character-count'
228
- row = { {
229
- label : translate ( lngKeys . CharacterCount ) ,
230
- type : 'content' ,
231
- icon : mdiText ,
232
- content : currentDoc . head . content . replace ( / \s + / g, '' ) . length || 0 ,
233
- } }
234
- /> ,
235
- ] }
223
+ < MetadataContainerRow
224
+ row = { {
225
+ label : translate ( lngKeys . WordCount ) ,
226
+ type : 'content' ,
227
+ icon : mdiFormatLetterCase ,
228
+ content : contentCounters . wordCount ,
229
+ } }
230
+ />
231
+ < MetadataContainerRow
232
+ row = { {
233
+ label : translate ( lngKeys . CharacterCount ) ,
234
+ type : 'content' ,
235
+ icon : mdiText ,
236
+ content : contentCounters . characterCount ,
237
+ } }
238
+ />
236
239
< BackLinksList team = { team } docs = { backLinks } />
237
240
< MetadataContainerBreak />
238
241
< DocContextMenuActions
0 commit comments