diff --git a/web/src/components/AudioTab/AudioTab.tsx b/web/src/components/AudioTab/AudioTab.tsx index 076dd7036..25814a34b 100644 --- a/web/src/components/AudioTab/AudioTab.tsx +++ b/web/src/components/AudioTab/AudioTab.tsx @@ -445,12 +445,12 @@ export function AudioTab() { setUploadVisible(false)} multiple={true} finish={afterUpload} cancelled={cancelled} - performedBy={speaker} - onSpeakerChange={handleNameChange} + speaker={speaker} + onSpeaker={handleNameChange} /> ); diff --git a/web/src/components/Discussions/DiscussionCard.tsx b/web/src/components/Discussions/DiscussionCard.tsx index 828e50729..8392c28fc 100644 --- a/web/src/components/Discussions/DiscussionCard.tsx +++ b/web/src/components/Discussions/DiscussionCard.tsx @@ -255,9 +255,9 @@ export const DiscussionCard = (props: IProps) => { const [myChanged, setMyChanged] = useState(false); const segSavingRef = useRef(false); const cardSavingRef = useRef(false); - // commit() handle for the category field; called at save so a newly typed + // saveCategory() handle for the category field; called at save so a newly typed // category is created on submission rather than on blur. - const catCommitRef = useRef<(() => Promise) | null>(null); + const categorySaveRef = useRef<(() => Promise) | null>(null); const [showMove, setShowMove] = useState(false); const [moveTo, setMoveTo] = useState(); const waitForRemoteQueue = useWaitForRemoteQueue(); @@ -756,8 +756,8 @@ export const DiscussionCard = (props: IProps) => { editSubject.length > 0 ? editSubject : tdcs.topic; // Create the category now (at save) if the user typed a new one; on blur it // was only resolved against existing categories. - const catId = catCommitRef.current - ? await catCommitRef.current() + const catId = categorySaveRef.current + ? await categorySaveRef.current() : editCategory; const ops: RecordOperation[] = []; const t = new RecordTransformBuilder(); @@ -1016,7 +1016,7 @@ export const DiscussionCard = (props: IProps) => { initCategory={editCategory} onCategoryChange={onCategoryChange} onNewDraft={onCategoryNewDraft} - commitRef={catCommitRef} + categorySaveRef={categorySaveRef} allowNew={userIsAdmin && (!offline || offlineOnly)} required={false} scripture={ArtCatScr.hide} diff --git a/web/src/components/GraphicPicker.test.tsx b/web/src/components/GraphicPicker.test.tsx index 23ddb001e..9187a93d7 100644 --- a/web/src/components/GraphicPicker.test.tsx +++ b/web/src/components/GraphicPicker.test.tsx @@ -65,23 +65,23 @@ jest.mock('./GraphicUploader', () => { return { mockHandleAddOrSave: handleAddOrSave, GraphicUploader: (props: { - metadata?: React.ReactNode; + metaData?: React.ReactNode; onFiles?: (files: File[]) => void; - mediaUploadControlsRef?: { + controlsRef?: { current: { handleAddOrSave: unknown; handleCancel: unknown; }; }; }) => { - if (props.mediaUploadControlsRef) { - props.mediaUploadControlsRef.current.handleAddOrSave = handleAddOrSave; - props.mediaUploadControlsRef.current.handleCancel = jest.fn(); + if (props.controlsRef) { + props.controlsRef.current.handleAddOrSave = handleAddOrSave; + props.controlsRef.current.handleCancel = jest.fn(); } return (
custom-upload - {props.metadata} + {props.metaData} {/* Deferred flow: pick a file, then Next only advances (no upload here) — the retained selection is uploaded later by the wizard - via submitRef. */} + via controlsRef. */} @@ -305,10 +307,10 @@ jest.mock('./ProjectResourceConfigure', () => ({ __esModule: true, default: ({ onBack, - onOpen, + onClose, }: { onBack?: () => void; - onOpen?: (open: boolean) => void; + onClose?: () => void; }) => (
Configure @@ -317,7 +319,7 @@ jest.mock('./ProjectResourceConfigure', () => ({ configure-back )} -
@@ -469,7 +471,7 @@ describe('AddResourceWizard', () => { }); stageToSelectSections(); - // Choose sections → the wizard fires the deferred upload through submitRef, + // Choose sections → the wizard fires the deferred upload through controlsRef, // which completes → configure step. fireEvent.click(screen.getByText('sections-select')); diff --git a/web/src/components/PassageDetail/Internalization/AddResourceWizard.tsx b/web/src/components/PassageDetail/Internalization/AddResourceWizard.tsx index 6904ee601..e993083e8 100644 --- a/web/src/components/PassageDetail/Internalization/AddResourceWizard.tsx +++ b/web/src/components/PassageDetail/Internalization/AddResourceWizard.tsx @@ -51,7 +51,7 @@ export function AddResourceWizard({ ? w.t.selectPassagesSub.replace('{0}', getOrganizedBy(false)) : w.t.editingFile.replace( '{0}', - safeFileBasename(w.projMedia?.attributes?.originalFile) + safeFileBasename(w.media?.attributes?.originalFile) )} ) : undefined @@ -78,37 +78,40 @@ export function AddResourceWizard({ > w.setRecordingStarted(true)} - isAudioMode={w.isAddingAudioResource} + isAddingAudioResource={w.isAddingAudioResource} active={w.step === WizardStep.Upload} finish={w.afterUpload} beforeUpload={w.handleBeforeUpload} cancelled={w.cancelled} artifactId={w.artifactId} uploadType={w.uploadType} - ready={w.resourceReady} + ready={w.ready} speaker={w.speaker} onSpeaker={w.setSpeaker} - inValue={w.markdownValue} + inValue={w.inValue} eafUrl={w.eafUrl} - defaultFilename={w.filename} - pendingRestore={w.resourcePendingRestore} + defaultFilename={w.defaultFilename} + pendingRestore={w.pendingRestore} onFiles={w.setResourceUploadFiles} deferred={ w.uploadType === UploadType.ProjectResource - ? { onNext: w.handleUploadStepNext, submitRef: w.submitRef } + ? { + onNext: w.handleUploadStepNext, + controlsRef: w.controlsRef, + } : undefined } - validationMessage={w.resourceUploadValidationMessage} + validationMessage={w.validationMessage} metaData={ } @@ -129,7 +132,7 @@ export function AddResourceWizard({ (undefined); const textRef = useRef(undefined); const catIdRef = useRef(undefined); - // commit() handle for the edit dialog's SelectArtifactCategory. Called at save + // saveCategory() handle for the edit dialog's SelectArtifactCategory. Called at save // to create a new category. - const editCatCommitRef = useRef<(() => Promise) | null>(null); + const editCategorySaveRef = useRef<(() => Promise) | null>(null); const descriptionRef = useRef(''); const [resourceKind, setResourceKindx] = useState( @@ -413,8 +413,8 @@ export function PassageDetailArtifacts() { const handleEditSave = async () => { // Create the category now (at save) if the user typed a new one; on blur it // was only resolved against existing categories. - if (editCatCommitRef.current) { - const catId = await editCatCommitRef.current(); + if (editCategorySaveRef.current) { + const catId = await editCategorySaveRef.current(); catIdRef.current = catId; } if (editResource) { @@ -632,10 +632,6 @@ export function PassageDetailArtifacts() { ); }; - const handlePassRes = (newValue: ResourceTypeEnum) => { - setResourceKind(newValue); - }; - const handleEnded = () => { setPlayItem(''); handleItemPlayEnd(); @@ -794,11 +790,11 @@ export function PassageDetailArtifacts() { uploadType={uploadType} initCategory={catIdRef.current || ''} onCategoryChange={handleCategory} - catCommitRef={editCatCommitRef} + categorySaveRef={editCategorySaveRef} initDescription={descriptionRef.current} onDescriptionChange={handleDescription} resourceKind={resourceKind} - onPassResChange={handlePassRes} + onResourceKindChange={setResourceKind} allowGeneralResourceOption={false} onTextChange={handleTextChange} /> diff --git a/web/src/components/PassageDetail/Internalization/PassageDetailsArtifactsMobile.tsx b/web/src/components/PassageDetail/Internalization/PassageDetailsArtifactsMobile.tsx index 6fc1c9340..480c470f2 100644 --- a/web/src/components/PassageDetail/Internalization/PassageDetailsArtifactsMobile.tsx +++ b/web/src/components/PassageDetail/Internalization/PassageDetailsArtifactsMobile.tsx @@ -144,9 +144,9 @@ export function PassageDetailArtifactsMobile() { const mediaRef = useRef(undefined); const textRef = useRef(undefined); const catIdRef = useRef(undefined); - // commit() handle for the edit dialog's SelectArtifactCategory. Called at save + // saveCategory() handle for the edit dialog's SelectArtifactCategory. Called at save // to create a new category. - const editCatCommitRef = useRef<(() => Promise) | null>(null); + const editCategorySaveRef = useRef<(() => Promise) | null>(null); const descriptionRef = useRef(''); const [resourceKind, setResourceKindx] = useState( @@ -413,8 +413,8 @@ export function PassageDetailArtifactsMobile() { const handleEditSave = async () => { // Create the category now (at save) if the user typed a new one; on blur it // was only resolved against existing categories. - if (editCatCommitRef.current) { - const catId = await editCatCommitRef.current(); + if (editCategorySaveRef.current) { + const catId = await editCategorySaveRef.current(); catIdRef.current = catId; } if (editResource) { @@ -632,10 +632,6 @@ export function PassageDetailArtifactsMobile() { ); }; - const handlePassRes = (newValue: ResourceTypeEnum) => { - setResourceKind(newValue); - }; - const handleEnded = () => { setPlayItem(''); handleItemPlayEnd(); @@ -795,11 +791,11 @@ export function PassageDetailArtifactsMobile() { uploadType={uploadType} initCategory={catIdRef.current || ''} onCategoryChange={handleCategory} - catCommitRef={editCatCommitRef} + categorySaveRef={editCategorySaveRef} initDescription={descriptionRef.current} onDescriptionChange={handleDescription} resourceKind={resourceKind} - onPassResChange={handlePassRes} + onResourceKindChange={setResourceKind} allowGeneralResourceOption={false} onTextChange={handleTextChange} wrapPreviewOverflow diff --git a/web/src/components/PassageDetail/Internalization/ProjectResourceConfigure.tsx b/web/src/components/PassageDetail/Internalization/ProjectResourceConfigure.tsx index c5124a973..a68373a29 100644 --- a/web/src/components/PassageDetail/Internalization/ProjectResourceConfigure.tsx +++ b/web/src/components/PassageDetail/Internalization/ProjectResourceConfigure.tsx @@ -199,7 +199,7 @@ interface IProps { candidateItems?: RecordIdentity[]; /** Artifact type id of a derived resource copy (`resource` slug). */ resourceTypeId?: string | null; - onOpen?: (open: boolean) => void; + onClose?: (() => void) | undefined; /** * When set, a "Back" button (the reverse of the selection dialog's Next) is * shown. It returns to SelectSections keeping the media, so the caller must @@ -217,7 +217,7 @@ export const ProjectResourceConfigure = (props: IProps) => { items, candidateItems, resourceTypeId, - onOpen, + onClose, onBack, } = props; const mediafiles = useOrbitData('mediafile'); @@ -384,7 +384,7 @@ export const ProjectResourceConfigure = (props: IProps) => { .finally(() => { setSaving(false); setComplete(0); - onOpen && onOpen(false); + onClose?.(); }); } } diff --git a/web/src/components/PassageDetail/Internalization/ResourceData.tsx b/web/src/components/PassageDetail/Internalization/ResourceData.tsx index fdf7816ef..0690becf8 100644 --- a/web/src/components/PassageDetail/Internalization/ResourceData.tsx +++ b/web/src/components/PassageDetail/Internalization/ResourceData.tsx @@ -57,12 +57,12 @@ interface IProps { resourceKind?: ResourceTypeEnum | undefined; onCategoryChange: (artifactCategoryId: string) => void; onDescriptionChange: (desc: string) => void; - onPassResChange?: ((value: ResourceTypeEnum) => void) | undefined; + onResourceKindChange?: ((value: ResourceTypeEnum) => void) | undefined; onTextChange?: ((text: string) => void) | undefined; allowGeneralResourceOption: boolean; // Forwarded to SelectArtifactCategory so the parent form can create a new // category at submission (rather than on blur). - catCommitRef?: RefObject<(() => Promise) | null> | undefined; + categorySaveRef?: RefObject<(() => Promise) | null> | undefined; wrapPreviewOverflow?: boolean; } export function ResourceData(props: IProps) { @@ -72,13 +72,13 @@ export function ResourceData(props: IProps) { resourceKind = ResourceTypeEnum.sectionResource, onCategoryChange, onDescriptionChange, - onPassResChange, + onResourceKindChange, allowGeneralResourceOption, media, uploadType, onTextChange, wrapPreviewOverflow, - catCommitRef, + categorySaveRef, } = props; // The TextField is uncontrolled (the parent owns the value via // onDescriptionChange); only emptiness is tracked here, for the error state, @@ -114,7 +114,7 @@ export function ResourceData(props: IProps) { ); const handleChange = (event: React.ChangeEvent) => { - onPassResChange?.(radioToResourceKind(event.target.value)); + onResourceKindChange?.(radioToResourceKind(event.target.value)); }; const handleChangeDescription = ( e: React.ChangeEvent @@ -161,11 +161,11 @@ export function ResourceData(props: IProps) { required={false} scripture={ArtCatScr.highlight} type={ArtifactCategoryType.Resource} - commitRef={catCommitRef} + categorySaveRef={categorySaveRef} /> - {onPassResChange && ( + {onResourceKindChange && ( {t.tip1a} ; function renderStep(overrides: Partial = {}) { const props: StepProps = { active: true, - isAudioMode: true, + isAddingAudioResource: true, uploadType: UploadType.Media, cancelled: { current: false }, finish: jest.fn(), @@ -127,14 +127,14 @@ describe('ResourceUploadStep', () => { describe('mode', () => { it('renders the record panel in audio mode, wired to the upload hook', () => { - renderStep({ isAudioMode: true }); + renderStep({ isAddingAudioResource: true }); expect(capturedPanel?.uploadMethod).toBe(mockUploadMethod); expect(capturedContent).toBeUndefined(); }); it('renders the upload content otherwise, wired to the upload hook', () => { - renderStep({ isAudioMode: false }); + renderStep({ isAddingAudioResource: false }); expect(capturedContent?.uploadMethod).toBe(mockUploadMethod); expect(capturedPanel).toBeUndefined(); @@ -144,7 +144,7 @@ describe('ResourceUploadStep', () => { describe('Faithbridge link value', () => { it('shows only the url and sends the transcription to the upload', () => { renderStep({ - isAudioMode: false, + isAddingAudioResource: false, uploadType: UploadType.FaithbridgeLink, inValue: 'https://fb.example/x||hello world', }); @@ -155,7 +155,7 @@ describe('ResourceUploadStep', () => { it('passes inValue through untouched for other upload types', () => { renderStep({ - isAudioMode: false, + isAddingAudioResource: false, uploadType: UploadType.Link, inValue: 'https://example.com/a||b', }); diff --git a/web/src/components/PassageDetail/Internalization/ResourceUploadStep.tsx b/web/src/components/PassageDetail/Internalization/ResourceUploadStep.tsx index ea034e4f3..2fb44b2e3 100644 --- a/web/src/components/PassageDetail/Internalization/ResourceUploadStep.tsx +++ b/web/src/components/PassageDetail/Internalization/ResourceUploadStep.tsx @@ -9,7 +9,7 @@ import type { PendingRestoreInput } from '../../../store/upload/pendingMediaUplo interface IProps { active: boolean; - isAudioMode: boolean; //shows a Record option as well as upload + isAddingAudioResource: boolean; //shows a Record option as well as upload uploadType: UploadType; artifactId?: string | null | undefined; speaker?: string | undefined; @@ -38,7 +38,7 @@ interface IProps { export function ResourceUploadStep(props: IProps) { const { active, - isAudioMode, + isAddingAudioResource, uploadType, artifactId: artifactIdProp, speaker, @@ -103,7 +103,7 @@ export function ResourceUploadStep(props: IProps) { '& > .MuiDialogActions-root > .MuiButton-root': { m: 0 }, }} > - {isAudioMode ? ( + {isAddingAudioResource ? ( {}} uploadType={uploadType} multiple uploadMethod={uploadMedia} diff --git a/web/src/components/PassageDetail/Internalization/useAddResourceWizard.ts b/web/src/components/PassageDetail/Internalization/useAddResourceWizard.ts index e8e006108..231345017 100644 --- a/web/src/components/PassageDetail/Internalization/useAddResourceWizard.ts +++ b/web/src/components/PassageDetail/Internalization/useAddResourceWizard.ts @@ -149,7 +149,7 @@ export function useAddResourceWizard({ launchSource.kind === WizardLaunchKind.Add && launchSource.action === AddResourceAction.Audio; const aiGenerated = launchSource.kind === WizardLaunchKind.FaithBridge; - const markdownValue = + const inValue = launchSource.kind === WizardLaunchKind.FaithBridge ? launchSource.audioUrl ? `${launchSource.audioUrl}||${launchSource.transcript}` @@ -175,21 +175,21 @@ export function useAddResourceWizard({ // The description's single copy (ResourceData's field is uncontrolled). A ref, // not state: it's only read at upload time, so typing needn't re-render. const descriptionRef = useRef(initDescription); - const addCategorySaveRef = useRef<(() => Promise) | null>(null); + const categorySaveRef = useRef<(() => Promise) | null>(null); const pendingResourceSeqRef = useRef(0); const [projSelection, setProjSelection] = useState<{ items: RecordIdentity[]; candidates: RecordIdentity[]; }>({ items: [], candidates: [] }); - const [projMedia, setProjMedia] = useState( + const [media, setMedia] = useState( launchSource.kind === WizardLaunchKind.EditGeneralResource ? launchSource.media : undefined ); // Handle to the (hidden, still-mounted) Upload step's active tab; // SelectSections' Upload button calls it to upload the held file/take. - const submitRef = useRef({ + const controlsRef = useRef({ handleAddOrSave: null, handleCancel: null, }); @@ -209,14 +209,14 @@ export function useAddResourceWizard({ : resourceType) ?? null; const planRec = plan ? getPlan(plan) : null; - const filename = planRec?.attributes?.slug + const defaultFilename = planRec?.attributes?.slug ? `${planRec.attributes.slug}resource` : 'resource'; const isPassageResource = resourceKind === ResourceTypeEnum.passageResource; const isProjectResource = resourceKind === ResourceTypeEnum.projectResource; - const resourcePendingRestore = useCallback(() => { + const pendingRestore = useCallback(() => { // Project resources should not get staged as pending uploads; they need to be configured in one go. if (resourceKind === ResourceTypeEnum.projectResource) { return undefined; @@ -251,10 +251,10 @@ export function useAddResourceWizard({ resourceUploadFiles, resourceKind ); - const resourceUploadValidationMessage = uploadConflict + const validationMessage = uploadConflict ? t.generalResourcesIndividually : ''; - const resourceReady = + const ready = (!descriptionRequiredForResource(undefined, uploadType) || hasDescription) && !uploadConflict; @@ -317,11 +317,11 @@ export function useAddResourceWizard({ } if (projRes.length === 1) { if (areSectionsPreselectedRef.current) { - const media = projRes[0] as MediaFileD; - setProjMedia(media); + const created = projRes[0] as MediaFileD; + setMedia(created); areSectionsPreselectedRef.current = false; setUploading(false); - setSelected(media.id, PlayInPlayer.yes); + setSelected(created.id, PlayInPlayer.yes); setStep(WizardStep.Configure); advanced = true; } @@ -342,20 +342,20 @@ export function useAddResourceWizard({ if (!advanced) onClose(); }; - // Commit the staged new category (if any) right before the real upload. + // Save the staged new category (if any) right before the real upload. const handleBeforeUpload = async () => { pendingResourceSeqRef.current = 0; - if (addCategorySaveRef.current) { - categoryIdRef.current = await addCategorySaveRef.current(); + if (categorySaveRef.current) { + categoryIdRef.current = await categorySaveRef.current(); // Cleared so a retry can't create a duplicate category. - addCategorySaveRef.current = null; + categorySaveRef.current = null; } }; // Upload step Next (general resource): go to SelectSections without uploading; - // the hidden Upload step keeps the file/take until submitRef fires it. + // the hidden Upload step keeps the file/take until controlsRef fires it. const handleUploadStepNext = () => { - setProjMedia(undefined); + setMedia(undefined); setStep(WizardStep.SelectSections); }; @@ -364,10 +364,10 @@ export function useAddResourceWizard({ candidates: RecordIdentity[] ) => { setProjSelection({ items, candidates }); - if (isAddingAudioResource && !projMedia) { + if (isAddingAudioResource && !media) { // Nothing uploaded yet. Fire the held upload now. SelectSections shows a // spinner until afterUpload advances or re-enables it. - const submit = submitRef.current.handleAddOrSave; + const submit = controlsRef.current.handleAddOrSave; if (!submit) return; cancelled.current = false; areSectionsPreselectedRef.current = true; @@ -396,7 +396,7 @@ export function useAddResourceWizard({ // SelectSections Back (add flow only): back to Upload to change the audio. // Any already-uploaded media is left in place; a replacement creates a new one. const handleSelectSectionsBack = () => { - setProjMedia(undefined); + setMedia(undefined); setStep(WizardStep.Upload); }; @@ -409,7 +409,7 @@ export function useAddResourceWizard({ setHasDescription(Boolean(desc.trim())); }; - const handlePassRes = (newValue: ResourceTypeEnum) => { + const handleResourceKind = (newValue: ResourceTypeEnum) => { setResourceKind(newValue); if (newValue === ResourceTypeEnum.projectResource) { setUploadType(UploadType.ProjectResource); @@ -488,24 +488,24 @@ export function useAddResourceWizard({ isAddingAudioResource, // seeded upload-step values uploadType, - resourceReady, + ready, speaker, setSpeaker, - markdownValue, + inValue, eafUrl: aiGenerated ? AIGenerated : '', - filename, - resourceUploadValidationMessage, + defaultFilename, + validationMessage, resourceKind, resourceType, // Seed only: ResourceData owns the live value (reported via handleDescription). initDescription, - projMedia, - projIdentity: projSelection.items, - projCandidate: projSelection.candidates, + media, + items: projSelection.items, + candidateItems: projSelection.candidates, cancelled, artifactId, - addCategorySaveRef, - submitRef, + categorySaveRef, + controlsRef, // section-select initialItems, uploading, @@ -515,11 +515,11 @@ export function useAddResourceWizard({ setRecordingStarted, afterUpload, handleBeforeUpload, - resourcePendingRestore, + pendingRestore, setResourceUploadFiles, handleDescription, handleCategory, - handlePassRes, + handleResourceKind, handleUploadStepNext, handleSectionsSelected, handleSelectSectionsBack, diff --git a/web/src/components/PassageDetail/PassageDetailItem.tsx b/web/src/components/PassageDetail/PassageDetailItem.tsx index f29234186..043eb0b15 100644 --- a/web/src/components/PassageDetail/PassageDetailItem.tsx +++ b/web/src/components/PassageDetail/PassageDetailItem.tsx @@ -297,9 +297,6 @@ export function PassageDetailItem(props: IProps) { setPlayItem(''); }; - const handleUploadVisible = (v: boolean) => { - setUploadVisible(v); - }; const handleUpload = () => { if (canSave) { showMessage(t.saveFirst); @@ -587,7 +584,7 @@ export function PassageDetailItem(props: IProps) { setUploadVisible(false)} multiple={false} finish={afterUpload} cancelled={cancelled} @@ -595,7 +592,7 @@ export function PassageDetailItem(props: IProps) { sourceSegments={JSON.stringify(getCurrentSegment())} sourceMediaId={mediafileId} artifactState={artifactState} - performedBy={speaker} + speaker={speaker} topic={topic} />
diff --git a/web/src/components/PassageDetail/PassageDetailRecord.tsx b/web/src/components/PassageDetail/PassageDetailRecord.tsx index a844134b2..a2a5cbd06 100644 --- a/web/src/components/PassageDetail/PassageDetailRecord.tsx +++ b/web/src/components/PassageDetail/PassageDetailRecord.tsx @@ -333,9 +333,6 @@ export function PassageDetailRecord(props: IProps) { const handleAudacityClose = () => { setAudacityVisible(false); }; - const handleUploadVisible = (v: boolean) => { - setUploadVisible(v); - }; const handleUpload = () => { saveIfChanged(() => { void confirmIfPending().then((ok) => { @@ -469,13 +466,13 @@ export function PassageDetailRecord(props: IProps) { setUploadVisible(false)} multiple={false} finish={afterUpload} cancelled={cancelled} passageId={passageId} - performedBy={speaker} - onSpeakerChange={handleNameChange} + speaker={speaker} + onSpeaker={handleNameChange} skipImportExportWait /> void; // for the wizard to trigger the real upload later - submitRef: React.RefObject; + controlsRef: React.RefObject; } export function PassageRecordPanel(props: IPassageRecordPanelProps) { @@ -81,7 +81,7 @@ export function PassageRecordPanel(props: IPassageRecordPanelProps) { onStartRecording, } = props; const onNext = deferred?.onNext; - const controlsRef = deferred?.submitRef; + const controlsRef = deferred?.controlsRef; const resourceStrings: IPassageDetailArtifactsStrings = useSelector( resourceSelector, shallowEqual @@ -219,7 +219,6 @@ export function PassageRecordPanel(props: IPassageRecordPanelProps) { {}} uploadType={uploadType} primaryButtonText={primaryButtonText} onNext={onNext} diff --git a/web/src/components/ProvideRights.tsx b/web/src/components/ProvideRights.tsx index 5a948e72b..7d31bb128 100644 --- a/web/src/components/ProvideRights.tsx +++ b/web/src/components/ProvideRights.tsx @@ -278,9 +278,6 @@ export function ProvideRights(props: IProps) { ); }; - const handleUploadVisible = (v: boolean) => { - setUploadVisible(v); - }; const handleUpload = () => { if (canSave) { showMessage(t.saveFirst); @@ -336,12 +333,12 @@ export function ProvideRights(props: IProps) { setUploadVisible(false)} multiple={false} finish={afterUpload} cancelled={cancelled} artifactState={artifactState} - performedBy={speaker} + speaker={speaker} planId={planId} uploadType={UploadType.IntellectualProperty} audioOnly={aiip} diff --git a/web/src/components/ResourceEdit/ResourceCategory.tsx b/web/src/components/ResourceEdit/ResourceCategory.tsx index 0e1eda30a..34081909e 100644 --- a/web/src/components/ResourceEdit/ResourceCategory.tsx +++ b/web/src/components/ResourceEdit/ResourceCategory.tsx @@ -5,11 +5,11 @@ import { ArtifactCategoryType } from '../../crud/useArtifactCategory'; interface IProps extends IResourceState { // Forwarded so the wizard can create a new category at save (not on blur). - commitRef?: RefObject<(() => Promise) | null> | undefined; + categorySaveRef?: RefObject<(() => Promise) | null> | undefined; } export const ResourceCategory = (props: IProps) => { - const { state, setState, commitRef } = props; + const { state, setState, categorySaveRef } = props; const { category, note } = state; const handleChange = (category: string) => { @@ -35,7 +35,7 @@ export const ResourceCategory = (props: IProps) => { onNewDraft={setState ? handleNewDraft : undefined} required={false} allowNew - commitRef={commitRef} + categorySaveRef={categorySaveRef} /> ); }; diff --git a/web/src/components/ResourceEdit/ResourceOverview.tsx b/web/src/components/ResourceEdit/ResourceOverview.tsx index 2e3a14c06..777730f3f 100644 --- a/web/src/components/ResourceEdit/ResourceOverview.tsx +++ b/web/src/components/ResourceEdit/ResourceOverview.tsx @@ -74,7 +74,7 @@ interface IProps extends IDialog { onLink?: (link: SharedResourceD) => Promise; onUnlink?: () => Promise | void; contentReadOnly?: boolean; - // Paint Saving and hold the sheet rebuild before category commit / orbit write. + // Paint Saving and hold the sheet rebuild before category save / orbit write. onSaving?: (saving: boolean) => void; } @@ -102,9 +102,9 @@ export default function ResourceOverview(props: IProps) { // (TT-7732). The ref blocks a click that lands before disabled paints. const savingRef = useRef(false); const [saving, setSaving] = React.useState(false); - // commit() handle for the category field; called at save so a newly typed + // saveCategory() handle for the category field; called at save so a newly typed // category is created on submission rather than on blur. - const catCommitRef = useRef<(() => Promise) | null>(null); + const categorySaveRef = useRef<(() => Promise) | null>(null); const { getOrgDefault, setOrgDefault, canSetOrgDefault } = useOrgDefaults(); const [findNote, setFindNote] = React.useState(false); const ts: ISharedStrings = useSelector(sharedSelector, shallowEqual); @@ -176,14 +176,14 @@ export default function ResourceOverview(props: IProps) { const handleAdd = async () => { if (savingRef.current) return; setAddBusy(true); - // Saving has to paint before category commit. A new category used to wait + // Saving has to paint before category save. A new category used to wait // on the remote queue here, so the snack never appeared (TT-7730). onSaving?.(true); try { // Create the category now (at save) if the user typed a new one; on blur it // was only resolved against existing categories. - const category = catCommitRef.current - ? await catCommitRef.current() + const category = categorySaveRef.current + ? await categorySaveRef.current() : state.category; await Promise.resolve(onCommit({ ...state, category })); } catch (err) { @@ -241,7 +241,7 @@ export default function ResourceOverview(props: IProps) { {!isNote ? ( diff --git a/web/src/components/Sheet/ScriptureTable.tsx b/web/src/components/Sheet/ScriptureTable.tsx index 2aa6664ec..37766fd2e 100644 --- a/web/src/components/Sheet/ScriptureTable.tsx +++ b/web/src/components/Sheet/ScriptureTable.tsx @@ -637,10 +637,6 @@ export function ScriptureTable(props: Readonly) { }); }; - const handleUploadVisible = (v: boolean) => { - setUploadVisible(v); - }; - const handleUpload = (i: number) => () => { saveIfChanged(() => { showUpload(i); @@ -1503,7 +1499,7 @@ export function ScriptureTable(props: Readonly) { )} setUploadVisible(false)} multiple={false} finish={afterUpload} cancelled={cancelled} @@ -1511,8 +1507,8 @@ export function ScriptureTable(props: Readonly) { related(uploadItem.current?.sharedResource, 'passage') ?? uploadItem.current?.passage?.id } - performedBy={speaker} - onSpeakerChange={handleNameChange} + speaker={speaker} + onSpeaker={handleNameChange} /> Promise) | null> | undefined; + // created on save rather than on blur. + categorySaveRef?: RefObject<(() => Promise) | null> | undefined; // Fires as the user types in an allowNew field, i.e. whenever the field holds - // text that only commit() will resolve to a category id. Parents that gate + // text that only saveCategory() will resolve to a category id. Parents that gate // their Save button on a "changed" flag would otherwise never enable it for a // new-category-only edit; they use this to mark themselves dirty. onNewDraft?: (() => void) | undefined; @@ -67,7 +67,7 @@ export const SelectArtifactCategory = (props: IProps) => { scripture, type, disabled, - commitRef, + categorySaveRef, onNewDraft, } = props; const artifactCategories = @@ -87,7 +87,7 @@ export const SelectArtifactCategory = (props: IProps) => { IArtifactCategory[] >([]); const [gettingCategories, setGettingCategories] = useState(true); - const committingRef = useRef(false); + const savingRef = useRef(false); const currentName = artifactCategorys.find((c) => c.id === categoryId)?.category ?? ''; const [inputVal, setInputVal] = useState(currentName); @@ -135,7 +135,7 @@ export const SelectArtifactCategory = (props: IProps) => { // Resolve a chosen/typed category name to an existing category id. Called on // blur and on change. Deliberately does NOT create new categories — that is - // deferred to commit() (form submission) so navigating away without saving + // deferred to saveCategory() (form submission) so navigating away without saving // never leaves an orphaned category behind. const resolveExisting = (raw: string | null) => { const name = (raw ?? '').trim(); @@ -158,13 +158,13 @@ export const SelectArtifactCategory = (props: IProps) => { setInputVal(currentName); return; } - // allowNew + a new name: keep the typed text as-is and wait for commit(). + // allowNew + a new name: keep the typed text as-is and wait for saveCategory(). }; // Resolve the current input to a category id, creating a new category when // the typed name matches none. Intended to run at form submission via - // commitRef. Returns the resolved id (empty string when the field is blank). - const commit = async (): Promise => { + // categorySaveRef. Returns the resolved id (empty string when the field is blank). + const saveCategory = async (): Promise => { const name = inputVal.trim(); // Field unchanged from the committed category — keep its id as-is rather // than re-resolving by name. Re-resolving could silently drop the category @@ -190,8 +190,8 @@ export const SelectArtifactCategory = (props: IProps) => { setInputVal(currentName); return categoryId; } - if (committingRef.current) return categoryId; - committingRef.current = true; + if (savingRef.current) return categoryId; + savingRef.current = true; try { const newId = await addNewArtifactCategory(name, type); const cats = await getCategorys(); @@ -209,18 +209,18 @@ export const SelectArtifactCategory = (props: IProps) => { } return categoryId; } finally { - committingRef.current = false; + savingRef.current = false; } }; - // Expose commit() to the parent form. No dependency array: re-assign every - // render so the closure stays current; clear on unmount so a stale commit is + // Expose saveCategory() to the parent form. No dependency array: re-assign every + // render so the closure stays current; clear on unmount so a stale save is // never invoked once the field is gone. useEffect(() => { - if (!commitRef) return; - commitRef.current = commit; + if (!categorySaveRef) return; + categorySaveRef.current = saveCategory; return () => { - commitRef.current = null; + categorySaveRef.current = null; }; }); @@ -238,7 +238,7 @@ export const SelectArtifactCategory = (props: IProps) => { inputValue={inputVal} onInputChange={(_e, v, reason) => { setInputVal(v); - // A typed name isn't resolved to an id until commit(), so + // A typed name isn't resolved to an id until saveCategory(), so // onCategoryChange won't fire; tell the parent it's dirty so Save can // enable. Only real keystrokes count, not the programmatic 'reset' MUI // fires when the committed value changes; and without allowNew a typed diff --git a/web/src/components/TitleTabs.tsx b/web/src/components/TitleTabs.tsx index 39bed8282..f5d43e9d5 100644 --- a/web/src/components/TitleTabs.tsx +++ b/web/src/components/TitleTabs.tsx @@ -249,7 +249,7 @@ const TitleTabs = (props: IProps) => { setFiles(files)} diff --git a/web/src/components/TitleUploader.tsx b/web/src/components/TitleUploader.tsx index 10f6fd5fc..a0ba05481 100644 --- a/web/src/components/TitleUploader.tsx +++ b/web/src/components/TitleUploader.tsx @@ -7,7 +7,7 @@ import { mediaTitleSelector } from '../selector'; interface IProps { isOpen: boolean; - onOpen: (visible: boolean) => void; + onClose: () => void; hasRights?: boolean; // required for upload cancelled: React.RefObject; uploadMethod: (files: File[]) => Promise; @@ -15,11 +15,12 @@ interface IProps { } export function TitleUploader(props: IProps) { - const { isOpen, onOpen, cancelled, hasRights, uploadMethod, onFiles } = props; + const { isOpen, onClose, cancelled, hasRights, uploadMethod, onFiles } = + props; const t: IMediaTitleStrings = useSelector(mediaTitleSelector, shallowEqual); const uploadCancel = () => { - onOpen(false); + onClose(); // eslint-disable-next-line react-hooks/immutability if (cancelled) cancelled.current = true; restoreScroll(); @@ -27,7 +28,7 @@ export function TitleUploader(props: IProps) { return isOpen ? ( void; + onClose: () => void; finish?: ((mediaRemoteIds?: string[]) => Promise) | undefined; // logic when upload complete cancelled: React.RefObject; multiple?: boolean | undefined; @@ -21,8 +21,8 @@ interface IProps { planId?: string | undefined; sourceMediaId?: string | undefined; sourceSegments?: string | undefined; - performedBy?: string | undefined; - onSpeakerChange?: ((performedBy: string) => void) | undefined; + speaker?: string | undefined; + onSpeaker?: ((speaker: string) => void) | undefined; topic?: string | undefined; uploadType?: UploadType | undefined; audioOnly?: boolean | undefined; @@ -39,7 +39,7 @@ export const Uploader = (props: IProps) => { noBusy, skipImportExportWait, isOpen, - onOpen, + onClose, cancelled, multiple, importList, @@ -48,8 +48,8 @@ export const Uploader = (props: IProps) => { planId, sourceMediaId, sourceSegments, - performedBy, - onSpeakerChange, + speaker, + onSpeaker, topic, uploadType, audioOnly, @@ -69,17 +69,13 @@ export const Uploader = (props: IProps) => { return planId || plan; }, [passageId, planId, plan, memory]); - const handleSpeakerChange = (speaker: string) => { - onSpeakerChange && onSpeakerChange(speaker); - }; - // Close the dialog once the batch is done (even if `finish` throws), as the // pre-hook Uploader did; the dialog itself only clears its progress on failure. const finishAndClose = async (mediaRemoteIds?: string[]) => { try { await finish?.(mediaRemoteIds); } finally { - onOpen(false); + onClose(); } }; @@ -92,7 +88,7 @@ export const Uploader = (props: IProps) => { localPlanId: resolvedLocalPlanId, sourceMediaId, sourceSegments, - performedBy, + performedBy: speaker, topic, }, uploadType, @@ -110,7 +106,7 @@ export const Uploader = (props: IProps) => { }); const uploadCancel = () => { - onOpen(false); + onClose(); if (cancelled) cancelled.current = true; restoreScroll(); }; @@ -121,17 +117,20 @@ export const Uploader = (props: IProps) => { {!hasImport && ( {})) : undefined } audioOnly={audioOnly} diff --git a/web/src/utils/useCompression.ts b/web/src/utils/useCompression.ts index f7a7b6f92..1a54cc1ae 100644 --- a/web/src/utils/useCompression.ts +++ b/web/src/utils/useCompression.ts @@ -31,7 +31,7 @@ export interface CompressionProps { dimension: number[]; defaultFilename?: string; finish?: (images: CompressedImages[]) => void; - onOpen?: (visible: boolean) => void; + onClose?: (() => void) | undefined; } export const useCompression = ({ @@ -40,7 +40,7 @@ export const useCompression = ({ dimension, defaultFilename, finish, - onOpen, + onClose, }: CompressionProps) => { const t: IMediaTabStrings = useSelector(mediaTabSelector, shallowEqual); const [errorReporter] = useGlobal('errorReporter'); @@ -110,7 +110,7 @@ export const useCompression = ({ } } if (finish) finish(results); - onOpen?.(false); + onClose?.(); }; return { showFile, uploadMedia };