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