disable a select file while global serch
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { SearchedUserFilesList } from '@/app/ui/search/searched-user-files-list';
|
||||
import { SearchedGlobalFilesList } from '@/app/ui/search/searched-global-files-list';
|
||||
import { useCallback, useState, useImperativeHandle } from 'react';
|
||||
import { useCallback, useState, useImperativeHandle, useEffect } from 'react';
|
||||
import { searchUserFiles, searchGlobalFiles } from '@/app/actions/searchActions';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Pagination } from '@/app/components/Pagination';
|
||||
@@ -29,9 +29,9 @@ export interface FileInfo {
|
||||
}
|
||||
|
||||
export function FileSearchPanel(
|
||||
{ fileId, ref, allowedExtensions, fileType }
|
||||
{ fileId, ref, allowedExtensions, fileType, onLoadingChange }
|
||||
:
|
||||
{ fileId: string | null, ref: any, allowedExtensions: AllowedExtensions, fileType: string | null }
|
||||
{ fileId: string | null, ref: any, allowedExtensions: AllowedExtensions, fileType: string | null, onLoadingChange?: (loading: boolean) => void }
|
||||
) {
|
||||
const [searchedUserFiles, setSearchedUserFiles] = useState<FileInfo[]>([]);
|
||||
const [searchedUserFilesShowNull, setSearchedUserFilesShowNull] = useState<boolean>(false);
|
||||
@@ -115,6 +115,7 @@ export function FileSearchPanel(
|
||||
|
||||
if (!actionFromPagination) {
|
||||
setLoading(true);
|
||||
onLoadingChange?.(true);
|
||||
setSearchedGlobalFilesShowNull(false);
|
||||
setSearchedGlobalFiles([]);
|
||||
} else {
|
||||
@@ -145,6 +146,7 @@ export function FileSearchPanel(
|
||||
/* await queryClient.invalidateQueries({ queryKey: ['userData'] });
|
||||
await queryClient.invalidateQueries({ queryKey: ['userSearchData'] }); */
|
||||
setLoading(false);
|
||||
onLoadingChange?.(false);
|
||||
setPaginationLoading(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ export default function SectionSearchFile() {
|
||||
const [fileType, setFileType] = useState<string | null>(null);
|
||||
const queryClient = useQueryClient();
|
||||
const isCancelledRef = useRef(false);
|
||||
const [isFileSearchLoading, setIsFileSearchLoading] = useState(false);
|
||||
|
||||
const childRef = useRef(null);
|
||||
|
||||
@@ -285,6 +286,10 @@ export default function SectionSearchFile() {
|
||||
}
|
||||
});
|
||||
|
||||
const handleLoadingChange = (loading: boolean) => {
|
||||
setIsFileSearchLoading(loading);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="upload-section">
|
||||
<div className="search-info">
|
||||
@@ -316,13 +321,14 @@ export default function SectionSearchFile() {
|
||||
style={{ display: 'none' }}
|
||||
onChange={handleFileInputChange}
|
||||
aria-label="Выбор файла для защиты"
|
||||
disabled={isFileSearchLoading || (uploadProgress !== undefined && uploadProgress !== 100)}
|
||||
/>
|
||||
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={handleButtonClick}
|
||||
type="button"
|
||||
disabled={uploadProgress && uploadProgress !== 100 ? true : false}
|
||||
disabled={isFileSearchLoading || (uploadProgress !== undefined && uploadProgress !== 100)}
|
||||
>
|
||||
Выбрать файл
|
||||
</button>
|
||||
@@ -363,7 +369,13 @@ export default function SectionSearchFile() {
|
||||
</div>
|
||||
|
||||
{isFileUploaded && (
|
||||
<FileSearchPanel fileId={fileId} ref={childRef} allowedExtensions={allFilesExtensions} fileType={fileType} />
|
||||
<FileSearchPanel
|
||||
fileId={fileId}
|
||||
ref={childRef}
|
||||
allowedExtensions={allFilesExtensions}
|
||||
fileType={fileType}
|
||||
onLoadingChange={handleLoadingChange}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user