@@ -15,11 +15,10 @@ import {
1515 Stack ,
1616 BoxProps ,
1717} from '@mui/material' ;
18- import DeleteIcon from '@mui/icons-material/Delete ' ;
18+ import DeleteIcon from '@mui/icons-material/DeleteOutlined ' ;
1919import PlayArrowIcon from '@mui/icons-material/PlayArrow' ;
2020import PauseIcon from '@mui/icons-material/Pause' ;
2121import ArrowForwardIcon from '@mui/icons-material/ArrowForward' ;
22- import { FaEarListen } from 'react-icons/fa6' ;
2322import { IoMdBarcode } from 'react-icons/io' ;
2423import { useContext , useEffect , useMemo , useRef , useState } from 'react' ;
2524import {
@@ -133,9 +132,14 @@ export function PassageDetailItem(props: IProps) {
133132 const isPhraseBackTranslation = slugs . includes (
134133 ArtifactTypeSlug . PhraseBackTranslation
135134 ) ;
136- const [ activity , setActivity ] = useState < Activity > ( ( ) =>
135+ const [ activity , setActivityx ] = useState < Activity > ( ( ) =>
137136 isPhraseBackTranslation ? Activity . Preview : Activity . Listen
138137 ) ;
138+ const activityRef = useRef < Activity > ( activity ) ;
139+ const setActivity = ( activity : Activity ) => {
140+ setActivityx ( activity ) ;
141+ activityRef . current = activity ;
142+ } ;
139143 const [ statusText , setStatusText ] = useState ( '' ) ;
140144 const [ canSave , setCanSave ] = useState ( false ) ;
141145 const [ defaultFilename , setDefaultFileName ] = useState ( '' ) ;
@@ -226,7 +230,9 @@ export function PassageDetailItem(props: IProps) {
226230
227231 const mediafileId = useMemo ( ( ) => {
228232 return playerMediafile ?. id ?? '' ;
229- } , [ playerMediafile ] ) ;
233+ // this seemed to need to refresh when the passage and shared resource were updated
234+ // eslint-disable-next-line react-hooks/exhaustive-deps
235+ } , [ playerMediafile , passage , sharedResource ] ) ;
230236 useEffect ( ( ) => {
231237 if ( segments ) {
232238 const def = getOrgDefault ( segments ) as IRegionParams ;
@@ -249,7 +255,7 @@ export function PassageDetailItem(props: IProps) {
249255 ArtifactTypeSlug . PhraseBackTranslation === recordType &&
250256 ( segString || '{}' ) !== '{}'
251257 ) {
252- setTimeout ( ( ) => handleSave ( ) , 100 ) ;
258+ setTimeout ( ( ) => handleSave ( ) , 500 ) ;
253259 }
254260 toolChanged ( toolId , canSave ) ;
255261 // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -281,7 +287,7 @@ export function PassageDetailItem(props: IProps) {
281287 } ;
282288
283289 useEffect ( ( ) => {
284- if ( hasBtRecordings && activity === Activity . Preview ) {
290+ if ( hasBtRecordings && activityRef . current === Activity . Preview ) {
285291 setActivity ( Activity . Listen ) ;
286292 }
287293 // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -371,7 +377,7 @@ export function PassageDetailItem(props: IProps) {
371377 //from recorder
372378 const afterUploadCb = async ( mediaId : string | undefined ) => {
373379 afterUpload ( '' , mediaId ? [ mediaId ] : undefined ) ;
374- if ( activity === Activity . Record ) {
380+ if ( activityRef . current === Activity . Record ) {
375381 setActivity ( Activity . Next ) ;
376382 }
377383 } ;
@@ -432,8 +438,10 @@ export function PassageDetailItem(props: IProps) {
432438 setConfirm ( '' ) ;
433439 } ;
434440
441+ const isRecording = ( ) =>
442+ recorderRecordingRef . current || recorderPlayingRef . current ;
435443 const updateRecorderBusy = ( ) => {
436- setRecording ( recorderRecordingRef . current || recorderPlayingRef . current ) ;
444+ setRecording ( isRecording ( ) ) ;
437445 } ;
438446 const handleRecorderRecording = ( recording : boolean ) => {
439447 const wasRecording = recorderRecordingRef . current ;
@@ -451,8 +459,8 @@ export function PassageDetailItem(props: IProps) {
451459 const handleSegmentFinished = ( ) => {
452460 if (
453461 segments &&
454- activity !== Activity . Record &&
455- activity !== Activity . Preview
462+ activityRef . current !== Activity . Record &&
463+ activityRef . current !== Activity . Preview
456464 ) {
457465 setActivity ( Activity . Record ) ;
458466 }
@@ -523,7 +531,7 @@ export function PassageDetailItem(props: IProps) {
523531 const flushDiscussionLeft = discussOpen && ! showSideBySide ;
524532
525533 useEffect ( ( ) => {
526- if ( activity !== Activity . Preview ) {
534+ if ( activityRef . current !== Activity . Preview ) {
527535 previewStartedRef . current = false ;
528536 }
529537 } , [ activity ] ) ;
@@ -540,7 +548,7 @@ export function PassageDetailItem(props: IProps) {
540548
541549 useEffect ( ( ) => {
542550 if (
543- activity === Activity . Preview &&
551+ activityRef . current === Activity . Preview &&
544552 previewStartedRef . current &&
545553 ! playing &&
546554 playerDuration > 0 &&
@@ -570,8 +578,8 @@ export function PassageDetailItem(props: IProps) {
570578 if ( ! playing ) previewStartedRef . current = true ;
571579 playerControlsRef . current ?. togglePlay ( ) ;
572580 } }
573- disabled = { playerDuration === 0 }
574- highlight = { activity === Activity . Preview }
581+ disabled = { playerDuration === 0 || isRecording ( ) }
582+ highlight = { activityRef . current === Activity . Preview }
575583 sx = { { py : '2px' , px : '4px' } }
576584 >
577585 { playing ? < PauseIcon /> : < PlayArrowIcon /> }
@@ -591,12 +599,12 @@ export function PassageDetailItem(props: IProps) {
591599 : undefined
592600 }
593601 forceRegionOnly = {
594- activity === Activity . Preview ? false : Boolean ( segments )
602+ activityRef . current === Activity . Preview ? false : Boolean ( segments )
595603 }
596604 highlightAutoSegment = {
597605 isPhraseBackTranslation &&
598606 mobileView &&
599- activity === Activity . Segment
607+ activityRef . current === Activity . Segment
600608 }
601609 onAutoSegment = { ( ) => {
602610 if ( isPhraseBackTranslation && mobileView ) {
@@ -616,6 +624,9 @@ export function PassageDetailItem(props: IProps) {
616624 onDuration = { setPlayerDuration }
617625 onSegmentFinished = { handleSegmentFinished }
618626 onInteraction = { ( ) => {
627+ if ( activityRef . current === Activity . Segment ) {
628+ setActivity ( Activity . Listen ) ;
629+ }
619630 showSegmentsChangedMessage ( ) ;
620631 userSegmentInteractionRef . current = true ;
621632 } }
@@ -645,7 +656,7 @@ export function PassageDetailItem(props: IProps) {
645656 < IconButton
646657 aria-label = { isRecorderPlaying ? 'Pause' : 'Play' }
647658 onClick = { ( ) => recorderControlsRef . current ?. togglePlay ( ) }
648- disabled = { recorderDuration === 0 }
659+ disabled = { recorderDuration === 0 || isRecording ( ) }
649660 sx = { { pl : 0 } }
650661 >
651662 { isRecorderPlaying ? < PauseIcon /> : < PlayArrowIcon /> }
@@ -704,6 +715,7 @@ export function PassageDetailItem(props: IProps) {
704715 id = "speaker"
705716 label = { t . speaker }
706717 value = { speaker }
718+ disabled = { isRecording ( ) || playing }
707719 onChange = { handleChangeSpeaker }
708720 sx = { smallInputProps }
709721 />
@@ -714,6 +726,7 @@ export function PassageDetailItem(props: IProps) {
714726 setActivity ( Activity . Listen ) ;
715727 recorderControlsRef . current ?. deleteRecording ( ) ;
716728 } }
729+ disabled = { isRecording ( ) || playing }
717730 >
718731 < DeleteIcon />
719732 </ IconButton >
@@ -744,10 +757,10 @@ export function PassageDetailItem(props: IProps) {
744757 setActivity ( Activity . Listen ) ;
745758 playerControlsRef . current ?. togglePlay ( ) ;
746759 } }
747- disabled = { false }
748- highlight = { activity === Activity . Listen }
760+ disabled = { isRecording ( ) }
761+ highlight = { activityRef . current === Activity . Listen }
749762 >
750- < FaEarListen />
763+ { playing ? < PauseIcon /> : < PlayArrowIcon /> }
751764 </ HighlightButton >
752765 < RecordButton
753766 recording = { recorderRecordingRef . current }
@@ -769,15 +782,17 @@ export function PassageDetailItem(props: IProps) {
769782 showText = { showTextRef . current }
770783 hasRecording = { Boolean ( currentSegmentMediaId ) }
771784 isStopLogic = { true }
772- active = { activity === Activity . Record }
785+ active = { true }
773786 />
774787 < HighlightButton
775788 ariaLabel = "Next Segment"
776789 onClick = { ( ) => {
777790 handleNextSegmentClick ( ) ;
778791 } }
779- disabled = { false }
780- highlight = { activity === Activity . Next }
792+ disabled = {
793+ isRecording ( ) || playing || Boolean ( toolChanged ( toolId ) )
794+ }
795+ highlight = { activityRef . current === Activity . Next }
781796 >
782797 < ArrowForwardIcon />
783798 </ HighlightButton >
0 commit comments