* Replaced legacy Button * Updated Dialog width * Restore text and spacing fixes * Updated drop zone styling * Migrated to ui-next colors
118 lines
3.7 KiB
TypeScript
118 lines
3.7 KiB
TypeScript
import React, { useCallback, useState } from 'react';
|
|
import { ReactElement } from 'react';
|
|
import Dropzone from 'react-dropzone';
|
|
import PropTypes from 'prop-types';
|
|
import classNames from 'classnames';
|
|
import DicomFileUploader from '../../utils/DicomFileUploader';
|
|
import DicomUploadProgress from './DicomUploadProgress';
|
|
import { Button } from '@ohif/ui-next';
|
|
// Removed dashed border CSS; using simple 1px solid border with muted foreground color
|
|
|
|
type DicomUploadProps = {
|
|
dataSource;
|
|
onComplete: () => void;
|
|
onStarted: () => void;
|
|
};
|
|
|
|
function DicomUpload({ dataSource, onComplete, onStarted }: DicomUploadProps): ReactElement {
|
|
const baseClassNames =
|
|
'min-h-[375px] flex flex-col bg-black select-none rounded-lg overflow-hidden';
|
|
const [dicomFileUploaderArr, setDicomFileUploaderArr] = useState([]);
|
|
|
|
const onDrop = useCallback(async acceptedFiles => {
|
|
onStarted();
|
|
setDicomFileUploaderArr(acceptedFiles.map(file => new DicomFileUploader(file, dataSource)));
|
|
}, []);
|
|
|
|
const getDropZoneComponent = (): ReactElement => {
|
|
return (
|
|
<Dropzone
|
|
onDrop={acceptedFiles => {
|
|
onDrop(acceptedFiles);
|
|
}}
|
|
noClick
|
|
>
|
|
{({ getRootProps }) => (
|
|
<div
|
|
{...getRootProps()}
|
|
className="m-5 flex h-full flex-col items-center justify-center rounded-2xl border"
|
|
style={{ borderColor: 'hsl(var(--muted-foreground) / 0.25)' }}
|
|
>
|
|
<div className="flex gap-2">
|
|
<Dropzone
|
|
onDrop={onDrop}
|
|
noDrag
|
|
>
|
|
{({ getRootProps, getInputProps }) => (
|
|
<div {...getRootProps()}>
|
|
<Button
|
|
variant="default"
|
|
size="lg"
|
|
disabled={false}
|
|
onClick={() => {}}
|
|
>
|
|
{'Add files'}
|
|
<input
|
|
{...getInputProps()}
|
|
style={{ display: 'none' }}
|
|
/>
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</Dropzone>
|
|
<Dropzone
|
|
onDrop={onDrop}
|
|
noDrag
|
|
>
|
|
{({ getRootProps, getInputProps }) => (
|
|
<div {...getRootProps()}>
|
|
<Button
|
|
variant="secondary"
|
|
size="lg"
|
|
disabled={false}
|
|
onClick={() => {}}
|
|
>
|
|
{'Add folder'}
|
|
<input
|
|
{...getInputProps()}
|
|
webkitdirectory="true"
|
|
mozdirectory="true"
|
|
style={{ display: 'none' }}
|
|
/>
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</Dropzone>
|
|
</div>
|
|
<div className="text-foreground pt-6 text-base">or drag images or folders here</div>
|
|
<div className="text-muted-foreground pt-1 text-base">(DICOM files supported)</div>
|
|
</div>
|
|
)}
|
|
</Dropzone>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{dicomFileUploaderArr.length ? (
|
|
<div className={classNames('h-[calc(100vh-300px)]', baseClassNames)}>
|
|
<DicomUploadProgress
|
|
dicomFileUploaderArr={Array.from(dicomFileUploaderArr)}
|
|
onComplete={onComplete}
|
|
/>
|
|
</div>
|
|
) : (
|
|
<div className={classNames('h-[480px]', baseClassNames)}>{getDropZoneComponent()}</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
DicomUpload.propTypes = {
|
|
dataSource: PropTypes.object.isRequired,
|
|
onComplete: PropTypes.func.isRequired,
|
|
onStarted: PropTypes.func.isRequired,
|
|
};
|
|
|
|
export default DicomUpload;
|