mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 12:34:23 -05:00
Add info message on empty toc (#567)
This commit is contained in:
parent
5972932d33
commit
8842fff06f
2 changed files with 8 additions and 2 deletions
|
@ -153,6 +153,7 @@
|
||||||
"untitledNote": "Untitled",
|
"untitledNote": "Untitled",
|
||||||
"placeholder": "← Start by entering a title here\n===\nVisit the features page if you don't know what to do.\nHappy hacking :)",
|
"placeholder": "← Start by entering a title here\n===\nVisit the features page if you don't know what to do.\nHappy hacking :)",
|
||||||
"invalidYaml": "The yaml-header is invalid. See <0></0> for more information.",
|
"invalidYaml": "The yaml-header is invalid. See <0></0> for more information.",
|
||||||
|
"infoToc": "Structure your note with headings to see a table-of-contents here.",
|
||||||
"help": {
|
"help": {
|
||||||
"shortcuts": {
|
"shortcuts": {
|
||||||
"title": "Shortcuts",
|
"title": "Shortcuts",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { Fragment, ReactElement, useMemo } from 'react'
|
import React, { Fragment, ReactElement, useMemo } from 'react'
|
||||||
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
||||||
import { ShowIf } from '../../common/show-if/show-if'
|
import { ShowIf } from '../../common/show-if/show-if'
|
||||||
import './table-of-contents.scss'
|
import './table-of-contents.scss'
|
||||||
|
@ -52,10 +53,14 @@ const convertLevel = (toc: TocAst, levelsToShowUnderThis: number, headerCounts:
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TableOfContents: React.FC<TableOfContentsProps> = ({ ast, maxDepth = 3, className }) => {
|
export const TableOfContents: React.FC<TableOfContentsProps> = ({ ast, maxDepth = 3, className }) => {
|
||||||
|
useTranslation()
|
||||||
const tocTree = useMemo(() => convertLevel(ast, maxDepth, new Map<string, number>(), false), [ast, maxDepth])
|
const tocTree = useMemo(() => convertLevel(ast, maxDepth, new Map<string, number>(), false), [ast, maxDepth])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`markdown-toc ${className ?? ''}`}>
|
<div className={`markdown-toc ${className ?? ''}`}>
|
||||||
|
<ShowIf condition={ast.c.length === 0}>
|
||||||
|
<Trans i18nKey={'editor.infoToc'}/>
|
||||||
|
</ShowIf>
|
||||||
{ tocTree }
|
{ tocTree }
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue