@@ -55,6 +55,7 @@ import {
5555 prepareExternalLinksHtmlFormSubmission ,
5656} from '../../edit/externalLinks.js' ;
5757import guessFeat from '../../edit/utility/guessFeat2.js' ;
58+ import isInvalidEditNote from '../../edit/utility/isInvalidEditNote.js' ;
5859import {
5960 applyAllPendingErrors ,
6061 hasSubfieldErrors ,
@@ -68,11 +69,13 @@ type ActionT =
6869 | { + type : 'guess-feat' }
6970 | { + type : 'show-all-pending-errors' }
7071 | { + type : 'toggle-bubble' , + bubble : string }
72+ | { + type : 'update-edit-note' , + editNote : string }
7173 | { + type : 'update-name' , + action : NameActionT }
7274 | { + type : 'update-artist-credit' , + action : ArtistCreditActionT } ;
7375/* eslint-enable ft-flow/sort-keys */
7476
7577type StateT = {
78+ + actionName : string ,
7679 + artistCredit : ArtistCreditStateT ,
7780 + form : RecordingFormT ,
7881 + guessCaseOptions : GuessCaseOptionsStateT ,
@@ -109,6 +112,7 @@ function createInitialState(
109112 updateNameFieldErrors ( nameFieldCtx ) ;
110113
111114 return {
115+ actionName : $c . action . name ,
112116 artistCredit : createArtistCreditState ( {
113117 artistCredit : $c . stash . artist_credit ,
114118 entity : recording ,
@@ -127,6 +131,22 @@ function reducer(state: StateT, action: ActionT): StateT {
127131 const newStateCtx = mutate ( state ) ;
128132
129133 match ( action ) {
134+ { type : 'update - edit - note ', const editNote} => {
135+ const errors = isInvalidEditNote ( editNote )
136+ ? [ l ( `Your edit note seems to have no actual content.
137+ Please provide a note that will be helpful to
138+ your fellow editors!` ) ]
139+ : state . actionName === 'create' && empty ( editNote )
140+ ? [ l ( `You must provide an edit note when adding
141+ a standalone recording` ) ]
142+ : [ ] ;
143+
144+ newStateCtx . set ( 'form' , 'field' , 'edit_note' , {
145+ ...newStateCtx . get ( 'form' , 'field' , 'edit_note' ) . read ( ) ,
146+ errors,
147+ value : editNote ,
148+ } ) ;
149+ }
130150 { type : 'update - name ', const action} => {
131151 const nameStateCtx = mutate ( {
132152 field : state . form . field . name ,
@@ -206,6 +226,15 @@ component RecordingEditForm(
206226 dispatch ( { action, type : 'update-artist-credit' } ) ;
207227 } , [ dispatch ] ) ;
208228
229+ const handleEditNoteChange = React . useCallback ( (
230+ event : SyntheticEvent < HTMLTextAreaElement > ,
231+ ) => {
232+ dispatch ( {
233+ editNote : event . currentTarget . value ,
234+ type : 'update-edit-note' ,
235+ } ) ;
236+ } , [ dispatch ] ) ;
237+
209238 function handleCommentFocus ( ) {
210239 dispatch ( { bubble : 'comment' , type : 'toggle-bubble' } ) ;
211240 }
@@ -362,7 +391,11 @@ component RecordingEditForm(
362391 />
363392 </ fieldset >
364393
365- < EnterEditNote field = { state . form . field . edit_note } />
394+ < EnterEditNote
395+ controlled
396+ field = { state . form . field . edit_note }
397+ onChange = { handleEditNoteChange }
398+ />
366399 < EnterEdit disabled = { hasErrors } form = { state . form } />
367400 </ div >
368401
0 commit comments