Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions web/src/components/AudioTab/AudioTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,12 @@ export function AudioTab() {
</Box>
<Uploader
isOpen={uploadVisible}
onOpen={setUploadVisible}
onClose={() => setUploadVisible(false)}
multiple={true}
finish={afterUpload}
cancelled={cancelled}
performedBy={speaker}
onSpeakerChange={handleNameChange}
speaker={speaker}
onSpeaker={handleNameChange}
/>
</ContentLayout>
);
Expand Down
10 changes: 5 additions & 5 deletions web/src/components/Discussions/DiscussionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>) | null>(null);
const categorySaveRef = useRef<(() => Promise<string>) | null>(null);
const [showMove, setShowMove] = useState(false);
const [moveTo, setMoveTo] = useState<string>();
const waitForRemoteQueue = useWaitForRemoteQueue();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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}
Expand Down
12 changes: 6 additions & 6 deletions web/src/components/GraphicPicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div>
custom-upload
{props.metadata}
{props.metaData}
<button
type="button"
onClick={() =>
Expand Down
18 changes: 9 additions & 9 deletions web/src/components/GraphicPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export function GraphicPicker({
const ts: ISharedStrings = useSelector(sharedSelector, shallowEqual);
const [tabValue, setTabValue] = useState(0);
const userTabRef = useRef(false);
const mediaUploadControlsRef = useRef<MediaUploadControlsRef>({
const controlsRef = useRef<MediaUploadControlsRef>({
handleCancel: null,
handleAddOrSave: null,
} as MediaUploadControlsRef);
Expand Down Expand Up @@ -691,8 +691,8 @@ export function GraphicPicker({
}, [isOpen, tabValue, search, keywordListSearch, showMessage, t]);

const handleClose = useCallback(() => {
if (mediaUploadControlsRef?.current?.handleCancel && tabValue === 1) {
mediaUploadControlsRef.current.handleCancel();
if (controlsRef?.current?.handleCancel && tabValue === 1) {
controlsRef.current.handleCancel();
}
onOpen(false);
onCancel?.();
Expand All @@ -708,10 +708,10 @@ export function GraphicPicker({
userTabRef.current = false;
if (tabValue === 1) {
onSelectedRights?.(rightsDraftRef.current);
if (mediaUploadControlsRef?.current?.handleAddOrSave) {
mediaUploadControlsRef.current.handleAddOrSave();
if (controlsRef?.current?.handleAddOrSave) {
controlsRef.current.handleAddOrSave();
}
// uploadMedia closes via finish → onOpen after the image save.
// uploadMedia closes via finish → onClose after the image save.
// Closing here races a rights-only save that can clobber it.
setSelectedId(null);
return;
Expand Down Expand Up @@ -943,7 +943,7 @@ export function GraphicPicker({
<TabPanel value={tabValue} index={1}>
<VertScrollBox>
<GraphicUploader
onOpen={onOpen}
onClose={() => onOpen(false)}
dimension={dimension}
defaultFilename={defaultFilename}
showMessage={showMessage}
Expand All @@ -960,9 +960,9 @@ export function GraphicPicker({
setPreviewUrl('');
}
}}
mediaUploadControlsRef={mediaUploadControlsRef}
controlsRef={controlsRef}
onSaveDisabled={setSaveDisabled}
metadata={
metaData={
<Box>
<GraphicRights
key={rightsFieldKey}
Expand Down
21 changes: 11 additions & 10 deletions web/src/components/GraphicUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,32 @@ import { CompressedImages, useCompression } from '../utils/useCompression';
interface IProps {
defaultFilename?: string;
dimension: number[];
onOpen: (visible: boolean) => void;
onClose: () => void;
showMessage: (msg: string | React.JSX.Element) => void;
hasRights?: boolean; // required for upload
finish?: (images: CompressedImages[]) => void; // when conversion complete
cancelled: React.RefObject<boolean>;
uploadType?: UploadType;
metadata?: React.JSX.Element;
metaData?: React.JSX.Element;
onFiles?: (files: File[]) => void;
mediaUploadControlsRef?: React.RefObject<MediaUploadControlsRef>;
controlsRef?: React.RefObject<MediaUploadControlsRef>;
onSaveDisabled?: ((disabled: boolean) => void) | undefined;
}

export function GraphicUploader(props: IProps) {
const {
defaultFilename,
dimension,
onOpen,
onClose,
showMessage,
cancelled,
uploadType,
hasRights,
finish,
metadata,
metaData,
onFiles,
onSaveDisabled,
controlsRef,
} = props;
const ts: ISharedStrings = useSelector(sharedSelector, shallowEqual);
const { showFile, uploadMedia } = useCompression({
Expand All @@ -47,26 +48,26 @@ export function GraphicUploader(props: IProps) {
dimension,
defaultFilename,
finish,
onOpen,
onClose,
});

const uploadCancel = () => {
onOpen?.(false);
onClose();
if (cancelled) cancelled.current = true;
restoreScroll();
};

return (
<MediaUploadContent
onVisible={onOpen}
onClose={onClose}
uploadType={uploadType || UploadType.Media}
uploadMethod={uploadMedia}
cancelMethod={uploadCancel}
cancelLabel={ts.close}
metaData={metadata}
metaData={metaData}
ready={Boolean(hasRights)}
onFiles={showFile}
controlsRef={props.mediaUploadControlsRef}
controlsRef={controlsRef}
onSaveDisabled={onSaveDisabled}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/ImportTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,8 @@ export function ImportTab(props: IProps) {

{uploadVisible && selectedImportType !== UploadType.Burrito && (
<MediaUploadDialog
visible={uploadVisible}
onVisible={setUploadVisible}
isOpen={uploadVisible}
onClose={() => setUploadVisible(false)}
uploadType={selectedImportType}
uploadMethod={
selectedImportType === UploadType.PTF
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/MediaUploadContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export interface MediaUploadControlsRef {
}

interface IProps {
onVisible: (v: boolean) => void;
onClose?: (() => void) | undefined;
uploadType: UploadType;
uploadMethod?:
((files: File[]) => void | boolean | Promise<void | boolean>) | undefined;
Expand Down Expand Up @@ -200,7 +200,7 @@ interface IProps {

function MediaUploadContent(props: IProps) {
const {
onVisible,
onClose,
uploadType,
multiple,
uploadMethod,
Expand Down Expand Up @@ -280,7 +280,7 @@ function MediaUploadContent(props: IProps) {
if (cancelMethod) {
cancelMethod();
}
onVisible(false);
onClose?.();
};
const saveDisabled = useMemo(
() =>
Expand Down
14 changes: 7 additions & 7 deletions web/src/components/MediaUploadDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { FaithBridge } from '../assets/brands';
import { UploadType } from './UploadType';

interface IProps {
visible: boolean;
onVisible: (v: boolean) => void;
isOpen: boolean;
onClose: () => void;
uploadType: UploadType;
uploadMethod?:
((files: File[]) => void | boolean | Promise<void | boolean>) | undefined;
Expand All @@ -23,8 +23,8 @@ interface IProps {

function MediaUploadDialog(props: IProps) {
const {
visible,
onVisible,
isOpen,
onClose,
uploadType,
multiple,
uploadMethod,
Expand Down Expand Up @@ -54,19 +54,19 @@ function MediaUploadDialog(props: IProps) {
if (cancelMethod) {
cancelMethod();
}
onVisible(false);
onClose();
};

return (
<BigDialog
isOpen={visible}
isOpen={isOpen}
onOpen={handleCancel}
title={title[uploadType] ?? ''}
bp={isMobile ? BigDialogBp.mobile : BigDialogBp.sm}
>
<>
<MediaUploadContent
onVisible={onVisible}
onClose={onClose}
uploadType={uploadType}
multiple={multiple}
uploadMethod={uploadMethod}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,19 @@ jest.mock('./ResourceUploadStep', () => {
ready?: boolean;
validationMessage?: string;
onFiles?: (f: File[]) => void;
deferred?: { onNext: () => void; submitRef: ControlsRef };
deferred?: { onNext: () => void; controlsRef: ControlsRef };
onStartRecording?: () => void;
finish?: (ids?: string[]) => void;
metaData?: React.ReactNode;
}) => {
const isProject = uploadType === UploadType.ProjectResource;
const onNext = deferred?.onNext;
const submitRef = deferred?.submitRef;
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 (submitRef) {
submitRef.current.handleAddOrSave = () => finish?.(['media-1']);
if (controlsRef) {
controlsRef.current.handleAddOrSave = () => finish?.(['media-1']);
}
return (
<>
Expand All @@ -198,7 +198,7 @@ jest.mock('./ResourceUploadStep', () => {
</button>
{/* 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. */}
<button
type="button"
onClick={() => {
Expand Down Expand Up @@ -241,18 +241,20 @@ jest.mock('./ResourceData', () => {
__esModule: true,
default: ({
onDescriptionChange,
onPassResChange,
onResourceKindChange,
}: {
onDescriptionChange: (d: string) => void;
onPassResChange?: (k: number) => void;
onResourceKindChange?: (k: number) => void;
}) => (
<div>
<button type="button" onClick={() => onDescriptionChange('desc')}>
set-desc
</button>
<button
type="button"
onClick={() => onPassResChange?.(ResourceTypeEnum.projectResource)}
onClick={() =>
onResourceKindChange?.(ResourceTypeEnum.projectResource)
}
>
set-general
</button>
Expand Down Expand Up @@ -305,10 +307,10 @@ jest.mock('./ProjectResourceConfigure', () => ({
__esModule: true,
default: ({
onBack,
onOpen,
onClose,
}: {
onBack?: () => void;
onOpen?: (open: boolean) => void;
onClose?: () => void;
}) => (
<div data-testid="configure">
<span>Configure</span>
Expand All @@ -317,7 +319,7 @@ jest.mock('./ProjectResourceConfigure', () => ({
configure-back
</button>
)}
<button type="button" onClick={() => onOpen?.(false)}>
<button type="button" onClick={() => onClose?.()}>
configure-done
</button>
</div>
Expand Down Expand Up @@ -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'));

Expand Down
Loading
Loading