mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 10:14:28 -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",
|
||||
"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.",
|
||||
"infoToc": "Structure your note with headings to see a table-of-contents here.",
|
||||
"help": {
|
||||
"shortcuts": {
|
||||
"title": "Shortcuts",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
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 { ShowIf } from '../../common/show-if/show-if'
|
||||
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 }) => {
|
||||
useTranslation()
|
||||
const tocTree = useMemo(() => convertLevel(ast, maxDepth, new Map<string, number>(), false), [ast, maxDepth])
|
||||
|
||||
return (
|
||||
<div className={`markdown-toc ${className ?? ''}`}>
|
||||
<ShowIf condition={ast.c.length === 0}>
|
||||
<Trans i18nKey={'editor.infoToc'}/>
|
||||
</ShowIf>
|
||||
{ tocTree }
|
||||
</div>
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue