@@ -10,9 +10,9 @@ import { Col, Modal, Row } from 'react-bootstrap'
10
10
import { useTranslation } from 'react-i18next'
11
11
import { useSelector } from 'react-redux'
12
12
import { ApplicationState } from '../../../redux'
13
- import { setNoteFrontmatter } from '../../../redux/note-details/methods'
13
+ import { replaceFrontmatterInMarkdownContentAction } from '../../../redux/note-details/methods'
14
14
import { CommonModal } from '../../common/modals/common-modal'
15
- import { NoteFrontmatter , NoteType } from '../note-frontmatter/note-frontmatter'
15
+ import { NoteType , RawNoteFrontmatter } from '../note-frontmatter/note-frontmatter'
16
16
import { BreaksMetadataInput } from './breaks-metadata-input'
17
17
import { DatalistMetadataInput } from './datalist-metadata-input'
18
18
import { InputLabel } from './input-label'
@@ -27,9 +27,9 @@ export interface MetadataEditorProps {
27
27
}
28
28
29
29
export interface MetadataInputFieldProps < T > {
30
- id : string
31
30
content : T
32
- onContentChange : ( newContent : T ) => void
31
+ frontmatterKey : keyof RawNoteFrontmatter
32
+ onContentChange : ( frontmatter : RawNoteFrontmatter ) => void
33
33
}
34
34
35
35
export interface SelectMetadataOptions < T > {
@@ -54,11 +54,9 @@ export const MetadataEditor: React.FC<MetadataEditorProps> = ({ show, onHide })
54
54
deprecatedTagsSyntax: false
55
55
})*/
56
56
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
+ } , [ ] )
62
60
63
61
return (
64
62
< CommonModal
@@ -71,46 +69,48 @@ export const MetadataEditor: React.FC<MetadataEditorProps> = ({ show, onHide })
71
69
< Row >
72
70
< Col lg = { 6 } >
73
71
< 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 } />
76
74
</ InputLabel >
77
75
< 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 } />
80
79
</ InputLabel >
81
80
< 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 } />
84
83
</ InputLabel >
85
84
< 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 } />
88
87
</ InputLabel >
89
88
< 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 } />
92
91
</ InputLabel >
93
92
</ Col >
94
93
< Col lg = { 6 } >
95
94
< 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 } />
98
98
</ InputLabel >
99
99
< 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 } />
102
102
</ InputLabel >
103
103
< 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 } />
106
106
</ InputLabel >
107
107
< 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 } />
110
110
</ InputLabel >
111
111
< 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 } />
114
114
</ InputLabel >
115
115
</ Col >
116
116
</ Row >
0 commit comments