@@ -34,13 +34,12 @@ export default function WordAlignerDialog({
34
34
const [ alignmentChange , setAlignmentChange ] = useState ( null )
35
35
const [ aligned , setAligned ] = useState ( false )
36
36
const [ lexiconData , setLexiconData ] = useState ( null )
37
- const [ dialogState , setDialogState ] = useState ( false )
37
+ const [ dialogState , setDialogState_ ] = useState ( { } )
38
38
const [ showResetWarning , setShowResetWarning ] = useState ( false )
39
39
const dialogRef = useRef ( null ) // for keeping track of aligner dialog position
40
40
41
41
const alignerData_ = alignerStatus ?. state ?. alignerData || null
42
- const shouldShowDialog = ! ! ( alignerData_ ?. verseAlignments && alignerData_ ?. targetWords )
43
-
42
+ const shouldShowDialog = ! ! ( alignerData_ ?. alignments && alignerData_ ?. wordBank )
44
43
const currentShowDialog = ! ! dialogState ?. showDialog
45
44
46
45
const {
@@ -80,11 +79,11 @@ export default function WordAlignerDialog({
80
79
console . log ( 'WordAlignerDialog: aligner data changed' )
81
80
if ( currentShowDialog !== shouldShowDialog ) {
82
81
console . log ( 'WordAlignerDialog: aligner visible state changed' )
83
- setShowDialog ( shouldShowDialog )
84
- setDialogState ( cloneDeep ( {
82
+ const dialogState_ = {
85
83
...alignerData_ ,
86
84
showDialog : shouldShowDialog ,
87
- } ) )
85
+ } ;
86
+ setDialogState ( dialogState_ )
88
87
}
89
88
} , [ alignerData_ ] )
90
89
@@ -103,11 +102,6 @@ export default function WordAlignerDialog({
103
102
)
104
103
}
105
104
106
-
107
- useEffect ( ( ) => {
108
- console . log ( 'WordAlignerDialog: initialized' )
109
- } , [ ] )
110
-
111
105
const currentInstance = dialogRef ?. current ;
112
106
useEffect ( ( ) => { // monitor changes in alignment dialog position and open state
113
107
if ( alignerData_ &&
@@ -157,6 +151,15 @@ export default function WordAlignerDialog({
157
151
} = alignerStatus ?. state ?. reference || { }
158
152
const title = `${ projectId ?. toUpperCase ( ) } ${ chapter } :${ verse } in ${ alignerStatus ?. state ?. title } `
159
153
154
+ function setDialogState ( newState ) {
155
+ const dialogState_ = cloneDeep (
156
+ {
157
+ ...dialogState ,
158
+ ...newState ,
159
+ }
160
+ )
161
+ setDialogState_ ( dialogState_ )
162
+ }
160
163
function cancelAlignment ( ) {
161
164
console . log ( 'WordAlignerDialog: cancelAlignment' )
162
165
const cancelAlignment = alignerStatus ?. actions ?. cancelAlignment
@@ -174,10 +177,9 @@ export default function WordAlignerDialog({
174
177
function setShowDialog ( show ) {
175
178
console . log ( 'WordAlignerDialog: setShowDialog' , show )
176
179
const _dialogState = {
177
- ...dialogState ,
178
180
showDialog : ! ! show ,
179
181
}
180
- setDialogState ( cloneDeep ( _dialogState ) ) ;
182
+ setDialogState ( _dialogState ) ;
181
183
}
182
184
183
185
/**
@@ -190,12 +192,11 @@ export default function WordAlignerDialog({
190
192
191
193
const showDialog = true ;
192
194
const dialogState_ = {
193
- ...dialogState , // keep old data
194
195
...alignmentData_ , // merge in reset alignment data
195
196
showDialog,
196
197
}
197
198
198
- setDialogState ( cloneDeep ( dialogState_ ) ) ; // this causes word aligner to redraw with empty alignments
199
+ setDialogState ( dialogState_ ) ; // this causes word aligner to redraw with empty alignments
199
200
setAlignmentChange ( cloneDeep ( alignmentData_ ) ) // clear the last alignment changes in case user next does save
200
201
}
201
202
@@ -217,8 +218,8 @@ export default function WordAlignerDialog({
217
218
alignmentIconStyle = { alignmentIconStyle }
218
219
title = { title || '' }
219
220
style = { { maxHeight : `${ height } px` , overflowY : 'auto' } }
220
- verseAlignments = { dialogState ?. verseAlignments || [ ] }
221
- targetWords = { dialogState ?. targetWords || [ ] }
221
+ verseAlignments = { dialogState ?. alignments || [ ] }
222
+ targetWords = { dialogState ?. wordBank || [ ] }
222
223
translate = { translate }
223
224
contextId = { { reference : alignerStatus ?. state ?. reference || { } } }
224
225
targetLanguage = { alignerStatus ?. state ?. targetLanguage || '' }
0 commit comments