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 + } = useResourceUploadContext(); + const isProject = uploadType === UploadType.ProjectResource; + const onNext = deferred?.onNext; + const controlsRef = deferred?.controlsRef; + // The body stays mounted and holds its own selection; invoking the + // exposed submit drives a successful upload (finish with one id), as the + // real upload's `finish` would. The wizard calls this from SelectSections. + if (controlsRef) { + controlsRef.current.handleAddOrSave = () => finish?.(['media-1']); + } + return ( + <> + {active && ( +
+ uploader-open + {metaData} + + + {/* Deferred flow: pick a file, then Next only advances (no upload here) — the retained selection is uploaded later by the wizard - via submitRef. */} - - {/* A real recording reports recording-start (onStartRecording) + via controlsRef. */} + + {/* A real recording reports recording-start (onStartRecording) when it begins, before Next advances. */} - - - {validationMessage &&
{validationMessage}
} - -
- )} - - ); - }, + + + {validationMessage &&
{validationMessage}
} + +
+ )} + + ); }; + MockResourceUploadStep.displayName = 'MockResourceUploadStep'; + return { __esModule: true, default: MockResourceUploadStep }; }); jest.mock('./ResourceData', () => { @@ -241,10 +231,10 @@ jest.mock('./ResourceData', () => { __esModule: true, default: ({ onDescriptionChange, - onPassResChange, + onResourceKindChange, }: { onDescriptionChange: (d: string) => void; - onPassResChange?: (k: number) => void; + onResourceKindChange?: (k: number) => void; }) => (
@@ -305,10 +297,10 @@ jest.mock('./ProjectResourceConfigure', () => ({ __esModule: true, default: ({ onBack, - onOpen, + onClose, }: { onBack?: () => void; - onOpen?: (open: boolean) => void; + onClose?: () => void; }) => (
Configure @@ -317,7 +309,7 @@ jest.mock('./ProjectResourceConfigure', () => ({ configure-back )} -
@@ -469,7 +461,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..0e8ecf9d7 100644 --- a/web/src/components/PassageDetail/Internalization/AddResourceWizard.tsx +++ b/web/src/components/PassageDetail/Internalization/AddResourceWizard.tsx @@ -1,4 +1,5 @@ import ResourceUploadStep from './ResourceUploadStep'; +import { ResourceUploadContext } from './ResourceUploadContext'; import BigDialog from '../../../hoc/BigDialog'; import { BigDialogBp } from '../../../hoc/BigDialogBp'; import SelectSections from './SelectSections'; @@ -51,7 +52,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 @@ -66,7 +67,7 @@ export function AddResourceWizard({ > <> {/* Step 1: stays mounted across the flow (gets css-hidden on other steps) so a - recorded take survives Next→Back (see PassageRecordPanel).*/} + recorded take survives Next→Back (see ResourceRecordPanel).*/} {launchSource.kind !== WizardLaunchKind.EditGeneralResource && ( - w.setRecordingStarted(true)} - isAudioMode={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} - speaker={w.speaker} - onSpeaker={w.setSpeaker} - inValue={w.markdownValue} - eafUrl={w.eafUrl} - defaultFilename={w.filename} - pendingRestore={w.resourcePendingRestore} - onFiles={w.setResourceUploadFiles} - deferred={ - w.uploadType === UploadType.ProjectResource - ? { onNext: w.handleUploadStepNext, submitRef: w.submitRef } - : undefined - } - validationMessage={w.resourceUploadValidationMessage} - metaData={ - - } - /> + w.setRecordingStarted(true), + uploadType: w.uploadType, + artifactId: w.artifactId, + defaultFilename: w.defaultFilename, + eafUrl: w.eafUrl, + inValue: w.inValue, + speaker: w.speaker, + onSpeaker: w.setSpeaker, + ready: w.ready, + validationMessage: w.validationMessage, + onFiles: w.setResourceUploadFiles, + metaData: ( + + ), + finish: w.afterUpload, + beforeUpload: w.handleBeforeUpload, + cancelled: w.cancelled, + pendingRestore: w.pendingRestore, + deferred: + w.uploadType === UploadType.ProjectResource + ? { + onNext: w.handleUploadStepNext, + controlsRef: w.controlsRef, + } + : undefined, + }} + > + + )} {/* Step 2: SelectSections stays mounted while the dialog is open @@ -129,7 +136,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} (({ theme }) => ({ marginRight: theme.spacing(2), @@ -35,37 +32,24 @@ const StatusMessage = styled(Typography)(({ theme }) => ({ marginBottom: '0.35em', })); -export interface IPassageRecordPanelProps { - active: boolean; - artifactId: string | null; - finish?: ((mediaRemoteIds?: string[]) => void | Promise) | undefined; - metaData?: React.JSX.Element | undefined; - defaultFilename: string; - ready?: boolean | undefined; // false disables the save/upload button - speaker?: string | undefined; - onSpeaker?: ((speaker: string) => void) | undefined; - onFiles?: ((files: File[]) => void) | undefined; - uploadType: UploadType; +// Everything else comes from ResourceUploadContext; these two are built by +// ResourceUploadStep itself. +export interface IResourceRecordPanelProps { + // The Upload tab's useMediaUpload instance (owned by ResourceUploadStep). uploadMethod: ((files: File[]) => void | boolean | Promise) | undefined; - validationMessage?: string | undefined; - pendingRestore?: import('../store/upload/pendingMediaUploads').PendingRestoreInput; - beforeUpload?: (() => Promise) | undefined; - deferred?: IDeferredUpload | undefined; - onStartRecording?: (() => void) | undefined; + // The recorder's finish: the wizard's finish, wrapped to set `cancelled`. + finish: (mediaRemoteIds?: string[]) => Promise; } -export interface IDeferredUpload { - onNext: () => void; - // for the wizard to trigger the real upload later - submitRef: React.RefObject; -} - -export function PassageRecordPanel(props: IPassageRecordPanelProps) { +/** The add-resource wizard's Upload | Record body for audio resources. */ +export function ResourceRecordPanel({ + uploadMethod, + finish, +}: IResourceRecordPanelProps) { const { active, artifactId, - finish, defaultFilename, ready, metaData, @@ -73,15 +57,14 @@ export function PassageRecordPanel(props: IPassageRecordPanelProps) { onSpeaker, onFiles, uploadType, - uploadMethod, validationMessage, pendingRestore, beforeUpload, deferred, onStartRecording, - } = props; + } = useResourceUploadContext(); const onNext = deferred?.onNext; - const controlsRef = deferred?.submitRef; + const controlsRef = deferred?.controlsRef; const resourceStrings: IPassageDetailArtifactsStrings = useSelector( resourceSelector, shallowEqual @@ -219,7 +202,6 @@ export function PassageRecordPanel(props: IPassageRecordPanelProps) { {}} uploadType={uploadType} primaryButtonText={primaryButtonText} onNext={onNext} @@ -239,4 +221,4 @@ export function PassageRecordPanel(props: IPassageRecordPanelProps) { ); } -export default PassageRecordPanel; +export default ResourceRecordPanel; diff --git a/web/src/components/PassageDetail/Internalization/ResourceUploadContext.tsx b/web/src/components/PassageDetail/Internalization/ResourceUploadContext.tsx new file mode 100644 index 000000000..e59ea336c --- /dev/null +++ b/web/src/components/PassageDetail/Internalization/ResourceUploadContext.tsx @@ -0,0 +1,55 @@ +import { createContext, useContext, type RefObject } from 'react'; +import type { MediaUploadControlsRef } from '../../MediaUploadContent'; +import type { UploadType } from '../../UploadType'; +import type { PendingRestoreInput } from '../../../store/upload/pendingMediaUploads'; + +export interface IDeferredUpload { + onNext: () => void; + // for the wizard to trigger the real upload later + controlsRef: RefObject; +} + +/** + * What the add-resource wizard's Upload step (ResourceUploadStep and its + * ResourceRecordPanel) needs from the wizard. + */ +export interface IResourceUploadContext { + // step state + active: boolean; // the Upload step is the visible step + isAddingAudioResource: boolean; // shows a Record option as well as upload + onStartRecording?: (() => void) | undefined; + // upload identity + uploadType: UploadType; + artifactId: string | null; // null = VernacularTag + defaultFilename: string; + eafUrl?: string | undefined; + inValue?: string | undefined; + // speaker + speaker?: string | undefined; + onSpeaker?: ((speaker: string) => void) | undefined; + // form gating + ready?: boolean | undefined; // false disables the save/upload button + validationMessage?: string | undefined; + onFiles?: ((files: File[]) => void) | undefined; + metaData?: React.JSX.Element | undefined; + // upload lifecycle + finish?: ((mediaRemoteIds?: string[]) => void | Promise) | undefined; + beforeUpload?: (() => Promise) | undefined; + cancelled: RefObject; + pendingRestore?: PendingRestoreInput | undefined; + // for the general-resource flow, which defers uploading the media until the next step + deferred?: IDeferredUpload | undefined; +} + +export const ResourceUploadContext = + createContext(null); + +export function useResourceUploadContext(): IResourceUploadContext { + const ctx = useContext(ResourceUploadContext); + if (!ctx) { + throw new Error( + 'useResourceUploadContext must be used inside a ResourceUploadContext provider' + ); + } + return ctx; +} diff --git a/web/src/components/PassageDetail/Internalization/ResourceUploadStep.test.tsx b/web/src/components/PassageDetail/Internalization/ResourceUploadStep.test.tsx index eab29eae7..ef767e40d 100644 --- a/web/src/components/PassageDetail/Internalization/ResourceUploadStep.test.tsx +++ b/web/src/components/PassageDetail/Internalization/ResourceUploadStep.test.tsx @@ -1,8 +1,11 @@ import { act, cleanup, render } from '@testing-library/react'; import { UploadType } from '../../UploadType'; +import { + ResourceUploadContext, + type IResourceUploadContext, +} from './ResourceUploadContext'; type PanelProps = { - artifactId?: string | null; finish: (mediaRemoteIds?: string[]) => Promise; uploadMethod?: unknown; }; @@ -14,7 +17,7 @@ type ContentProps = { let capturedPanel: PanelProps | undefined; let capturedContent: ContentProps | undefined; -jest.mock('../../PassageRecordPanel', () => ({ +jest.mock('./ResourceRecordPanel', () => ({ __esModule: true, default: (props: PanelProps) => { capturedPanel = props; @@ -36,7 +39,6 @@ const mockUploadMethod = jest.fn(); const mockUseMediaUpload = jest.fn((_opts: unknown) => mockUploadMethod); jest.mock('../../../crud', () => ({ useMediaUpload: (opts: unknown) => mockUseMediaUpload(opts), - VernacularTag: 'vern-tag', })); jest.mock('../../../utils', () => ({ @@ -53,20 +55,23 @@ jest.mock('../../../utils/contentType', () => ({ import ResourceUploadStep from './ResourceUploadStep'; -type StepProps = React.ComponentProps; - -function renderStep(overrides: Partial = {}) { - const props: StepProps = { +function renderStep(overrides: Partial = {}) { + const value: IResourceUploadContext = { active: true, - isAudioMode: true, + isAddingAudioResource: true, uploadType: UploadType.Media, + artifactId: 'art-1', cancelled: { current: false }, finish: jest.fn(), defaultFilename: 'resource', ...overrides, }; - render(); - return props; + render( + + + + ); + return value; } function hookOptions() { @@ -127,14 +132,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 +149,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 +160,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', }); @@ -166,28 +171,23 @@ describe('ResourceUploadStep', () => { }); }); - describe('artifactId', () => { - it.each([ - ['undefined', undefined], - ['null', null], - ])('defaults to VernacularTag when %s', (_, artifactId) => { - renderStep({ artifactId }); - - expect(hookOptions().fields.artifactId).toBe('vern-tag'); - expect(capturedPanel?.artifactId).toBe('vern-tag'); - }); + it('uploads with the context artifactId', () => { + renderStep({ artifactId: 'art-2' }); - it('uses the given artifactId', () => { - renderStep({ artifactId: 'art-1' }); + expect(hookOptions().fields.artifactId).toBe('art-2'); + }); - expect(hookOptions().fields.artifactId).toBe('art-1'); - expect(capturedPanel?.artifactId).toBe('art-1'); - }); + it('throws when rendered outside the provider', () => { + const spy = jest.spyOn(console, 'error').mockImplementation(() => {}); + expect(() => render()).toThrow( + /ResourceUploadContext provider/ + ); + spy.mockRestore(); }); it('configures the upload hook from its props', () => { const beforeUpload = jest.fn(async () => {}); - const pendingRestore = {} as StepProps['pendingRestore']; + const pendingRestore = {} as IResourceUploadContext['pendingRestore']; const props = renderStep({ speaker: 'Ann', eafUrl: 'eaf-url', diff --git a/web/src/components/PassageDetail/Internalization/ResourceUploadStep.tsx b/web/src/components/PassageDetail/Internalization/ResourceUploadStep.tsx index ea034e4f3..d7b1eaf09 100644 --- a/web/src/components/PassageDetail/Internalization/ResourceUploadStep.tsx +++ b/web/src/components/PassageDetail/Internalization/ResourceUploadStep.tsx @@ -1,51 +1,26 @@ -import { RefObject } from 'react'; import { Box } from '@mui/material'; import MediaUploadContent from '../../MediaUploadContent'; -import PassageRecordPanel, { IDeferredUpload } from '../../PassageRecordPanel'; -import { useMediaUpload, VernacularTag } from '../../../crud'; +import ResourceRecordPanel from './ResourceRecordPanel'; +import { useMediaUpload } from '../../../crud'; import { splitFaithbridgeValue } from '../../../utils/contentType'; import { UploadType } from '../../UploadType'; -import type { PendingRestoreInput } from '../../../store/upload/pendingMediaUploads'; - -interface IProps { - active: boolean; - isAudioMode: boolean; //shows a Record option as well as upload - uploadType: UploadType; - artifactId?: string | null | undefined; - speaker?: string | undefined; - onSpeaker?: ((speaker: string) => void) | undefined; - eafUrl?: string | undefined; - inValue?: string | undefined; - defaultFilename: string; - ready?: boolean | undefined; // false disables the save/upload button - validationMessage?: string | undefined; - metaData?: React.JSX.Element | undefined; - finish?: ((mediaRemoteIds?: string[]) => void | Promise) | undefined; - beforeUpload?: (() => Promise) | undefined; - cancelled: RefObject; - pendingRestore?: PendingRestoreInput | undefined; - onFiles?: ((files: File[]) => void) | undefined; - deferred?: IDeferredUpload | undefined; // for the general-resource flow which defers uploading the media until the next step - onStartRecording?: (() => void) | undefined; -} +import { useResourceUploadContext } from './ResourceUploadContext'; /** * The add-resource wizard's step-1 body: the Upload/Record UI, embedded (no * dialog of its own) so the wizard shows/hides it as a step and it stays mounted * across the flow — a recorded take survives Next→Back. Drives the shared * useMediaUpload pipeline directly (the standalone dialog path is Uploader). + * Reads its inputs from ResourceUploadContext. */ -export function ResourceUploadStep(props: IProps) { +export function ResourceUploadStep() { const { - active, - isAudioMode, + isAddingAudioResource, uploadType, - artifactId: artifactIdProp, + artifactId, speaker, - onSpeaker, eafUrl, inValue, - defaultFilename, ready, validationMessage, metaData, @@ -54,10 +29,7 @@ export function ResourceUploadStep(props: IProps) { cancelled, pendingRestore, onFiles, - deferred, - onStartRecording, - } = props; - const artifactId = artifactIdProp ?? VernacularTag; + } = useResourceUploadContext(); // A Faithbridge link arrives as `url||transcript` in inValue; split it here const faithbridge = @@ -103,30 +75,12 @@ 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 /> { - 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 };