@@ -10,9 +10,9 @@ import { Col, Modal, Row } from 'react-bootstrap'
1010import { useTranslation } from 'react-i18next'
1111import { useSelector } from 'react-redux'
1212import { ApplicationState } from '../../../redux'
13- import { setNoteFrontmatter } from '../../../redux/note-details/methods'
13+ import { replaceFrontmatterInMarkdownContentAction } from '../../../redux/note-details/methods'
1414import { CommonModal } from '../../common/modals/common-modal'
15- import { NoteFrontmatter , NoteType } from '../note-frontmatter/note-frontmatter'
15+ import { NoteType , RawNoteFrontmatter } from '../note-frontmatter/note-frontmatter'
1616import { BreaksMetadataInput } from './breaks-metadata-input'
1717import { DatalistMetadataInput } from './datalist-metadata-input'
1818import { InputLabel } from './input-label'
@@ -27,9 +27,9 @@ export interface MetadataEditorProps {
2727}
2828
2929export interface MetadataInputFieldProps < T > {
30- id : string
3130 content : T
32- onContentChange : ( newContent : T ) => void
31+ frontmatterKey : keyof RawNoteFrontmatter
32+ onContentChange : ( frontmatter : RawNoteFrontmatter ) => void
3333}
3434
3535export interface SelectMetadataOptions < T > {
@@ -54,11 +54,9 @@ export const MetadataEditor: React.FC<MetadataEditorProps> = ({ show, onHide })
5454 deprecatedTagsSyntax: false
5555 })*/
5656
57- const setMarkdown = useCallback ( ( changes : Partial < NoteFrontmatter > ) => {
58- const newMetadata = Object . assign ( yamlMetadata , changes )
59-
60- // setnoteDetails(noteDetails)
61- } , [ noteDetails ] )
57+ const updateFrontmatter = useCallback ( ( frontmatter : RawNoteFrontmatter ) : void => {
58+ replaceFrontmatterInMarkdownContentAction ( frontmatter )
59+ } , [ ] )
6260
6361 return (
6462 < CommonModal
@@ -71,46 +69,48 @@ export const MetadataEditor: React.FC<MetadataEditorProps> = ({ show, onHide })
7169 < Row >
7270 < Col lg = { 6 } >
7371 < InputLabel id = { 'title' } label = { t ( 'editor.modal.metadataEditor.labels.title' ) } >
74- < StringMetadataInput id = { 'title' } content = { yamlMetadata . title }
75- onContentChange = { title => setNoteFrontmatter ( { ... yamlMetadata , title } ) } />
72+ < StringMetadataInput frontmatterKey = { 'title' } content = { yamlMetadata . title }
73+ onContentChange = { updateFrontmatter } />
7674 </ InputLabel >
7775 < InputLabel id = { 'type' } label = { t ( 'editor.modal.metadataEditor.labels.type' ) } >
78- < DatalistMetadataInput id = { 'type' } options = { Object . values ( NoteType ) } content = { yamlMetadata . type }
79- onContentChange = { type => setNoteFrontmatter ( { ...yamlMetadata , type : ( type as NoteType ) } ) } />
76+ < DatalistMetadataInput frontmatterKey = { 'type' } options = { Object . values ( NoteType ) }
77+ content = { yamlMetadata . type }
78+ onContentChange = { updateFrontmatter } />
8079 </ InputLabel >
8180 < InputLabel id = { 'dir' } label = { t ( 'editor.modal.metadataEditor.labels.dir' ) } >
82- < TextDirectionMetadataInput id = { 'dir' } content = { yamlMetadata . dir }
83- onContentChange = { dir => setNoteFrontmatter ( { ... yamlMetadata , dir } ) } />
81+ < TextDirectionMetadataInput frontmatterKey = { 'dir' } content = { yamlMetadata . dir }
82+ onContentChange = { updateFrontmatter } />
8483 </ InputLabel >
8584 < InputLabel id = { 'description' } label = { t ( 'editor.modal.metadataEditor.labels.description' ) } >
86- < StringMetadataTextarea id = { 'description' } content = { yamlMetadata . description }
87- onContentChange = { description => setNoteFrontmatter ( { ... yamlMetadata , description } ) } />
85+ < StringMetadataTextarea frontmatterKey = { 'description' } content = { yamlMetadata . description }
86+ onContentChange = { updateFrontmatter } />
8887 </ InputLabel >
8988 < InputLabel id = { 'disqus' } label = { t ( 'editor.modal.metadataEditor.labels.disqus' ) } >
90- < StringMetadataInput id = { 'disqus' } content = { yamlMetadata . disqus }
91- onContentChange = { disqus => setNoteFrontmatter ( { ... yamlMetadata , disqus } ) } />
89+ < StringMetadataInput frontmatterKey = { 'disqus' } content = { yamlMetadata . disqus }
90+ onContentChange = { updateFrontmatter } />
9291 </ InputLabel >
9392 </ Col >
9493 < Col lg = { 6 } >
9594 < InputLabel id = { 'lang' } label = { t ( 'editor.modal.metadataEditor.labels.lang' ) } >
96- < DatalistMetadataInput id = { 'lang' } options = { ISO . getAllCodes ( ) } content = { yamlMetadata . lang }
97- onContentChange = { lang => setNoteFrontmatter ( { ...yamlMetadata , lang } ) } />
95+ < DatalistMetadataInput frontmatterKey = { 'lang' } options = { ISO . getAllCodes ( ) }
96+ content = { yamlMetadata . lang }
97+ onContentChange = { updateFrontmatter } />
9898 </ InputLabel >
9999 < InputLabel id = { 'robots' } label = { t ( 'editor.modal.metadataEditor.labels.robots' ) } >
100- < StringMetadataInput id = { 'robots' } content = { yamlMetadata . robots }
101- onContentChange = { robots => setNoteFrontmatter ( { ... yamlMetadata , robots } ) } />
100+ < StringMetadataInput frontmatterKey = { 'robots' } content = { yamlMetadata . robots }
101+ onContentChange = { updateFrontmatter } />
102102 </ InputLabel >
103103 < InputLabel id = { 'breaks' } label = { t ( 'editor.modal.metadataEditor.labels.breaks' ) } >
104- < BreaksMetadataInput id = { 'breaks' } content = { yamlMetadata . breaks }
105- onContentChange = { breaks => setNoteFrontmatter ( { ... yamlMetadata , breaks } ) } />
104+ < BreaksMetadataInput frontmatterKey = { 'breaks' } content = { yamlMetadata . breaks }
105+ onContentChange = { updateFrontmatter } />
106106 </ InputLabel >
107107 < InputLabel id = { 'tags' } label = { t ( 'editor.modal.metadataEditor.labels.tags' ) } >
108- < TagsMetadataInput id = { 'tags' } content = { yamlMetadata . tags }
109- onContentChange = { tags => setNoteFrontmatter ( { ... yamlMetadata , tags } ) } />
108+ < TagsMetadataInput frontmatterKey = { 'tags' } content = { yamlMetadata . tags }
109+ onContentChange = { updateFrontmatter } />
110110 </ InputLabel >
111111 < InputLabel id = { 'GA' } label = { t ( 'editor.modal.metadataEditor.labels.GA' ) } >
112- < StringMetadataInput id = { 'GA' } content = { yamlMetadata . GA }
113- onContentChange = { GA => setNoteFrontmatter ( { ... yamlMetadata , GA } ) } />
112+ < StringMetadataInput frontmatterKey = { 'GA' } content = { yamlMetadata . GA }
113+ onContentChange = { updateFrontmatter } />
114114 </ InputLabel >
115115 </ Col >
116116 </ Row >
0 commit comments