mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-24 12:07:08 -04:00
Set sanitized note title as filename for download (#1057)
This commit is contained in:
parent
7dd91c7b46
commit
a1698047a8
3 changed files with 26 additions and 4 deletions
|
@ -5,18 +5,20 @@
|
|||
*/
|
||||
|
||||
import React, { useCallback } from 'react'
|
||||
import sanitize from 'sanitize-filename'
|
||||
import { store } from '../../../redux'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { useNoteMarkdownContent } from '../../../hooks/common/use-note-markdown-content'
|
||||
import { download } from '../../common/download/download'
|
||||
import { SidebarButton } from './sidebar-button'
|
||||
|
||||
export const ExportMarkdownSidebarEntry: React.FC = () => {
|
||||
useTranslation()
|
||||
|
||||
const { t } = useTranslation()
|
||||
const markdownContent = useNoteMarkdownContent()
|
||||
const onClick = useCallback(() => {
|
||||
download(markdownContent, `title.md`, 'text/markdown') //todo: replace hard coded title with redux
|
||||
}, [markdownContent])
|
||||
const sanitized = sanitize(store.getState().noteDetails.noteTitle)
|
||||
download(markdownContent, `${ sanitized !== '' ? sanitized : t('editor.untitledNote') }.md`, 'text/markdown')
|
||||
}, [markdownContent, t])
|
||||
|
||||
return (
|
||||
<SidebarButton data-cy={ 'menu-export-markdown' } onClick={ onClick } icon={ 'file-text' }>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue