Skip to content

Commit e1d650e

Browse files
author
Greg Trihus
committed
Fix static reported issues.
1 parent 5665682 commit e1d650e

10 files changed

Lines changed: 112 additions & 130 deletions

src/renderer/src/components/PassageDetail/PassageDetailMarkVerses.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ export function PassageDetailMarkVerses({ width }: MarkVersesProps) {
224224
return () => {
225225
window.removeEventListener('resize', handleResize);
226226
};
227-
/* eslint-disable-next-line react-hooks/exhaustive-deps */
228227
}, []);
229228

230229
useEffect(() => {
@@ -233,7 +232,7 @@ export function PassageDetailMarkVerses({ width }: MarkVersesProps) {
233232
ColName.Limits
234233
);
235234
playerControlsRef.current?.applyMarkVersesRegionColors?.();
236-
}, [data, pastedSegments]);
235+
}, [ColName.Limits, data, pastedSegments]);
237236

238237
const rowCells = (row: string[], first = false) =>
239238
row.map(
@@ -631,7 +630,7 @@ export function PassageDetailMarkVerses({ width }: MarkVersesProps) {
631630
}))
632631
)
633632
: data.map((r) => r.map((c) => ({ ...c, readOnly: true }))),
634-
[data, hasPermission]
633+
[ColName.Limits, ColName.Ref, data, hasPermission]
635634
);
636635

637636
const handleRowClick = async (rowIndex: number) => {
@@ -844,7 +843,12 @@ export function PassageDetailMarkVerses({ width }: MarkVersesProps) {
844843
[]
845844
);
846845

847-
useEffect(() => () => { scheduleAutosave.clear(); }, [scheduleAutosave]);
846+
useEffect(
847+
() => () => {
848+
scheduleAutosave.clear();
849+
},
850+
[scheduleAutosave]
851+
);
848852

849853
useEffect(() => {
850854
if (!isChanged(verseToolId) || !hasPermission || savingRef.current) return;

src/renderer/src/components/PassageDetail/mobile/MarkVerses/EditReferenceDropdown.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ export default function EditReferenceDropdown({
181181
<NativeSelect
182182
value={draft.startSuffix}
183183
onChange={handleSuffixChange('startSuffix')}
184-
inputProps={{ 'aria-label': 'start verse suffix' }}
184+
inputProps={{
185+
'aria-label': 'start verse suffix',
186+
title: 'start verse suffix',
187+
}}
185188
sx={{ ...selectSx, mt: 0.5 }}
186189
>
187190
{suffixOptions.map((option) => (
@@ -218,7 +221,7 @@ export default function EditReferenceDropdown({
218221
onChange={handleEndVerseChange}
219222
inputProps={{
220223
'aria-label': 'end verse number',
221-
title: 'End verse number',
224+
title: 'end verse number',
222225
}}
223226
sx={verseSelectSx}
224227
>
@@ -237,7 +240,10 @@ export default function EditReferenceDropdown({
237240
<NativeSelect
238241
value={draft.endSuffix}
239242
onChange={handleSuffixChange('endSuffix')}
240-
inputProps={{ 'aria-label': 'end verse suffix' }}
243+
inputProps={{
244+
'aria-label': 'end verse suffix',
245+
title: 'end verse suffix',
246+
}}
241247
sx={{ ...selectSx, mt: 0.5 }}
242248
>
243249
{suffixOptions.map((option) => (

src/renderer/src/components/PassageDetail/mobile/MarkVerses/PassageDetailMarkVersesIsMobile.test.tsx

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,24 +304,6 @@ const markVersesTbody = () => {
304304
return tbody;
305305
};
306306

307-
/**
308-
* Click the n-th data row in tbody (0 = first passage row). Avoids relying on
309-
* whether `getAllByRole('row')` on the whole table includes thead rows.
310-
*/
311-
const clickMarkVersesBodyRow = async (
312-
user: UserEvent,
313-
bodyRowIndex: number
314-
) => {
315-
const rows = within(markVersesTbody()).getAllByRole('row');
316-
const row = rows[bodyRowIndex];
317-
if (!row) {
318-
throw new Error(
319-
`mark verses body row ${bodyRowIndex} missing (have ${rows.length} rows)`
320-
);
321-
}
322-
await user.click(row);
323-
};
324-
325307
/**
326308
* Click the tbody row whose Limits column shows `limitsText` (requires verse
327309
* segments / waveform so the cell is not "-"). Scoped to tbody so the label is
@@ -570,7 +552,9 @@ test('saves a split verse range and shifts following references up', async () =>
570552
within(editReferenceDialog()).getByRole('button', { name: 'Save' })
571553
);
572554

573-
expect(screen.getByLabelText('verse-reference-1')).toHaveTextContent('1:1a-2e');
555+
expect(screen.getByLabelText('verse-reference-1')).toHaveTextContent(
556+
'1:1a-2e'
557+
);
574558
expect(screen.getByLabelText('verse-reference-2')).toHaveTextContent('1:3');
575559
expect(screen.getByLabelText('verse-reference-3')).toHaveTextContent('1:4');
576560
});
@@ -802,7 +786,9 @@ test('shows undo after dialog save and restores the previous table', async () =>
802786
);
803787

804788
expect(screen.getByRole('button', { name: 'Undo' })).toBeInTheDocument();
805-
expect(screen.getByLabelText('verse-reference-1')).toHaveTextContent('1:1a-2e');
789+
expect(screen.getByLabelText('verse-reference-1')).toHaveTextContent(
790+
'1:1a-2e'
791+
);
806792

807793
await user.click(screen.getByRole('button', { name: 'Undo' }));
808794

src/renderer/src/components/PassageDetail/mobile/MarkVerses/PassageDetailMarkVersesIsMobile.tsx

Lines changed: 44 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import {
66
useRef,
77
useState,
88
} from 'react';
9-
import { Box, debounce, IconButton, Paper, SxProps, Typography } from '@mui/material';
9+
import {
10+
Box,
11+
debounce,
12+
IconButton,
13+
Paper,
14+
SxProps,
15+
Typography,
16+
} from '@mui/material';
1017
import { shallowEqual, useSelector } from 'react-redux';
1118
import { useGlobal } from '../../../../context/useGlobal';
1219
import usePassageDetailContext from '../../../../context/usePassageDetailContext';
@@ -189,8 +196,6 @@ export default function PassageDetailMarkVersesIsMobile({
189196
currentSegment,
190197
currentSegmentIndex,
191198
setCurrentSegment,
192-
setStepComplete,
193-
gotoNextStep,
194199
rowData,
195200
} = usePassageDetailContext();
196201
const [memory] = useGlobal('memory');
@@ -254,8 +259,6 @@ export default function PassageDetailMarkVersesIsMobile({
254259
saveCompleted,
255260
clearRequested,
256261
clearCompleted,
257-
checkSavedFn,
258-
waitForSave,
259262
} = useContext(UnsavedContext).state;
260263
const hasChanged = useMemo(() => isChanged(verseToolId), [isChanged]);
261264
const projectSegmentSave = useProjectSegmentSave();
@@ -317,16 +320,19 @@ export default function PassageDetailMarkVersesIsMobile({
317320
}
318321
}, [emptyTable, setData]);
319322

320-
const tableSignature = (tableData: ICell[][]) =>
321-
JSON.stringify(
322-
tableData.map((row) =>
323-
row.map((cell) => ({
324-
value: cell.value ?? '',
325-
className: cell.className ?? '',
326-
readOnly: cell.readOnly ?? false,
327-
}))
328-
)
329-
);
323+
const tableSignature = useCallback(
324+
(tableData: ICell[][]) =>
325+
JSON.stringify(
326+
tableData.map((row) =>
327+
row.map((cell) => ({
328+
value: cell.value ?? '',
329+
className: cell.className ?? '',
330+
readOnly: cell.readOnly ?? false,
331+
}))
332+
)
333+
),
334+
[]
335+
);
330336

331337
const media = useMemo(
332338
() => findRecord(memory, 'mediafile', mediafileId) as MediaFileD,
@@ -471,13 +477,6 @@ export default function PassageDetailMarkVersesIsMobile({
471477
// eslint-disable-next-line react-hooks/exhaustive-deps
472478
}, [getPassageRefs, passage]);
473479

474-
const handleComplete = (complete: boolean) => {
475-
waitForSave(undefined, 200).finally(async () => {
476-
await setStepComplete(currentstep, complete);
477-
if (complete) gotoNextStep();
478-
});
479-
};
480-
481480
const collectRefs = useCallback(
482481
(tableData: ICell[][]) => {
483482
const refs: string[] = [];
@@ -579,7 +578,6 @@ export default function PassageDetailMarkVersesIsMobile({
579578
requestAnimationFrame(apply);
580579
}, []);
581580

582-
583581
useEffect(() => {
584582
const ctrl = playerControlsRef.current;
585583
if (ctrl?.isReady()) {
@@ -607,7 +605,9 @@ export default function PassageDetailMarkVersesIsMobile({
607605

608606
const pushUndoSnapshot = useCallback(() => {
609607
const snapshot: MarkVersesSnapshot = {
610-
tableData: cloneTableData(dataRef.current) as MarkVersesSnapshot['tableData'],
608+
tableData: cloneTableData(
609+
dataRef.current
610+
) as MarkVersesSnapshot['tableData'],
611611
segmentsJson: segmentsRef.current,
612612
pastedSegments,
613613
waveSegmentsJson,
@@ -955,11 +955,12 @@ export default function PassageDetailMarkVersesIsMobile({
955955
}
956956
},
957957
[
958-
cloneTableData,
959958
getActiveSegmentForRow,
959+
cloneTableData,
960+
setActiveRowHighlight,
961+
tableSignature,
960962
setCurrentSegment,
961963
setData,
962-
setActiveRowHighlight,
963964
syncProgressFromPlayer,
964965
]
965966
);
@@ -1173,8 +1174,7 @@ export default function PassageDetailMarkVersesIsMobile({
11731174
const change =
11741175
numSegments !== regions.length ||
11751176
tableSignature(previousData) !== tableSignature(newData);
1176-
const addedSegment =
1177-
!init && regions.length > prevRegionCountRef.current;
1177+
const addedSegment = !init && regions.length > prevRegionCountRef.current;
11781178
prevRegionCountRef.current = regions.length;
11791179

11801180
if (change) {
@@ -1207,17 +1207,17 @@ export default function PassageDetailMarkVersesIsMobile({
12071207
passage,
12081208
emptyTable,
12091209
rowCells,
1210-
t.startStop,
1211-
t.reference,
1210+
t,
12121211
collectRefs,
12131212
numSegments,
1213+
tableSignature,
12141214
toolChanged,
12151215
formLim,
12161216
applyActiveRowHighlight,
1217-
setData,
12181217
isChanged,
1219-
seekToRowSegment,
1218+
setData,
12201219
scrollActiveRowIntoView,
1220+
seekToRowSegment,
12211221
]
12221222
);
12231223

@@ -1235,7 +1235,7 @@ export default function PassageDetailMarkVersesIsMobile({
12351235
});
12361236
}, [mediafileId, passageRefsKey, savedVerseSegmentsJson]);
12371237

1238-
const setSegments = () => {
1238+
const setSegments = useCallback(() => {
12391239
const regions: IRegion[] = [];
12401240
dataRef.current.forEach((row, index) => {
12411241
if (index === 0) return;
@@ -1247,15 +1247,15 @@ export default function PassageDetailMarkVersesIsMobile({
12471247
});
12481248
});
12491249
resetSegments(regions);
1250-
};
1250+
}, [getSegmentFromRow]);
12511251

12521252
const flushSetSegments = useCallback(() => {
12531253
if (setSegmentsDebounceRef.current) {
12541254
clearTimeout(setSegmentsDebounceRef.current);
12551255
setSegmentsDebounceRef.current = undefined;
12561256
setSegments();
12571257
}
1258-
}, []);
1258+
}, [setSegments]);
12591259

12601260
const scheduleSetSegments = useCallback(() => {
12611261
if (setSegmentsDebounceRef.current) {
@@ -1265,7 +1265,7 @@ export default function PassageDetailMarkVersesIsMobile({
12651265
setSegmentsDebounceRef.current = undefined;
12661266
setSegments();
12671267
}, REF_SEGMENT_SYNC_DEBOUNCE_MS);
1268-
}, []);
1268+
}, [setSegments]);
12691269

12701270
const flushSetSegmentsRef = useRef(flushSetSegments);
12711271
flushSetSegmentsRef.current = flushSetSegments;
@@ -1315,9 +1315,7 @@ export default function PassageDetailMarkVersesIsMobile({
13151315

13161316
const restoreUndoSnapshot = useCallback(
13171317
(snapshot: MarkVersesSnapshot) => {
1318-
const restoredData = cloneTableData(
1319-
snapshot.tableData as ICell[][]
1320-
);
1318+
const restoredData = cloneTableData(snapshot.tableData as ICell[][]);
13211319
segmentsRef.current = snapshot.segmentsJson;
13221320
suppressVerseResyncFromMediaRef.current = true;
13231321
resettingSegmentsRef.current = true;
@@ -1330,9 +1328,7 @@ export default function PassageDetailMarkVersesIsMobile({
13301328
setPastedSegments(snapshot.segmentsJson);
13311329
}, 40);
13321330
setData(restoredData);
1333-
const restoredRegion = parseCurrentSegmentRegion(
1334-
snapshot.currentSegment
1335-
);
1331+
const restoredRegion = parseCurrentSegmentRegion(snapshot.currentSegment);
13361332
setCurrentSegment(restoredRegion, snapshot.currentSegmentIndex);
13371333
const highlightedRowIndex = findHighlightedRowIndex(restoredData);
13381334
if (highlightedRowIndex > 0) {
@@ -1352,11 +1348,12 @@ export default function PassageDetailMarkVersesIsMobile({
13521348
},
13531349
[
13541350
cloneTableData,
1351+
setData,
13551352
parseCurrentSegmentRegion,
13561353
setCurrentSegment,
1357-
setData,
1358-
toolChanged,
13591354
findHighlightedRowIndex,
1355+
toolChanged,
1356+
getSegmentFromRow,
13601357
]
13611358
);
13621359

@@ -1617,7 +1614,7 @@ export default function PassageDetailMarkVersesIsMobile({
16171614
// eslint-disable-next-line react-hooks/exhaustive-deps
16181615
}, [toolsChanged]);
16191616

1620-
const checkRefs = () => {
1617+
const checkRefs = useCallback(() => {
16211618
const refs = collectRefs(dataRef.current);
16221619
const noSegRefs = dataRef.current
16231620
.filter((_, index) => index > 0)
@@ -1664,26 +1661,14 @@ export default function PassageDetailMarkVersesIsMobile({
16641661
if (noRefSegs) nextIssues.push(t.noReferences);
16651662
if (hasBtRecordings) nextIssues.push(t.btNotUpdated);
16661663
return nextIssues;
1667-
};
1664+
}, [collectRefs, t, hasBtRecordings]);
16681665

16691666
useEffect(() => {
16701667
if (!hasChanged || !hasPermission || savingRef.current) return;
16711668
const issues = checkRefs();
16721669
if (issues.length > 0) return;
16731670
scheduleAutosave();
1674-
}, [toolsChanged, hasChanged, hasPermission, scheduleAutosave]);
1675-
1676-
const handleCancel = () => {
1677-
if (savingRef.current) {
1678-
showMessage(t.canceling);
1679-
canceling.current = true;
1680-
return;
1681-
}
1682-
checkSavedFn(() => {
1683-
toolChanged(verseToolId, false);
1684-
if (hasPermission) handleComplete(true);
1685-
});
1686-
};
1671+
}, [toolsChanged, hasChanged, hasPermission, scheduleAutosave, checkRefs]);
16871672

16881673
const resetSave = () => {
16891674
setResetConfirmOpen(false);

0 commit comments

Comments
 (0)