Skip to content

Commit 2e30781

Browse files
author
PhotoNomad0
committed
have aligner area working.
1 parent 3f19d29 commit 2e30781

File tree

2 files changed

+18
-83
lines changed

2 files changed

+18
-83
lines changed

src/components/WordAlignerArea.js

-66
Original file line numberDiff line numberDiff line change
@@ -29,84 +29,18 @@ export default function WordAlignerArea({
2929
}) {
3030
const [aligned_, setAligned] = useState(aligned)
3131
const [alignmentChange, setAlignmentChange] = useState(null)
32-
const alignerData_ =
33-
targetWords && verseAlignments
34-
?
35-
{
36-
targetWords,
37-
verseAlignments
38-
}
39-
:
40-
null;
4132

4233
useEffect(() => {
4334
console.log('WordAlignerArea: initialized')
4435
}, [])
4536

46-
useEffect(() => {
47-
// see if alignment data has changed
48-
const show = alignerData_?.showDialog;
49-
const verseAlignments_ = dialogState?.verseAlignments || null;
50-
const targetWords_ = dialogState?.targetWords || null;
51-
const changedTW = !isEqual(targetWords, targetWords_);
52-
if (changedTW) {
53-
// const differences = diff(wordBank, targetWords_);
54-
console.log("targetWords differences")
55-
}
56-
const changedVA = !isEqual(verseAlignments_, verseAlignments_);
57-
if (changedVA) {
58-
// const differences = diff(verseAlignments, verseAlignments_);
59-
console.log("verseAlignments differences")
60-
}
61-
const showDialog = !!(verseAlignments_ && targetWords);
62-
const changedShow = (!show !== !showDialog)
63-
64-
if (changedTW || changedVA || changedShow) {
65-
const verseAlignments = cloneDeep(verseAlignments_);
66-
const targetWords = cloneDeep(wordBank);
67-
setDialogState({
68-
verseAlignments,
69-
targetWords,
70-
showDialog,
71-
})
72-
}
73-
74-
setCurrentAlignerData(cloneDeep(alignerData_))
75-
}, [alignerData_])
76-
7737
useEffect(() => {
7838
if (aligned !== aligned_) {
7939
console.log('WordAlignerArea: set alignment to', aligned)
8040
setAligned(aligned)
8141
}
8242
}, [aligned])
8343

84-
useEffect(() => {
85-
// see if verse alignment data has changed
86-
const alignments_ = verseAlignments || null;
87-
const wordBank_ = targetWords || null;
88-
89-
const changedTW = !isEqual(wordBank_, wordBank);
90-
if (changedTW) {
91-
// const differences = diff(wordBank, targetWords_);
92-
console.log("wordBank differences")
93-
}
94-
const changedVA = !isEqual(alignments_, verseAlignments_);
95-
if (changedVA) {
96-
// const differences = diff(verseAlignments, verseAlignments_);
97-
console.log("alignments differences")
98-
}
99-
if (changedTW || changedVA) {
100-
const alignments = cloneDeep(alignments_);
101-
const wordBank = cloneDeep(wordBank_);
102-
setCurrentAlignerData({
103-
alignments,
104-
wordBank,
105-
})
106-
}
107-
}, [targetWords, verseAlignments,])
108-
109-
11044
function onAlignmentChange(results) {
11145
// const onAlignmentsChange = alignerStatus?.actions?.onAlignmentsChange
11246
// const alignmentComplete = onAlignmentsChange?.(results)

src/components/WordAlignerDialog.js

+18-17
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ export default function WordAlignerDialog({
3434
const [alignmentChange, setAlignmentChange] = useState(null)
3535
const [aligned, setAligned] = useState(false)
3636
const [lexiconData, setLexiconData] = useState(null)
37-
const [dialogState, setDialogState] = useState(false)
37+
const [dialogState, setDialogState_] = useState({})
3838
const [showResetWarning, setShowResetWarning] = useState(false)
3939
const dialogRef = useRef(null) // for keeping track of aligner dialog position
4040

4141
const alignerData_ = alignerStatus?.state?.alignerData || null
42-
const shouldShowDialog = !!(alignerData_?.verseAlignments && alignerData_?.targetWords)
43-
42+
const shouldShowDialog = !!(alignerData_?.alignments && alignerData_?.wordBank)
4443
const currentShowDialog = !!dialogState?.showDialog
4544

4645
const {
@@ -80,11 +79,11 @@ export default function WordAlignerDialog({
8079
console.log('WordAlignerDialog: aligner data changed')
8180
if (currentShowDialog !== shouldShowDialog) {
8281
console.log('WordAlignerDialog: aligner visible state changed')
83-
setShowDialog(shouldShowDialog)
84-
setDialogState(cloneDeep({
82+
const dialogState_ = {
8583
...alignerData_,
8684
showDialog: shouldShowDialog,
87-
}))
85+
};
86+
setDialogState(dialogState_)
8887
}
8988
}, [alignerData_])
9089

@@ -103,11 +102,6 @@ export default function WordAlignerDialog({
103102
)
104103
}
105104

106-
107-
useEffect(() => {
108-
console.log('WordAlignerDialog: initialized')
109-
}, [])
110-
111105
const currentInstance = dialogRef?.current;
112106
useEffect(() => { // monitor changes in alignment dialog position and open state
113107
if (alignerData_ &&
@@ -157,6 +151,15 @@ export default function WordAlignerDialog({
157151
} = alignerStatus?.state?.reference || {}
158152
const title = `${projectId?.toUpperCase()} ${chapter}:${verse} in ${alignerStatus?.state?.title}`
159153

154+
function setDialogState(newState) {
155+
const dialogState_ = cloneDeep(
156+
{
157+
...dialogState,
158+
...newState,
159+
}
160+
)
161+
setDialogState_(dialogState_)
162+
}
160163
function cancelAlignment() {
161164
console.log('WordAlignerDialog: cancelAlignment')
162165
const cancelAlignment = alignerStatus?.actions?.cancelAlignment
@@ -174,10 +177,9 @@ export default function WordAlignerDialog({
174177
function setShowDialog(show) {
175178
console.log('WordAlignerDialog: setShowDialog', show)
176179
const _dialogState = {
177-
...dialogState,
178180
showDialog: !!show,
179181
}
180-
setDialogState(cloneDeep(_dialogState));
182+
setDialogState(_dialogState);
181183
}
182184

183185
/**
@@ -190,12 +192,11 @@ export default function WordAlignerDialog({
190192

191193
const showDialog = true;
192194
const dialogState_ = {
193-
...dialogState, // keep old data
194195
...alignmentData_, // merge in reset alignment data
195196
showDialog,
196197
}
197198

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
199200
setAlignmentChange(cloneDeep(alignmentData_)) // clear the last alignment changes in case user next does save
200201
}
201202

@@ -217,8 +218,8 @@ export default function WordAlignerDialog({
217218
alignmentIconStyle={alignmentIconStyle}
218219
title={title || ''}
219220
style={{ maxHeight: `${height}px`, overflowY: 'auto' }}
220-
verseAlignments={dialogState?.verseAlignments || []}
221-
targetWords={dialogState?.targetWords || []}
221+
verseAlignments={dialogState?.alignments || []}
222+
targetWords={dialogState?.wordBank || []}
222223
translate={translate}
223224
contextId={{ reference: alignerStatus?.state?.reference || {} }}
224225
targetLanguage={alignerStatus?.state?.targetLanguage || ''}

0 commit comments

Comments
 (0)