add local file serach in to header menu
This commit is contained in:
@@ -9,6 +9,7 @@ import { useQueryClient } from '@tanstack/react-query';
|
||||
import { removeUserFile } from '@/app/actions/fileEntity';
|
||||
import { FileSearchPanel } from '@/app/ui/search/file-search-panel';
|
||||
import { getFileType } from '@/app/lib/getFileType';
|
||||
import { useAllFilesExtensions } from '@/app/hooks/react-query/useAllFilesExtensions';
|
||||
interface SelectedFile {
|
||||
file: File;
|
||||
preview: string | undefined;
|
||||
@@ -33,10 +34,9 @@ export interface AllowedExtensions {
|
||||
|
||||
interface SectionSearchFile {
|
||||
allowedExtensions: AllowedExtensions
|
||||
maxFileSize: number
|
||||
}
|
||||
|
||||
export default function SectionSearchFile({ allowedExtensions, maxFileSize }: SectionSearchFile) {
|
||||
export default function SectionSearchFile() {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [isDragging, setIsDragging] = useState<boolean>(false);
|
||||
const [selectedFile, setSelectedFile] = useState<SelectedFile | null>(null);
|
||||
@@ -53,7 +53,15 @@ export default function SectionSearchFile({ allowedExtensions, maxFileSize }: Se
|
||||
|
||||
const t = useTranslations('Global');
|
||||
|
||||
const allExtensions = useMemo(() => { return [...allowedExtensions.images, ...allowedExtensions.videos, ...allowedExtensions.audios, ...allowedExtensions.documents] }, []);
|
||||
const { data: allFilesExtensions, isLoading, isError } = useAllFilesExtensions();
|
||||
|
||||
const allExtensions = useMemo(() => {
|
||||
if (allFilesExtensions) {
|
||||
return [...allFilesExtensions.images, ...allFilesExtensions.videos, ...allFilesExtensions.audios, ...allFilesExtensions.documents]
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}, []);
|
||||
|
||||
const acceptString = useMemo(() => {
|
||||
if (!allExtensions || !Array.isArray(allExtensions)) {
|
||||
@@ -73,7 +81,7 @@ export default function SectionSearchFile({ allowedExtensions, maxFileSize }: Se
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_SIZE = maxFileSize;
|
||||
const MAX_SIZE = allFilesExtensions?.maxFileSize ? allFilesExtensions?.maxFileSize : 0;
|
||||
|
||||
if (file.size > MAX_SIZE) {
|
||||
return {
|
||||
@@ -168,7 +176,7 @@ export default function SectionSearchFile({ allowedExtensions, maxFileSize }: Se
|
||||
setError(null);
|
||||
isCancelledRef.current = false;
|
||||
const file = fileInfo.file;
|
||||
const fileType = getFileType(fileInfo.file.name, allowedExtensions);
|
||||
const fileType = getFileType(fileInfo.file.name, allFilesExtensions);
|
||||
|
||||
try {
|
||||
const extension = file.name.split('.').pop() || '';
|
||||
@@ -238,7 +246,7 @@ export default function SectionSearchFile({ allowedExtensions, maxFileSize }: Se
|
||||
} finally {
|
||||
setUploadId(null);
|
||||
}
|
||||
}, [uploadId, allowedExtensions]);
|
||||
}, [uploadId, allFilesExtensions]);
|
||||
|
||||
useEffect(() => {
|
||||
// Обработка закрытия вкладки
|
||||
@@ -351,7 +359,7 @@ export default function SectionSearchFile({ allowedExtensions, maxFileSize }: Se
|
||||
</div>
|
||||
|
||||
{isFileUploaded && (
|
||||
<FileSearchPanel fileId={fileId} ref={childRef} allowedExtensions={allowedExtensions} fileType={fileType} />
|
||||
<FileSearchPanel fileId={fileId} ref={childRef} allowedExtensions={allFilesExtensions} fileType={fileType} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user