add retry button for global search while error

This commit is contained in:
smanylov
2026-03-03 11:57:18 +07:00
parent 3b1509edf0
commit 2227a842ae
2 changed files with 20 additions and 12 deletions
+20 -11
View File
@@ -44,6 +44,7 @@ export function FileSearchPanel(
const [showGlobalSearch, setShowGlobalSearch] = useState<boolean>(false);
const queryClient = useQueryClient();
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [globalSearchErrorMessage, setGlobalSearchErrorMessage] = useState<string | null>(null);
const t = useTranslations('Global');
const [searchTotalPages, setSearchTotalPages] = useState<number>(0);
@@ -64,6 +65,7 @@ export function FileSearchPanel(
const handlerSearchUserFile = useCallback(async (fileId: string, page: number): Promise<void> => {
setErrorMessage(null);
setGlobalSearchErrorMessage(null);
try {
let result = await searchUserFiles(fileId);
@@ -84,6 +86,8 @@ export function FileSearchPanel(
}, [fileId])
const handlerSearchGlobalFile = useCallback(async (fileId: string, page: number, actionFromPagination?: boolean): Promise<void> => {
setGlobalSearchErrorMessage(null);
if (!actionFromPagination) {
setLoading(true);
setSearchedGlobalFilesShowNull(false);
@@ -94,8 +98,10 @@ export function FileSearchPanel(
try {
let result = await searchGlobalFiles(fileId, page);
console.log('searchGlobalFiles');
console.log(result);
if (result.error) {
throw result.error;
}
if (result.images.length) {
setSearchedGlobalFiles(result.images);
setSearchTotalPages(result.totalPages);
@@ -105,7 +111,7 @@ export function FileSearchPanel(
setSearchedGlobalFilesShowNull(true);
}
} catch (error) {
setErrorMessage('error');
setGlobalSearchErrorMessage('error');
} finally {
await queryClient.invalidateQueries({ queryKey: ['userData'] });
await queryClient.invalidateQueries({ queryKey: ['userSearchData'] });
@@ -230,7 +236,15 @@ export function FileSearchPanel(
<p className="global-no-result-text">
{t('no-similar-global-description')}
</p>
{/* <button
</div>
)}
{globalSearchErrorMessage && (
<>
<div className="global-error">
<strong>{t('search-error')}</strong>
</div>
<button
onClick={() => {
if (fileId) {
handlerSearchGlobalFile(fileId, 1);
@@ -239,15 +253,10 @@ export function FileSearchPanel(
className="btn btn-primary btn-search"
>
{t('search-again')}
</button> */}
</div>
</button>
</>
)}
<div className="global-error">
<strong>{t('global-error-title')}</strong>
<span id="global-error-text"></span>
</div>
<Pagination
totalPages={searchTotalPages}
currentPage={searchCurrentPages}